S3 Select: Mismatched types don't match (#8608)

When comparing for equality, if types cannot be matched, they don't match.
master
Klaus Post 5 years ago committed by kannappanr
parent 97deba2a7c
commit f1e2e1cc9e
  1. 27
      pkg/s3select/select_test.go
  2. 9
      pkg/s3select/sql/value.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(`<?xml version="1.0" encoding="UTF-8"?>
@ -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)
}

@ -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 {

Loading…
Cancel
Save