diff --git a/dax/test/dax/dax_test.go b/dax/test/dax/dax_test.go index 859884007..b9415850d 100644 --- a/dax/test/dax/dax_test.go +++ b/dax/test/dax/dax_test.go @@ -149,8 +149,9 @@ func TestDAXIntegration(t *testing.T) { "viewtests/drop-view", // drop view does a delete "viewtests/drop-view-if-exists-after-drop", "viewtests/select-view-after-drop", - "time_quantum_insert/test-12", // orchestrator currently does not support to,from args on Rows() - "select-having/string", // fails in DAX because the string isn't translated. + "time_quantum_insert/stringset-rangeq", // orchestrator currently does not support to,from args on Rows() + "time_quantum_insert/idset-rangeq", + "select-having/string", // fails in DAX because the string isn't translated. } doSkip := func(name string) bool { diff --git a/sql3/planner/expression.go b/sql3/planner/expression.go index 0457f2f32..5cd4d3534 100644 --- a/sql3/planner/expression.go +++ b/sql3/planner/expression.go @@ -1720,7 +1720,7 @@ func (n *qualifiedRefPlanExpression) Evaluate(currentRow []interface{}) (interfa } switch n.dataType.(type) { - case *parser.DataTypeIDSet: + case *parser.DataTypeIDSet, *parser.DataTypeIDSetQuantum: row, ok := currentRow[n.columnIndex].([]uint64) if !ok { return nil, sql3.NewErrInternalf("unexpected type for current row '%T'", currentRow[n.columnIndex]) diff --git a/sql3/planner/inbuiltfunctionsset.go b/sql3/planner/inbuiltfunctionsset.go index f696bb6c5..8c24f8559 100644 --- a/sql3/planner/inbuiltfunctionsset.go +++ b/sql3/planner/inbuiltfunctionsset.go @@ -49,7 +49,7 @@ func (n *callPlanExpression) EvaluateSetContains(currentRow []interface{}) (inte return nil, sql3.NewErrInternalf("unable to convert value") } - return intSetContains(targetSet, int64(testValue)), nil + return intSetContains(targetSet, testValue), nil default: return nil, sql3.NewErrInternalf("unexpected data type '%T'", typ) diff --git a/sql3/test/defs/defs.go b/sql3/test/defs/defs.go index b348960df..282ef22c2 100644 --- a/sql3/test/defs/defs.go +++ b/sql3/test/defs/defs.go @@ -45,6 +45,7 @@ var TableTests []TableTest = []TableTest{ setLiteralTests, setFunctionTests, setParameterTests, + setTimeQuantumTests, dateTimePartTests, dateTimeNameTests, toTimestampTests, diff --git a/sql3/test/defs/defs_set_functions.go b/sql3/test/defs/defs_set_functions.go index d16dcf3d7..893f9bfbf 100644 --- a/sql3/test/defs/defs_set_functions.go +++ b/sql3/test/defs/defs_set_functions.go @@ -304,3 +304,93 @@ var setParameterTests = TableTest{ }, }, } + +// test IDSetQ and StringSetQ functions +var setTimeQuantumTests = TableTest{ + name: "selectwithsetqliterals", + Table: tbl( + "selectwithsetqliterals", + srcHdrs( + srcHdr("_id", fldTypeID), + srcHdr("a", fldTypeInt, "min 0", "max 1000"), + srcHdr("b", fldTypeInt, "min 0", "max 1000"), + srcHdr("ssq1", fldTypeStringSetQ, "timequantum 'YMD'"), + srcHdr("isq1", fldTypeIDSetQ, "timequantum 'YMD'"), + ), + ), + SQLTests: []SQLTest{ + // can't find example syntax or docs for how to put time quantum fields in with srcRow() + // so i'm inserting them with SQL statements. + { + SQLs: sqls( + "insert into selectwithsetqliterals(_id, a, b, ssq1, isq1) values (1, 10, 100, {'2022-01-03T00:00:00Z', ['foo']}, {'2022-01-01T00:00:00Z', [99, 101]})", + "insert into selectwithsetqliterals(_id, a, b, ssq1, isq1) values (2, 20, 200, {'2022-01-03T00:00:00Z', ['bar']}, {'2022-01-01T00:00:00Z', [100]})", + "insert into selectwithsetqliterals(_id, a, b, ssq1, isq1) values (3, 30, 300, {'2022-01-03T00:00:00Z', ['foo', 'bar']}, {'2022-01-01T00:00:00Z', [101]})", + ), + ExpHdrs: hdrs(), + ExpRows: rows(), + Compare: CompareExactUnordered, + }, + { + // SetContainsSelectList + name: "set-contains-select-list", + SQLs: sqls( + "select _id, setcontains(ssq1, 'bar') from selectwithsetqliterals", + ), + ExpHdrs: hdrs( + hdr("_id", fldTypeID), + hdr("", fldTypeBool), + ), + ExpRows: rows( + row(int64(1), false), + row(int64(2), true), + row(int64(3), true), + ), + Compare: CompareExactUnordered, + }, + { + // SetContainsSelectListInt + name: "set-contains-select-list-int", + SQLs: sqls( + "select _id, setcontains(isq1, 101) from selectwithsetqliterals", + ), + ExpHdrs: hdrs( + hdr("_id", fldTypeID), + hdr("", fldTypeBool), + ), + ExpRows: rows( + row(int64(1), true), + row(int64(2), false), + row(int64(3), true), + ), + Compare: CompareExactUnordered, + }, + { + // SetContainsWithLiteral + // SetContainsWithLiteralInt + // SetContainsWithLiteralAny + // SetContainsWithLiteralAnyInt + // SetContainsWithLiteralAll + // SetContainsWithLiteralAllInt + name: "set-contains-with-literal", + SQLs: sqls( + "select _id, setcontains(['foo'], 'foo') from selectwithsetqliterals", + "select _id, setcontains([101], 101) from selectwithsetqliterals", + "select _id, setcontainsany(['foo'], ['foo']) from selectwithsetqliterals", + "select _id, setcontainsany([101], [101]) from selectwithsetqliterals", + "select _id, setcontainsall(['foo'], ['foo']) from selectwithsetqliterals", + "select _id, setcontainsall([101], [101]) from selectwithsetqliterals", + ), + ExpHdrs: hdrs( + hdr("_id", fldTypeID), + hdr("", fldTypeBool), + ), + ExpRows: rows( + row(int64(1), true), + row(int64(2), true), + row(int64(3), true), + ), + Compare: CompareExactUnordered, + }, + }, +} diff --git a/sql3/test/defs/defs_timequantum.go b/sql3/test/defs/defs_timequantum.go index 4440139fe..f1330a170 100644 --- a/sql3/test/defs/defs_timequantum.go +++ b/sql3/test/defs/defs_timequantum.go @@ -26,6 +26,48 @@ var timeQuantumTest = TableTest{ ), ExpErr: "an expression of type 'tuple(stringset)' cannot be assigned to type 'stringsetq'", }, + { + SQLs: sqls( + "insert into time_quantum_insert (_id, i1, ss1, ids1) values (1, 1, ['1'], {[1]})", + ), + ExpErr: "an expression of type 'tuple(idset)' cannot be assigned to type 'idsetq'", + }, + { + SQLs: sqls( + "insert into time_quantum_insert (_id, i1, ss1, ids1) values (1, 1, {'notatimestamp', ['1']}, [1])", + ), + ExpErr: "unable to convert 'notatimestamp' to type 'timestamp'", + }, + { + SQLs: sqls( + "insert into time_quantum_insert (_id, i1, ss1, ids1) values (1, 1, ['1'], {'notatimestamp', [1]})", + ), + ExpErr: "unable to convert 'notatimestamp' to type 'timestamp'", + }, + { + SQLs: sqls( + "insert into time_quantum_insert (_id, i1, ss1, ids1) values (1, 1, {'2022-01-01T00:00:00Z', [1]}, {[1]})", + ), + ExpErr: "an expression of type 'tuple(string, idset)' cannot be assigned to type 'stringsetq'", + }, + { + SQLs: sqls( + "insert into time_quantum_insert (_id, i1, ss1, ids1) values (1, 1, ['1'], {'2022-01-01T00:00:00Z', ['1']})", + ), + ExpErr: "an expression of type 'tuple(string, stringset)' cannot be assigned to type 'idsetq'", + }, + { + SQLs: sqls( + "insert into time_quantum_insert (_id, i1, ss1, ids1) values (1, 1, '1', {[1]})", + ), + ExpErr: "an expression of type 'string' cannot be assigned to type 'stringsetq'", + }, + { + SQLs: sqls( + "insert into time_quantum_insert (_id, i1, ss1, ids1) values (1, 1, ['1'], 1)", + ), + ExpErr: "an expression of type 'int' cannot be assigned to type 'idsetq'", + }, { SQLs: sqls( "insert into time_quantum_insert (_id, i1, ss1, ids1) values (1, 1, {1676649734, ['1']}, {1676649734, [1]})", @@ -84,7 +126,7 @@ var timeQuantumTest = TableTest{ SQLs: sqls( "select a._id, a.ss1 from time_quantum_insert a where rangeq(a.ss1, null, null)", ), - ExpErr: "alling ranqeq() 'from' and 'to' parameters cannot both be null", + ExpErr: "calling ranqeq() 'from' and 'to' parameters cannot both be null", }, { SQLs: sqls( @@ -99,6 +141,7 @@ var timeQuantumTest = TableTest{ ExpErr: "calling ranqeq() usage invalid", }, { + name: "stringset-rangeq", SQLs: sqls( "select a._id, a.ss1 from time_quantum_insert a where rangeq(a.ss1, '2022-01-02T00:00:00Z', null)", ), @@ -111,6 +154,20 @@ var timeQuantumTest = TableTest{ ), Compare: CompareExactUnordered, }, + { + name: "idset-rangeq", + SQLs: sqls( + "select a._id, a.ids1 from time_quantum_insert a where rangeq(a.ids1, '2022-01-02T00:00:00Z', null)", + ), + ExpHdrs: hdrs( + hdr("_id", fldTypeID), + hdr("ids1", fldTypeIDSetQ), + ), + ExpRows: rows( + row(int64(1), []int64{1, 2}), + ), + Compare: CompareExactUnordered, + }, }, }