mirror of
https://github.com/minio/minio.git
synced 2025-07-27 01:10:08 -04:00
S3 Select: Mismatched types don't match (#8608)
When comparing for equality, if types cannot be matched, they don't match.
This commit is contained in:
parent
97deba2a7c
commit
f1e2e1cc9e
@ -61,6 +61,7 @@ func TestJSONQueries(t *testing.T) {
|
|||||||
query string
|
query string
|
||||||
requestXML []byte // override request XML
|
requestXML []byte // override request XML
|
||||||
wantResult string
|
wantResult string
|
||||||
|
withJSON string // Override JSON input
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "select-in-array-full",
|
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][*]`,
|
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]]}`,
|
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",
|
name: "select-output-field-as-csv",
|
||||||
requestXML: []byte(`<?xml version="1.0" encoding="UTF-8"?>
|
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) {
|
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 {
|
}); err != nil {
|
||||||
t.Fatal(err)
|
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 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 {
|
func inferTypesForCmp(a *Value, b *Value) error {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user