MCPcopy Create free account
hub / github.com/cloudquery/cloudquery / sanitizeRecordJSONKeys

Function sanitizeRecordJSONKeys

plugins/destination/s3/client/write.go:120–142  ·  view source on GitHub ↗

sanitizeRecordJSONKeys replaces all invalid characters in JSON keys with underscores. This is required for compatibility with Athena.

(record arrow.RecordBatch)

Source from the content-addressed store, hash-verified

118// sanitizeRecordJSONKeys replaces all invalid characters in JSON keys with underscores. This is required
119// for compatibility with Athena.
120func 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
144func sanitizeJSONRawMessage(rawMessage json.RawMessage) (any, error) {
145 var data any

Callers 1

WriteTableMethod · 0.85

Calls 2

sanitizeJSONRawMessageFunction · 0.85
AppendMethod · 0.80

Tested by

no test coverage detected