sanitizeRecordJSONKeys replaces all invalid characters in JSON keys with underscores. This is required for compatibility with Athena.
(record arrow.RecordBatch)
| 118 | // sanitizeRecordJSONKeys replaces all invalid characters in JSON keys with underscores. This is required |
| 119 | // for compatibility with Athena. |
| 120 | func sanitizeRecordJSONKeys(record arrow.RecordBatch) (arrow.RecordBatch, error) { |
| 121 | cols := make([]arrow.Array, record.NumCols()) |
| 122 | for i, col := range record.Columns() { |
| 123 | if arrow.TypeEqual(col.DataType(), types.NewJSONType()) { |
| 124 | b := types.NewJSONBuilder(memory.DefaultAllocator) |
| 125 | for r := 0; r < int(record.NumRows()); r++ { |
| 126 | if col.IsNull(r) { |
| 127 | b.AppendNull() |
| 128 | continue |
| 129 | } |
| 130 | data, err := sanitizeJSONRawMessage(col.GetOneForMarshal(r).(json.RawMessage)) |
| 131 | if err != nil { |
| 132 | return nil, err |
| 133 | } |
| 134 | b.Append(data) |
| 135 | } |
| 136 | cols[i] = b.NewArray() |
| 137 | continue |
| 138 | } |
| 139 | cols[i] = col |
| 140 | } |
| 141 | return array.NewRecordBatch(record.Schema(), cols, record.NumRows()), nil |
| 142 | } |
| 143 | |
| 144 | func sanitizeJSONRawMessage(rawMessage json.RawMessage) (any, error) { |
| 145 | var data any |
no test coverage detected