Use jstream to serialize records to JSON format in S3Select (#7318)

- Also, switch to jstream to generate internal record representation
  from CSV/JSON readers

- This fixes a bug in which JSON output objects have their keys
  reversed from the order they are specified in the Select columns.

- Also includes a fix for tests.
This commit is contained in:
Aditya Manthramurthy
2019-03-07 00:20:10 -08:00
committed by Harshavardhana
parent f97a33a63f
commit f4879ed96d
4 changed files with 68 additions and 50 deletions

View File

@@ -23,7 +23,6 @@ import (
"github.com/minio/minio/pkg/s3select/sql"
"github.com/bcicen/jstream"
"github.com/tidwall/sjson"
)
// Reader - JSON record reader for S3Select.
@@ -50,17 +49,18 @@ func (r *Reader) Read() (sql.Record, error) {
if v.ValueType == jstream.Object {
data, err = json.Marshal(v.Value)
} else {
// To be AWS S3 compatible
// Select for JSON needs to output non-object JSON as single column value
// i.e. a map with `_1` as key and value as the non-object.
data, err = sjson.SetBytes(data, "_1", v.Value)
// To be AWS S3 compatible Select for JSON needs to
// output non-object JSON as single column value
// i.e. a map with `_1` as key and value as the
// non-object.
data, err = json.Marshal(jstream.KVS{jstream.KV{Key: "_1", Value: v.Value}})
}
if err != nil {
return nil, errJSONParsingError(err)
}
return &Record{
data: data,
Data: data,
}, nil
}