diff --git a/pkg/s3select/select_test.go b/pkg/s3select/select_test.go index f583017ee..e1e758378 100644 --- a/pkg/s3select/select_test.go +++ b/pkg/s3select/select_test.go @@ -61,6 +61,7 @@ func TestJSONQueries(t *testing.T) { query string requestXML []byte // override request XML wantResult string + withJSON string // Override JSON input }{ { name: "select-in-array-full", @@ -208,6 +209,26 @@ func TestJSONQueries(t *testing.T) { query: `SELECT * from s3object s WHERE (8.0+0.5) IN s.nested[1][*]`, wantResult: `{"id":3,"title":"Second Record","desc":"another text","nested":[[2,3,4],[7,8.5,9]]}`, }, + { + name: "compare-mixed", + query: `SELECT id from s3object s WHERE value = true`, + wantResult: `{"id":1}`, + withJSON: `{"id":0, "value": false} +{"id":1, "value": true} +{"id":2, "value": 42} +{"id":3, "value": "true"} +`, + }, + { + name: "compare-mixed-not", + query: `SELECT COUNT(id) as n from s3object s WHERE value != true`, + wantResult: `{"n":3}`, + withJSON: `{"id":0, "value": false} +{"id":1, "value": true} +{"id":2, "value": 42} +{"id":3, "value": "true"} +`, + }, { name: "select-output-field-as-csv", requestXML: []byte(` @@ -263,7 +284,11 @@ func TestJSONQueries(t *testing.T) { } if err = s3Select.Open(func(offset, length int64) (io.ReadCloser, error) { - return ioutil.NopCloser(bytes.NewBufferString(input)), nil + in := input + if len(testCase.withJSON) > 0 { + in = testCase.withJSON + } + return ioutil.NopCloser(bytes.NewBufferString(in)), nil }); err != nil { t.Fatal(err) } diff --git a/pkg/s3select/sql/value.go b/pkg/s3select/sql/value.go index 657afe1d1..6991d9a4e 100644 --- a/pkg/s3select/sql/value.go +++ b/pkg/s3select/sql/value.go @@ -445,7 +445,14 @@ func (v *Value) compareOp(op string, a *Value) (res bool, err error) { return timestampCompare(op, timestampV, timestampA), nil } - return false, errCmpMismatchedTypes + // Types cannot be compared, they do not match. + switch op { + case opEq: + return false, nil + case opIneq: + return true, nil + } + return false, errCmpInvalidBoolOperator } func inferTypesForCmp(a *Value, b *Value) error {