mirror of
https://github.com/minio/minio.git
synced 2025-11-08 21:24:55 -05:00
fix: S3 Select CSV -> JSON with variable field count (#15677)
When there are fewer fields than expected, output fewer fields.
This commit is contained in:
@@ -125,9 +125,11 @@ func (r *Record) WriteCSV(writer io.Writer, opts sql.WriteCSVOpts) error {
|
||||
|
||||
// WriteJSON - encodes to JSON data.
|
||||
func (r *Record) WriteJSON(writer io.Writer) error {
|
||||
var kvs jstream.KVS = make([]jstream.KV, len(r.columnNames))
|
||||
for i := 0; i < len(r.columnNames); i++ {
|
||||
kvs[i] = jstream.KV{Key: r.columnNames[i], Value: r.csvRecord[i]}
|
||||
var kvs jstream.KVS = make([]jstream.KV, 0, len(r.columnNames))
|
||||
for i, cn := range r.columnNames {
|
||||
if i < len(r.csvRecord) {
|
||||
kvs = append(kvs, jstream.KV{Key: cn, Value: r.csvRecord[i]})
|
||||
}
|
||||
}
|
||||
return json.NewEncoder(writer).Encode(kvs)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user