diff --git a/sql3/sql_definitions_test.go b/sql3/sql_definitions_test.go deleted file mode 100644 index 70063bd0d..000000000 --- a/sql3/sql_definitions_test.go +++ /dev/null @@ -1,561 +0,0 @@ -// Copyright 2021 Molecula Corp. All rights reserved. -package sql3_test - -import ( - "time" - - "github.com/molecula/featurebase/v3/pql" -) - -// tableTests is the list of tests which get run by TestSQL_Execute in -// sql_test.go. They're defined here just to keep the test definitions separate -// from the test execution logic. -var tableTests []tableTest = []tableTest{ - { - name: "minmaxnegatives", - table: tbl( - "minmaxnegatives", - srcHdrs( - srcHdr("_id", fldTypeID), - srcHdr("positive_int", fldTypeInt, "min 10", "max 100"), - srcHdr("negative_int", fldTypeInt, "min -100", "max -10"), - ), - srcRows( - srcRow(int64(1), int64(11), int64(-11)), - srcRow(int64(2), int64(22), int64(-22)), - srcRow(int64(3), int64(33), int64(-33)), - ), - ), - sqlTests: []sqlTest{}, - }, - { - name: "unkeyed", - table: tbl( - "unkeyed", - srcHdrs( - srcHdr("_id", fldTypeID), - srcHdr("an_int", fldTypeInt, "min 0", "max 100"), - srcHdr("an_id_set", fldTypeIDSet), - srcHdr("an_id", fldTypeID), - srcHdr("a_string", fldTypeString), - srcHdr("a_string_set", fldTypeStringSet), - srcHdr("a_decimal", fldTypeDecimal2), - ), - srcRows( - srcRow(int64(1), int64(11), []int64{11, 12, 13}, int64(101), "str1", []string{"a1", "b1", "c1"}, float64(123.45)), - srcRow(int64(2), int64(22), []int64{21, 22, 23}, int64(201), "str2", []string{"a2", "b2", "c2"}, float64(234.56)), - srcRow(int64(3), int64(33), []int64{31, 32, 33}, int64(301), "str3", []string{"a3", "b3", "c3"}, float64(345.67)), - srcRow(int64(4), int64(44), []int64{41, 42, 43}, int64(401), "str4", []string{"a4", "b4", "c4"}, float64(456.78)), - ), - ), - sqlTests: []sqlTest{ - { - // Select all. - name: "select-all", - sqls: sqls( - "select * from unkeyed", - "select _id, an_int, an_id_set, an_id, a_string, a_string_set, a_decimal from unkeyed", - ), - expHdrs: hdrs( - hdr("_id", fldTypeID), - hdr("an_int", fldTypeInt), - hdr("an_id_set", fldTypeIDSet), - hdr("an_id", fldTypeID), - hdr("a_string", fldTypeString), - hdr("a_string_set", fldTypeStringSet), - hdr("a_decimal", fldTypeDecimal2), - ), - expRows: rows( - row(int64(1), int64(11), []int64{11, 12, 13}, int64(101), "str1", []string{"a1", "b1", "c1"}, pql.NewDecimal(12345, 2)), - row(int64(2), int64(22), []int64{21, 22, 23}, int64(201), "str2", []string{"a2", "b2", "c2"}, pql.NewDecimal(23456, 2)), - row(int64(3), int64(33), []int64{31, 32, 33}, int64(301), "str3", []string{"a3", "b3", "c3"}, pql.NewDecimal(34567, 2)), - row(int64(4), int64(44), []int64{41, 42, 43}, int64(401), "str4", []string{"a4", "b4", "c4"}, pql.NewDecimal(45678, 2)), - ), - compare: compareExactUnordered, - sortStringKeys: true, - }, - { - // Select all with top. - name: "select-all-with-top", - sqls: sqls( - "select top(2) * from unkeyed", - ), - expHdrs: hdrs( - hdr("_id", fldTypeID), - hdr("an_int", fldTypeInt), - hdr("an_id_set", fldTypeIDSet), - hdr("an_id", fldTypeID), - hdr("a_string", fldTypeString), - hdr("a_string_set", fldTypeStringSet), - hdr("a_decimal", fldTypeDecimal2), - ), - expRows: rows( - row(int64(1), int64(11), []int64{11, 12, 13}, int64(101), "str1", []string{"a1", "b1", "c1"}, pql.NewDecimal(12345, 2)), - row(int64(2), int64(22), []int64{21, 22, 23}, int64(201), "str2", []string{"a2", "b2", "c2"}, pql.NewDecimal(23456, 2)), - ), - compare: compareExactUnordered, - sortStringKeys: true, - }, - { - // Select all with where on each field. - name: "select-all-with-where", - sqls: sqls( - "select * from unkeyed where an_int = 22", - "select * from unkeyed where a_string = 'str2'", - "select * from unkeyed where an_id = 201", - ), - expHdrs: hdrs( - hdr("_id", fldTypeID), - hdr("an_int", fldTypeInt), - hdr("an_id_set", fldTypeIDSet), - hdr("an_id", fldTypeID), - hdr("a_string", fldTypeString), - hdr("a_string_set", fldTypeStringSet), - hdr("a_decimal", fldTypeDecimal2), - ), - expRows: rows( - row(int64(2), int64(22), []int64{21, 22, 23}, int64(201), "str2", []string{"a2", "b2", "c2"}, pql.NewDecimal(23456, 2)), - ), - compare: compareExactOrdered, - sortStringKeys: true, - }, - }, - }, - { - table: tbl( - "keyed", - srcHdrs( - srcHdr("_id", fldTypeString), - srcHdr("an_int", fldTypeInt, "min 0", "max 100"), - srcHdr("an_id_set", fldTypeIDSet), - srcHdr("an_id", fldTypeID), - srcHdr("a_string", fldTypeString), - srcHdr("a_string_set", fldTypeStringSet), - ), - srcRows( - srcRow("one", int64(11), []int64{11, 12, 13}, int64(101), "str1", []string{"a1", "b1", "c1"}), - srcRow("two", int64(22), []int64{21, 22, 23}, int64(201), "str2", []string{"a2", "b2", "c2"}), - srcRow("three", int64(33), []int64{31, 32, 33}, int64(301), "str3", []string{"a3", "b3", "c3"}), - srcRow("four", int64(44), []int64{41, 42, 43}, int64(401), "str4", []string{"a4", "b4", "c4"}), - ), - ), - sqlTests: []sqlTest{ - { - // Select all. - name: "select-all", - sqls: sqls( - "select * from keyed", - "select _id, an_int, an_id_set, an_id, a_string, a_string_set from keyed", - ), - expHdrs: hdrs( - hdr("_id", fldTypeString), - hdr("an_int", fldTypeInt), - hdr("an_id_set", fldTypeIDSet), - hdr("an_id", fldTypeID), - hdr("a_string", fldTypeString), - hdr("a_string_set", fldTypeStringSet), - ), - expRows: rows( - row("one", int64(11), []int64{11, 12, 13}, int64(101), "str1", []string{"a1", "b1", "c1"}), - row("two", int64(22), []int64{21, 22, 23}, int64(201), "str2", []string{"a2", "b2", "c2"}), - row("three", int64(33), []int64{31, 32, 33}, int64(301), "str3", []string{"a3", "b3", "c3"}), - row("four", int64(44), []int64{41, 42, 43}, int64(401), "str4", []string{"a4", "b4", "c4"}), - ), - compare: compareExactUnordered, - sortStringKeys: true, - }, - { - // Select all with top. - name: "select-all-with-top", - sqls: sqls( - "select top(2) * from keyed", - ), - expHdrs: hdrs( - hdr("_id", fldTypeString), - hdr("an_int", fldTypeInt), - hdr("an_id_set", fldTypeIDSet), - hdr("an_id", fldTypeID), - hdr("a_string", fldTypeString), - hdr("a_string_set", fldTypeStringSet), - ), - expRows: rows( - row("one", int64(11), []int64{11, 12, 13}, int64(101), "str1", []string{"a1", "b1", "c1"}), - row("two", int64(22), []int64{21, 22, 23}, int64(201), "str2", []string{"a2", "b2", "c2"}), - row("three", int64(33), []int64{31, 32, 33}, int64(301), "str3", []string{"a3", "b3", "c3"}), - row("four", int64(44), []int64{41, 42, 43}, int64(401), "str4", []string{"a4", "b4", "c4"}), - ), - compare: compareIncludedIn, - sortStringKeys: true, - expRowCount: 2, - }, - { - // Select all with where on int field. - name: "select-all-with-where", - sqls: sqls( - "select * from keyed where an_int = 22", - "select * from keyed where a_string = 'str2'", - "select * from keyed where an_id = 201", - ), - expHdrs: hdrs( - hdr("_id", fldTypeString), - hdr("an_int", fldTypeInt), - hdr("an_id_set", fldTypeIDSet), - hdr("an_id", fldTypeID), - hdr("a_string", fldTypeString), - hdr("a_string_set", fldTypeStringSet), - ), - expRows: rows( - row("two", int64(22), []int64{21, 22, 23}, int64(201), "str2", []string{"a2", "b2", "c2"}), - ), - compare: compareExactUnordered, - sortStringKeys: true, - }, - }, - }, - - setLiteralTests, - setFunctionTests, - setParameterTests, - datePartTests, - - insertTest, - keyedInsertTest, - timestampLiterals, - unaryOpExprWithInt, - unaryOpExprWithID, - unaryOpExprWithBool, - unaryOpExprWithDecimal, - unaryOpExprWithTimestamp, - unaryOpExprWithIDSet, - unaryOpExprWithString, - unaryOpExprWithStringSet, - - binOpExprWithIntInt, - binOpExprWithIntBool, - binOpExprWithIntID, - binOpExprWithIntDecimal, - binOpExprWithIntTimestamp, - binOpExprWithIntIDSet, - binOpExprWithIntString, - binOpExprWithIntStringSet, - - binOpExprWithBoolInt, - binOpExprWithBoolBool, - binOpExprWithBoolID, - binOpExprWithBoolDecimal, - binOpExprWithBoolTimestamp, - binOpExprWithBoolIDSet, - binOpExprWithBoolString, - binOpExprWithBoolStringSet, - - binOpExprWithIDInt, - binOpExprWithIDBool, - binOpExprWithIDID, - binOpExprWithIDDecimal, - binOpExprWithIDTimestamp, - binOpExprWithIDIDSet, - binOpExprWithIDString, - binOpExprWithIDStringSet, - - binOpExprWithDecInt, - binOpExprWithDecBool, - binOpExprWithDecID, - binOpExprWithDecDecimal, - binOpExprWithDecTimestamp, - binOpExprWithDecIDSet, - binOpExprWithDecString, - binOpExprWithDecStringSet, - - binOpExprWithTSInt, - binOpExprWithTSBool, - binOpExprWithTSID, - binOpExprWithTSDecimal, - binOpExprWithTSTimestamp, - binOpExprWithTSIDSet, - binOpExprWithTSString, - binOpExprWithTSStringSet, - - binOpExprWithIDSetInt, - binOpExprWithIDSetBool, - binOpExprWithIDSetID, - binOpExprWithIDSetDecimal, - binOpExprWithIDSetTimestamp, - binOpExprWithIDSetIDSet, - binOpExprWithIDSetString, - binOpExprWithIDSetStringSet, - - binOpExprWithStringInt, - binOpExprWithStringBool, - binOpExprWithStringID, - binOpExprWithStringDecimal, - binOpExprWithStringTimestamp, - binOpExprWithStringIDSet, - binOpExprWithStringString, - binOpExprWithStringStringSet, - - binOpExprWithStringSetInt, - binOpExprWithStringSetBool, - binOpExprWithStringSetID, - binOpExprWithStringSetDecimal, - binOpExprWithStringSetTimestamp, - binOpExprWithStringSetIDSet, - binOpExprWithStringSetString, - binOpExprWithStringSetStringSet, - - //cast tests - castIntLiteral, - castInt, - - castBool, - castDecimal, - castID, - castIDSet, - castString, - castStringSet, - castTimestamp, - - //like tests - likeTests, - notLikeTests, - - //null tests - nullTests, - notNullTests, - - //null filter tests - nullFilterTests, - - //between tests - betweenTests, - notBetweenTests, - - //in tests - inTests, - notInTests, - - //aggregate tests - countTests, - countDistinctTests, - sumTests, - avgTests, - percentileTests, - minmaxTests, - - //groupby tests - groupByTests, - - //create table tests - createTable, - - //joins - joinTestsUsers, - joinTestsOrders, - joinTests, - - //bool (batch logic) - boolTests, - - //time quantums - // Skip for now - timeQuantumInsertTest, -} - -var insertTest = tableTest{ - table: tbl( - "testinsert", - srcHdrs( - srcHdr("_id", fldTypeID), - srcHdr("a", fldTypeInt, "min 0", "max 1000"), - srcHdr("b", fldTypeInt, "min 0", "max 1000"), - srcHdr("s", fldTypeString), - srcHdr("bl", fldTypeBool), - srcHdr("d", fldTypeDecimal2), - srcHdr("event", fldTypeStringSet), - srcHdr("ievent", fldTypeIDSet), - ), - nil, - ), - sqlTests: []sqlTest{ - { - // Insert - sqls: sqls( - "insert into testinsert (_id, a, b, s, bl, d, event, ievent) values (4, 40, 400, 'foo', false, 10.12, ['A', 'B', 'C'], [1, 2, 3])", - ), - expHdrs: hdrs(), - expRows: rows(), - compare: compareExactUnordered, - }, - { - // Replace - sqls: sqls( - "replace into testinsert (_id, a, b, s, bl, d, event, ievent) values (4, 40, 400, 'foo', false, 10.12, ['A', 'B', 'C'], [1, 2, 3])", - ), - expHdrs: hdrs(), - expRows: rows(), - compare: compareExactUnordered, - }, - { - // Insert multiple tuples - sqls: sqls( - "insert into testinsert (_id, a, b, s, bl, d, event, ievent) values (4, 40, 400, 'foo', false, 10.12, ['A', 'B', 'C'], [1, 2, 3]), (5, 50, 500, 'var', true, 20.24, ['X', 'Y', 'Z'], [4, 5, 6])", - ), - expHdrs: hdrs(), - expRows: rows(), - compare: compareExactUnordered, - }, - { - // Insert with nulls - sqls: sqls( - "insert into testinsert (_id, a, b, s, bl, d, event, ievent) values (5, null, null, null, null, null, null, null)", - "insert into testinsert (_id, a, b, s, bl, d, event, ievent) values (6, 1, null, null, null, null, null, null)", - ), - expHdrs: hdrs(), - expRows: rows(), - compare: compareExactUnordered, - }, - { - // Insert with exprs - sqls: sqls( - "insert into testinsert (_id, a, b, s, bl, d, event, ievent) values (4, 40*10, 400+1, 'foo' || 'bar', 1 > 2, 10.12 + 3.1, ['A', 'B', 'C'], [1, 2, 3])", - ), - expHdrs: hdrs(), - expRows: rows(), - compare: compareExactUnordered, - }, - { - // InsertBadTable - sqls: sqls( - "insert into ifoo (a, b) values (1, 2)", - ), - expErr: "table 'ifoo' not found", - }, - { - // InsertBadColumn - sqls: sqls( - "insert into testinsert (c, b) values (1, 2)", - ), - expErr: "column 'c' not found", - }, - { - // InsertDupeColumn - sqls: sqls( - "insert into testinsert (a, a, b) values (1, 2)", - ), - expErr: "duplicate column 'a'", - }, - { - // InsertMismatchColumnValues - sqls: sqls( - "insert into testinsert (_id, a, b) values (1)", - ), - expErr: "mismatch in the count of expressions and target columns", - }, - { - // InsertHandleMissingColumns - sqls: sqls( - "insert into testinsert values (4, 40, 400)", - ), - expErr: "mismatch in the count of expressions and target columns", - }, - { - // InsertHandleMissingId - sqls: sqls( - "insert into testinsert (a, b) values (1, 2)", - ), - expErr: "insert column list must have '_id' column specified", - }, - { - // InsertHandleMissingIdPlusOneOther - sqls: sqls( - "insert into testinsert (_id) values (1)", - ), - expErr: "insert column list must have at least one non '_id' column specified", - }, - { - // InsertSetsTypeError - sqls: sqls( - "insert into testinsert (_id, a, event) values (4, 40, [101, 150])", - ), - expErr: "an expression of type 'IDSET' cannot be assigned to type 'STRINGSET'", - }, - { - // InsertSetsTypeError2 - sqls: sqls( - "insert into testinsert (_id, a, ievent) values (4, 40, ['POST', 'GET'])", - ), - expErr: "an expression of type 'STRINGSET' cannot be assigned to type 'IDSET'", - }, - }, -} - -var keyedInsertTest = tableTest{ - name: "keyedinsert", - table: tbl( - "testkeyedinsert", - srcHdrs( - srcHdr("_id", fldTypeString), - srcHdr("a", fldTypeInt, "min 0", "max 1000"), - srcHdr("b", fldTypeInt, "min 0", "max 1000"), - srcHdr("s", fldTypeString), - srcHdr("bl", fldTypeBool), - srcHdr("d", fldTypeDecimal2), - srcHdr("event", fldTypeStringSet), - srcHdr("ievent", fldTypeIDSet), - ), - nil, - ), - sqlTests: []sqlTest{ - { - // Insert - sqls: sqls( - "insert into testkeyedinsert (_id, a, b, s, bl, d, event, ievent) values ('four', 40, 400, 'foo', false, 10.12, ['A', 'B', 'C'], [1, 2, 3])", - ), - expHdrs: hdrs(), - expRows: rows(), - compare: compareExactUnordered, - }, - }, -} - -func knownTimestamp() time.Time { - tm, err := time.ParseInLocation(time.RFC3339, "2012-11-01T22:08:41+00:00", time.UTC) - if err != nil { - panic(err.Error()) - } - return tm -} - -var timestampLiterals = tableTest{ - table: tbl( - "testtimestampliterals", - srcHdrs( - srcHdr("_id", fldTypeID), - srcHdr("a", fldTypeInt, "min 0", "max 1000"), - srcHdr("b", fldTypeInt, "min 0", "max 1000"), - srcHdr("d", fldTypeDecimal2), - srcHdr("ts", fldTypeTimestamp), - srcHdr("event", fldTypeStringSet), - srcHdr("ievent", fldTypeIDSet), - ), - srcRows(), - ), - sqlTests: []sqlTest{ - { - // InsertWithCurrentTimestamp - sqls: sqls( - "insert into testtimestampliterals (_id, a, b, d, ts, event, ievent) values (4, 40, 400, 10.12, current_timestamp, ['A', 'B', 'C'], [1, 2, 3])", - ), - expHdrs: hdrs(), - expRows: rows(), - compare: compareExactUnordered, - }, - { - // InsertWithCurrentDate - sqls: sqls( - "insert into testtimestampliterals (_id, a, b, d, ts, event, ievent) values (4, 40, 400, 10.12, current_date, ['A', 'B', 'C'], [1, 2, 3])", - ), - expHdrs: hdrs(), - expRows: rows(), - compare: compareExactUnordered, - }, - }, -} diff --git a/sql3/sql_defs_binops_test.go b/sql3/sql_defs_binops_test.go deleted file mode 100644 index 05a2283dd..000000000 --- a/sql3/sql_defs_binops_test.go +++ /dev/null @@ -1,7923 +0,0 @@ -package sql3_test - -import ( - "time" - - "github.com/molecula/featurebase/v3/pql" -) - -// INT bin op tests -var binOpExprWithIntInt = tableTest{ - table: tbl( - "binoptesti_i", - srcHdrs( - srcHdr("_id", fldTypeID), - srcHdr("a", fldTypeInt, "min 0", "max 1000"), - srcHdr("b", fldTypeInt, "min 0", "max 1000"), - ), - srcRows( - srcRow(int64(1), int64(10), int64(20)), - ), - ), - sqlTests: []sqlTest{ - { - sqls: sqls( - "select a != b from binoptesti_i;", - ), - expHdrs: hdrs( - hdr("", fldTypeBool), - ), - expRows: rows( - row(bool(true)), - ), - compare: compareExactUnordered, - }, - { - sqls: sqls( - "select a = b from binoptesti_i;", - ), - expHdrs: hdrs( - hdr("", fldTypeBool), - ), - expRows: rows( - row(bool(false)), - ), - compare: compareExactUnordered, - }, - { - sqls: sqls( - "select a <= b from binoptesti_i;", - ), - expHdrs: hdrs( - hdr("", fldTypeBool), - ), - expRows: rows( - row(bool(true)), - ), - compare: compareExactUnordered, - }, - { - sqls: sqls( - "select a >= b from binoptesti_i;", - ), - expHdrs: hdrs( - hdr("", fldTypeBool), - ), - expRows: rows( - row(bool(false)), - ), - compare: compareExactUnordered, - }, - { - sqls: sqls( - "select a < b from binoptesti_i;", - ), - expHdrs: hdrs( - hdr("", fldTypeBool), - ), - expRows: rows( - row(bool(true)), - ), - compare: compareExactUnordered, - }, - { - sqls: sqls( - "select a > b from binoptesti_i;", - ), - expHdrs: hdrs( - hdr("", fldTypeBool), - ), - expRows: rows( - row(bool(false)), - ), - compare: compareExactUnordered, - }, - { - sqls: sqls( - "select a & b from binoptesti_i;", - ), - expHdrs: hdrs( - hdr("", fldTypeInt), - ), - expRows: rows( - row(int64(0)), - ), - compare: compareExactUnordered, - }, - { - sqls: sqls( - "select a | b from binoptesti_i;", - ), - expHdrs: hdrs( - hdr("", fldTypeInt), - ), - expRows: rows( - row(int64(30)), - ), - compare: compareExactUnordered, - }, - { - sqls: sqls( - "select a << b from binoptesti_i;", - ), - expHdrs: hdrs( - hdr("", fldTypeInt), - ), - expRows: rows( - row(int64(10485760)), - ), - compare: compareExactUnordered, - }, - { - sqls: sqls( - "select a >> b from binoptesti_i;", - ), - expHdrs: hdrs( - hdr("", fldTypeInt), - ), - expRows: rows( - row(int64(0)), - ), - compare: compareExactUnordered, - }, - { - sqls: sqls( - "select a + b from binoptesti_i;", - ), - expHdrs: hdrs( - hdr("", fldTypeInt), - ), - expRows: rows( - row(int64(30)), - ), - compare: compareExactUnordered, - }, - { - sqls: sqls( - "select a - b from binoptesti_i;", - ), - expHdrs: hdrs( - hdr("", fldTypeInt), - ), - expRows: rows( - row(int64(-10)), - ), - compare: compareExactUnordered, - }, - { - sqls: sqls( - "select a * b from binoptesti_i;", - ), - expHdrs: hdrs( - hdr("", fldTypeInt), - ), - expRows: rows( - row(int64(200)), - ), - compare: compareExactUnordered, - }, - { - sqls: sqls( - "select a / b from binoptesti_i;", - ), - expHdrs: hdrs( - hdr("", fldTypeInt), - ), - expRows: rows( - row(int64(0)), - ), - compare: compareExactUnordered, - }, - { - sqls: sqls( - "select a % b from binoptesti_i;", - ), - expHdrs: hdrs( - hdr("", fldTypeInt), - ), - expRows: rows( - row(int64(10)), - ), - compare: compareExactUnordered, - }, - { - sqls: sqls( - "select a || b from binoptesti_i;", - ), - expErr: "operator '||' incompatible with type 'INT'", - }, - }, -} - -var binOpExprWithIntBool = tableTest{ - table: tbl( - "binoptesti_b", - srcHdrs( - srcHdr("_id", fldTypeID), - srcHdr("a", fldTypeInt, "min 0", "max 1000"), - srcHdr("b", fldTypeBool), - ), - srcRows( - srcRow(int64(1), int64(10), bool(true)), - ), - ), - sqlTests: []sqlTest{ - { - sqls: sqls( - "select a != b from binoptesti_b;", - ), - expErr: "types 'INT' and 'BOOL' are not equatable", - }, - { - sqls: sqls( - "select a = b from binoptesti_b;", - ), - expErr: "types 'INT' and 'BOOL' are not equatable", - }, - { - sqls: sqls( - "select a <= b from binoptesti_b;", - ), - expErr: "operator '<=' incompatible with type 'BOOL'", - }, - { - sqls: sqls( - "select a >= b from binoptesti_b;", - ), - expErr: "operator '>=' incompatible with type 'BOOL'", - }, - { - sqls: sqls( - "select a < b from binoptesti_b;", - ), - expErr: "operator '<' incompatible with type 'BOOL'", - }, - { - sqls: sqls( - "select a > b from binoptesti_b;", - ), - expErr: "operator '>' incompatible with type 'BOOL'", - }, - { - sqls: sqls( - "select a & b from binoptesti_b;", - ), - expErr: "operator '&' incompatible with type 'BOOL'", - }, - { - sqls: sqls( - "select a | b from binoptesti_b;", - ), - expErr: "operator '|' incompatible with type 'BOOL'", - }, - { - sqls: sqls( - "select a << b from binoptesti_b;", - ), - expErr: "operator '<<' incompatible with type 'BOOL'", - }, - { - sqls: sqls( - "select a >> b from binoptesti_b;", - ), - expErr: "operator '>>' incompatible with type 'BOOL'", - }, - { - sqls: sqls( - "select a + b from binoptesti_b;", - ), - expErr: "operator '+' incompatible with type 'BOOL'", - }, - { - sqls: sqls( - "select a - b from binoptesti_b;", - ), - expErr: "operator '-' incompatible with type 'BOOL'", - }, - { - sqls: sqls( - "select a * b from binoptesti_b;", - ), - expErr: "operator '*' incompatible with type 'BOOL'", - }, - { - sqls: sqls( - "select a / b from binoptesti_b;", - ), - expErr: "operator '/' incompatible with type 'BOOL'", - }, - { - sqls: sqls( - "select a % b from binoptesti_b;", - ), - expErr: "operator '%' incompatible with type 'BOOL'", - }, - { - sqls: sqls( - "select a || b from binoptesti_b;", - ), - expErr: "operator '||' incompatible with type 'INT'", - }, - }, -} - -var binOpExprWithIntID = tableTest{ - table: tbl( - "binoptesti_id", - srcHdrs( - srcHdr("_id", fldTypeID), - srcHdr("b", fldTypeInt, "min 0", "max 1000"), - ), - srcRows( - srcRow(int64(10), int64(20)), - ), - ), - sqlTests: []sqlTest{ - { - sqls: sqls( - "select b != _id from binoptesti_id;", - ), - expHdrs: hdrs( - hdr("", fldTypeBool), - ), - expRows: rows( - row(bool(true)), - ), - compare: compareExactUnordered, - }, - { - sqls: sqls( - "select b = _id from binoptesti_id;", - ), - expHdrs: hdrs( - hdr("", fldTypeBool), - ), - expRows: rows( - row(bool(false)), - ), - compare: compareExactUnordered, - }, - { - sqls: sqls( - "select b <= _id from binoptesti_id;", - ), - expHdrs: hdrs( - hdr("", fldTypeBool), - ), - expRows: rows( - row(bool(false)), - ), - compare: compareExactUnordered, - }, - { - sqls: sqls( - "select b >= _id from binoptesti_id;", - ), - expHdrs: hdrs( - hdr("", fldTypeBool), - ), - expRows: rows( - row(bool(true)), - ), - compare: compareExactUnordered, - }, - { - sqls: sqls( - "select b < _id from binoptesti_id;", - ), - expHdrs: hdrs( - hdr("", fldTypeBool), - ), - expRows: rows( - row(bool(false)), - ), - compare: compareExactUnordered, - }, - { - sqls: sqls( - "select b > _id from binoptesti_id;", - ), - expHdrs: hdrs( - hdr("", fldTypeBool), - ), - expRows: rows( - row(bool(true)), - ), - compare: compareExactUnordered, - }, - { - sqls: sqls( - "select b & _id from binoptesti_id;", - ), - expHdrs: hdrs( - hdr("", fldTypeInt), - ), - expRows: rows( - row(int64(0)), - ), - compare: compareExactUnordered, - }, - { - sqls: sqls( - "select b | _id from binoptesti_id;", - ), - expHdrs: hdrs( - hdr("", fldTypeInt), - ), - expRows: rows( - row(int64(30)), - ), - compare: compareExactUnordered, - }, - { - sqls: sqls( - "select b << _id from binoptesti_id;", - ), - expHdrs: hdrs( - hdr("", fldTypeInt), - ), - expRows: rows( - row(int64(20480)), - ), - compare: compareExactUnordered, - }, - { - sqls: sqls( - "select b >> _id from binoptesti_id;", - ), - expHdrs: hdrs( - hdr("", fldTypeInt), - ), - expRows: rows( - row(int64(0)), - ), - compare: compareExactUnordered, - }, - { - sqls: sqls( - "select b + _id from binoptesti_id;", - ), - expHdrs: hdrs( - hdr("", fldTypeInt), - ), - expRows: rows( - row(int64(30)), - ), - compare: compareExactUnordered, - }, - { - sqls: sqls( - "select b - _id from binoptesti_id;", - ), - expHdrs: hdrs( - hdr("", fldTypeInt), - ), - expRows: rows( - row(int64(10)), - ), - compare: compareExactUnordered, - }, - { - sqls: sqls( - "select b * _id from binoptesti_id;", - ), - expHdrs: hdrs( - hdr("", fldTypeInt), - ), - expRows: rows( - row(int64(200)), - ), - compare: compareExactUnordered, - }, - { - sqls: sqls( - "select b / _id from binoptesti_id;", - ), - expHdrs: hdrs( - hdr("", fldTypeInt), - ), - expRows: rows( - row(int64(2)), - ), - compare: compareExactUnordered, - }, - { - sqls: sqls( - "select b % _id from binoptesti_id;", - ), - expHdrs: hdrs( - hdr("", fldTypeInt), - ), - expRows: rows( - row(int64(0)), - ), - compare: compareExactUnordered, - }, - { - sqls: sqls( - "select b || _id from binoptesti_id;", - ), - expErr: "operator '||' incompatible with type 'INT'", - }, - }, -} - -var binOpExprWithIntDecimal = tableTest{ - table: tbl( - "binoptesti_d", - srcHdrs( - srcHdr("_id", fldTypeID), - srcHdr("a", fldTypeInt, "min 0", "max 1000"), - srcHdr("d", fldTypeDecimal2), - ), - srcRows( - srcRow(int64(1), int64(20), float64(12.34)), - ), - ), - sqlTests: []sqlTest{ - { - sqls: sqls( - "select a != d from binoptesti_d;", - ), - expHdrs: hdrs( - hdr("", fldTypeBool), - ), - expRows: rows( - row(bool(true)), - ), - compare: compareExactUnordered, - }, - { - sqls: sqls( - "select a = d from binoptesti_d;", - ), - expHdrs: hdrs( - hdr("", fldTypeBool), - ), - expRows: rows( - row(bool(false)), - ), - compare: compareExactUnordered, - }, - { - sqls: sqls( - "select a <= d from binoptesti_d;", - ), - expHdrs: hdrs( - hdr("", fldTypeBool), - ), - expRows: rows( - row(bool(false)), - ), - compare: compareExactUnordered, - }, - { - sqls: sqls( - "select a >= d from binoptesti_d;", - ), - expHdrs: hdrs( - hdr("", fldTypeBool), - ), - expRows: rows( - row(bool(true)), - ), - compare: compareExactUnordered, - }, - { - sqls: sqls( - "select a < d from binoptesti_d;", - ), - expHdrs: hdrs( - hdr("", fldTypeBool), - ), - expRows: rows( - row(bool(false)), - ), - compare: compareExactUnordered, - }, - { - sqls: sqls( - "select a > d from binoptesti_d;", - ), - expHdrs: hdrs( - hdr("", fldTypeBool), - ), - expRows: rows( - row(bool(true)), - ), - compare: compareExactUnordered, - }, - { - sqls: sqls( - "select a & d from binoptesti_d;", - ), - expErr: "operator '&' incompatible with type 'DECIMAL(2)'", - }, - { - sqls: sqls( - "select a | d from binoptesti_d;", - ), - expErr: "operator '|' incompatible with type 'DECIMAL(2)'", - }, - { - sqls: sqls( - "select a << d from binoptesti_d;", - ), - expErr: "operator '<<' incompatible with type 'DECIMAL(2)'", - }, - { - sqls: sqls( - "select a >> d from binoptesti_d;", - ), - expErr: "operator '>>' incompatible with type 'DECIMAL(2)'", - }, - { - sqls: sqls( - "select a + d from binoptesti_d;", - ), - expHdrs: hdrs( - hdr("", fldTypeDecimal2), - ), - expRows: rows( - row(pql.NewDecimal(3234, 2)), - ), - compare: compareExactUnordered, - }, - { - sqls: sqls( - "select a - d from binoptesti_d;", - ), - expHdrs: hdrs( - hdr("", fldTypeDecimal2), - ), - expRows: rows( - row(pql.NewDecimal(766, 2)), - ), - compare: compareExactUnordered, - }, - { - sqls: sqls( - "select a * d from binoptesti_d;", - ), - expHdrs: hdrs( - hdr("", fldTypeDecimal2), - ), - expRows: rows( - row(pql.NewDecimal(24680, 2)), - ), - compare: compareExactUnordered, - }, - { - sqls: sqls( - "select a / d from binoptesti_d;", - ), - expHdrs: hdrs( - hdr("", fldTypeDecimal2), - ), - expRows: rows( - row(pql.NewDecimal(162, 2)), - ), - compare: compareExactUnordered, - }, - { - sqls: sqls( - "select a % d from binoptesti_d;", - ), - expErr: "operator '%' incompatible with type 'DECIMAL(2)'", - }, - { - sqls: sqls( - "select a || d from binoptesti_d;", - ), - expErr: "operator '||' incompatible with type 'INT'", - }, - }, -} - -var binOpExprWithIntTimestamp = tableTest{ - table: tbl( - "binoptesti_ts", - srcHdrs( - srcHdr("_id", fldTypeID), - srcHdr("a", fldTypeInt, "min 0", "max 1000"), - srcHdr("ts", fldTypeTimestamp), - ), - srcRows( - srcRow(int64(1), int64(20), time.Time(knownTimestamp())), - ), - ), - sqlTests: []sqlTest{ - { - sqls: sqls( - "select a != ts from binoptesti_ts;", - ), - expErr: "types 'INT' and 'TIMESTAMP' are not equatable", - }, - { - sqls: sqls( - "select a = ts from binoptesti_ts;", - ), - expErr: "types 'INT' and 'TIMESTAMP' are not equatable", - }, - { - sqls: sqls( - "select a <= ts from binoptesti_ts;", - ), - expErr: "types 'INT' and 'TIMESTAMP' are not equatable", - }, - { - sqls: sqls( - "select a >= ts from binoptesti_ts;", - ), - expErr: "types 'INT' and 'TIMESTAMP' are not equatable", - }, - { - sqls: sqls( - "select a < ts from binoptesti_ts;", - ), - expErr: "types 'INT' and 'TIMESTAMP' are not equatable", - }, - { - sqls: sqls( - "select a > ts from binoptesti_ts;", - ), - expErr: "types 'INT' and 'TIMESTAMP' are not equatable", - }, - { - sqls: sqls( - "select a & ts from binoptesti_ts;", - ), - expErr: "operator '&' incompatible with type 'TIMESTAMP'", - }, - { - sqls: sqls( - "select a | ts from binoptesti_ts;", - ), - expErr: "operator '|' incompatible with type 'TIMESTAMP'", - }, - { - sqls: sqls( - "select a << ts from binoptesti_ts;", - ), - expErr: "operator '<<' incompatible with type 'TIMESTAMP'", - }, - { - sqls: sqls( - "select a >> ts from binoptesti_ts;", - ), - expErr: "operator '>>' incompatible with type 'TIMESTAMP'", - }, - { - sqls: sqls( - "select a + ts from binoptesti_ts;", - ), - expErr: "operator '+' incompatible with type 'TIMESTAMP'", - }, - { - sqls: sqls( - "select a - ts from binoptesti_ts;", - ), - expErr: "operator '-' incompatible with type 'TIMESTAMP'", - }, - { - sqls: sqls( - "select a * ts from binoptesti_ts;", - ), - expErr: "operator '*' incompatible with type 'TIMESTAMP'", - }, - { - sqls: sqls( - "select a / ts from binoptesti_ts;", - ), - expErr: "operator '/' incompatible with type 'TIMESTAMP'", - }, - { - sqls: sqls( - "select a % ts from binoptesti_ts;", - ), - expErr: "operator '%' incompatible with type 'TIMESTAMP'", - }, - { - sqls: sqls( - "select a || ts from binoptesti_ts;", - ), - expErr: "operator '||' incompatible with type 'INT'", - }, - }, -} - -var binOpExprWithIntIDSet = tableTest{ - table: tbl( - "binoptesti_ids", - srcHdrs( - srcHdr("_id", fldTypeID), - srcHdr("a", fldTypeInt, "min 0", "max 1000"), - srcHdr("b", fldTypeIDSet), - ), - srcRows( - srcRow(int64(1), int64(20), []int64{101, 102}), - ), - ), - sqlTests: []sqlTest{ - { - sqls: sqls( - "select a != b from binoptesti_ids;", - ), - expErr: "types 'INT' and 'IDSET' are not equatable", - }, - { - sqls: sqls( - "select a = b from binoptesti_ids;", - ), - expErr: "types 'INT' and 'IDSET' are not equatable", - }, - { - sqls: sqls( - "select a <= b from binoptesti_ids;", - ), - expErr: " operator '<=' incompatible with type 'IDSET'", - }, - { - sqls: sqls( - "select a >= b from binoptesti_ids;", - ), - expErr: " operator '>=' incompatible with type 'IDSET'", - }, - { - sqls: sqls( - "select a < b from binoptesti_ids;", - ), - expErr: " operator '<' incompatible with type 'IDSET'", - }, - { - sqls: sqls( - "select a > b from binoptesti_ids;", - ), - expErr: " operator '>' incompatible with type 'IDSET'", - }, - { - sqls: sqls( - "select a & b from binoptesti_ids;", - ), - expErr: " operator '&' incompatible with type 'IDSET'", - }, - { - sqls: sqls( - "select a | b from binoptesti_ids;", - ), - expErr: " operator '|' incompatible with type 'IDSET'", - }, - { - sqls: sqls( - "select a << b from binoptesti_ids;", - ), - expErr: " operator '<<' incompatible with type 'IDSET'", - }, - { - sqls: sqls( - "select a >> b from binoptesti_ids;", - ), - expErr: " operator '>>' incompatible with type 'IDSET'", - }, - { - sqls: sqls( - "select a + b from binoptesti_ids;", - ), - expErr: " operator '+' incompatible with type 'IDSET'", - }, - { - sqls: sqls( - "select a - b from binoptesti_ids;", - ), - expErr: " operator '-' incompatible with type 'IDSET'", - }, - { - sqls: sqls( - "select a * b from binoptesti_ids;", - ), - expErr: " operator '*' incompatible with type 'IDSET'", - }, - { - sqls: sqls( - "select a / b from binoptesti_ids;", - ), - expErr: " operator '/' incompatible with type 'IDSET'", - }, - { - sqls: sqls( - "select a % b from binoptesti_ids;", - ), - expErr: " operator '%' incompatible with type 'IDSET'", - }, - { - sqls: sqls( - "select a || b from binoptesti_ids;", - ), - expErr: "operator '||' incompatible with type 'INT'", - }, - }, -} - -var binOpExprWithIntString = tableTest{ - table: tbl( - "binoptesti_s", - srcHdrs( - srcHdr("_id", fldTypeID), - srcHdr("a", fldTypeInt, "min 0", "max 1000"), - srcHdr("b", fldTypeString), - ), - srcRows( - srcRow(int64(1), int64(20), string("101")), - ), - ), - sqlTests: []sqlTest{ - { - sqls: sqls( - "select a != b from binoptesti_s;", - ), - expErr: "types 'INT' and 'STRING' are not equatable", - }, - { - sqls: sqls( - "select a = b from binoptesti_s;", - ), - expErr: "types 'INT' and 'STRING' are not equatable", - }, - { - sqls: sqls( - "select a <= b from binoptesti_s;", - ), - expErr: " operator '<=' incompatible with type 'STRING'", - }, - { - sqls: sqls( - "select a >= b from binoptesti_s;", - ), - expErr: " operator '>=' incompatible with type 'STRING'", - }, - { - sqls: sqls( - "select a < b from binoptesti_s;", - ), - expErr: " operator '<' incompatible with type 'STRING'", - }, - { - sqls: sqls( - "select a > b from binoptesti_s;", - ), - expErr: " operator '>' incompatible with type 'STRING'", - }, - { - sqls: sqls( - "select a & b from binoptesti_s;", - ), - expErr: " operator '&' incompatible with type 'STRING'", - }, - { - sqls: sqls( - "select a | b from binoptesti_s;", - ), - expErr: " operator '|' incompatible with type 'STRING'", - }, - { - sqls: sqls( - "select a << b from binoptesti_s;", - ), - expErr: " operator '<<' incompatible with type 'STRING'", - }, - { - sqls: sqls( - "select a >> b from binoptesti_s;", - ), - expErr: " operator '>>' incompatible with type 'STRING'", - }, - { - sqls: sqls( - "select a + b from binoptesti_s;", - ), - expErr: " operator '+' incompatible with type 'STRING'", - }, - { - sqls: sqls( - "select a - b from binoptesti_s;", - ), - expErr: " operator '-' incompatible with type 'STRING'", - }, - { - sqls: sqls( - "select a * b from binoptesti_s;", - ), - expErr: " operator '*' incompatible with type 'STRING'", - }, - { - sqls: sqls( - "select a / b from binoptesti_s;", - ), - expErr: " operator '/' incompatible with type 'STRING'", - }, - { - sqls: sqls( - "select a % b from binoptesti_s;", - ), - expErr: " operator '%' incompatible with type 'STRING'", - }, - { - sqls: sqls( - "select a || b from binoptesti_s;", - ), - expErr: "operator '||' incompatible with type 'INT'", - }, - }, -} - -var binOpExprWithIntStringSet = tableTest{ - table: tbl( - "binoptesti_ss", - srcHdrs( - srcHdr("_id", fldTypeID), - srcHdr("a", fldTypeInt, "min 0", "max 1000"), - srcHdr("b", fldTypeStringSet), - ), - srcRows( - srcRow(int64(1), int64(20), []string{"101", "102"}), - ), - ), - sqlTests: []sqlTest{ - { - sqls: sqls( - "select a != b from binoptesti_ss;", - ), - expErr: "types 'INT' and 'STRINGSET' are not equatable", - }, - { - sqls: sqls( - "select a = b from binoptesti_ss;", - ), - expErr: "types 'INT' and 'STRINGSET' are not equatable", - }, - { - sqls: sqls( - "select a <= b from binoptesti_ss;", - ), - expErr: " operator '<=' incompatible with type 'STRINGSET'", - }, - { - sqls: sqls( - "select a >= b from binoptesti_ss;", - ), - expErr: " operator '>=' incompatible with type 'STRINGSET'", - }, - { - sqls: sqls( - "select a < b from binoptesti_ss;", - ), - expErr: " operator '<' incompatible with type 'STRINGSET'", - }, - { - sqls: sqls( - "select a > b from binoptesti_ss;", - ), - expErr: " operator '>' incompatible with type 'STRINGSET'", - }, - { - sqls: sqls( - "select a & b from binoptesti_ss;", - ), - expErr: " operator '&' incompatible with type 'STRINGSET'", - }, - { - sqls: sqls( - "select a | b from binoptesti_ss;", - ), - expErr: " operator '|' incompatible with type 'STRINGSET'", - }, - { - sqls: sqls( - "select a << b from binoptesti_ss;", - ), - expErr: " operator '<<' incompatible with type 'STRINGSET'", - }, - { - sqls: sqls( - "select a >> b from binoptesti_ss;", - ), - expErr: " operator '>>' incompatible with type 'STRINGSET'", - }, - { - sqls: sqls( - "select a + b from binoptesti_ss;", - ), - expErr: " operator '+' incompatible with type 'STRINGSET'", - }, - { - sqls: sqls( - "select a - b from binoptesti_ss;", - ), - expErr: " operator '-' incompatible with type 'STRINGSET'", - }, - { - sqls: sqls( - "select a * b from binoptesti_ss;", - ), - expErr: " operator '*' incompatible with type 'STRINGSET'", - }, - { - sqls: sqls( - "select a / b from binoptesti_ss;", - ), - expErr: " operator '/' incompatible with type 'STRINGSET'", - }, - { - sqls: sqls( - "select a % b from binoptesti_ss;", - ), - expErr: " operator '%' incompatible with type 'STRINGSET'", - }, - { - sqls: sqls( - "select a || b from binoptesti_ss;", - ), - expErr: "operator '||' incompatible with type 'INT'", - }, - }, -} - -// BOOL bin op tests -var binOpExprWithBoolInt = tableTest{ - table: tbl( - "binoptestb_i", - srcHdrs( - srcHdr("_id", fldTypeID), - srcHdr("a", fldTypeBool), - srcHdr("b", fldTypeInt, "min 0", "max 1000"), - ), - srcRows( - srcRow(int64(1), bool(true), int64(20)), - ), - ), - sqlTests: []sqlTest{ - { - sqls: sqls( - "select a != b from binoptestb_i;", - ), - expErr: "types 'BOOL' and 'INT' are not equatable", - }, - { - sqls: sqls( - "select a = b from binoptestb_i;", - ), - expErr: "types 'BOOL' and 'INT' are not equatable", - }, - { - sqls: sqls( - "select a <= b from binoptestb_i;", - ), - expErr: "operator '<=' incompatible with type 'BOOL'", - }, - { - sqls: sqls( - "select a >= b from binoptestb_i;", - ), - expErr: "operator '>=' incompatible with type 'BOOL'", - }, - { - sqls: sqls( - "select a < b from binoptestb_i;", - ), - expErr: "operator '<' incompatible with type 'BOOL'", - }, - { - sqls: sqls( - "select a > b from binoptestb_i;", - ), - expErr: "operator '>' incompatible with type 'BOOL'", - }, - { - sqls: sqls( - "select a & b from binoptestb_i;", - ), - expErr: "operator '&' incompatible with type 'BOOL'", - }, - { - sqls: sqls( - "select a | b from binoptestb_i;", - ), - expErr: "operator '|' incompatible with type 'BOOL'", - }, - { - sqls: sqls( - "select a << b from binoptestb_i;", - ), - expErr: "operator '<<' incompatible with type 'BOOL'", - }, - { - sqls: sqls( - "select a >> b from binoptestb_i;", - ), - expErr: "operator '>>' incompatible with type 'BOOL'", - }, - { - sqls: sqls( - "select a + b from binoptestb_i;", - ), - expErr: "operator '+' incompatible with type 'BOOL'", - }, - { - sqls: sqls( - "select a - b from binoptestb_i;", - ), - expErr: "operator '-' incompatible with type 'BOOL'", - }, - { - sqls: sqls( - "select a * b from binoptestb_i;", - ), - expErr: "operator '*' incompatible with type 'BOOL'", - }, - { - sqls: sqls( - "select a / b from binoptestb_i;", - ), - expErr: "operator '/' incompatible with type 'BOOL'", - }, - { - sqls: sqls( - "select a % b from binoptestb_i;", - ), - expErr: "operator '%' incompatible with type 'BOOL'", - }, - { - sqls: sqls( - "select a || b from binoptestb_i;", - ), - expErr: "operator '||' incompatible with type 'BOOL'", - }, - }, -} - -var binOpExprWithBoolBool = tableTest{ - table: tbl( - "binoptestb_b", - srcHdrs( - srcHdr("_id", fldTypeID), - srcHdr("a", fldTypeBool), - srcHdr("b", fldTypeBool), - ), - srcRows( - srcRow(int64(1), bool(true), bool(true)), - ), - ), - sqlTests: []sqlTest{ - { - sqls: sqls( - "select a != b from binoptestb_b;", - ), - expHdrs: hdrs( - hdr("", fldTypeBool), - ), - expRows: rows( - row(bool(false)), - ), - compare: compareExactUnordered, - }, - { - sqls: sqls( - "select a = b from binoptestb_b;", - ), - expHdrs: hdrs( - hdr("", fldTypeBool), - ), - expRows: rows( - row(bool(true)), - ), - compare: compareExactUnordered, - }, - { - sqls: sqls( - "select a <= b from binoptestb_b;", - ), - expErr: "operator '<=' incompatible with type 'BOOL'", - }, - { - sqls: sqls( - "select a >= b from binoptestb_b;", - ), - expErr: "operator '>=' incompatible with type 'BOOL'", - }, - { - sqls: sqls( - "select a < b from binoptestb_b;", - ), - expErr: "operator '<' incompatible with type 'BOOL'", - }, - { - sqls: sqls( - "select a > b from binoptestb_b;", - ), - expErr: "operator '>' incompatible with type 'BOOL'", - }, - { - sqls: sqls( - "select a & b from binoptestb_b;", - ), - expErr: "operator '&' incompatible with type 'BOOL'", - }, - { - sqls: sqls( - "select a | b from binoptestb_b;", - ), - expErr: "operator '|' incompatible with type 'BOOL'", - }, - { - sqls: sqls( - "select a << b from binoptestb_b;", - ), - expErr: "operator '<<' incompatible with type 'BOOL'", - }, - { - sqls: sqls( - "select a >> b from binoptestb_b;", - ), - expErr: "operator '>>' incompatible with type 'BOOL'", - }, - { - sqls: sqls( - "select a + b from binoptestb_b;", - ), - expErr: "operator '+' incompatible with type 'BOOL'", - }, - { - sqls: sqls( - "select a - b from binoptestb_b;", - ), - expErr: "operator '-' incompatible with type 'BOOL'", - }, - { - sqls: sqls( - "select a * b from binoptestb_b;", - ), - expErr: "operator '*' incompatible with type 'BOOL'", - }, - { - sqls: sqls( - "select a / b from binoptestb_b;", - ), - expErr: "operator '/' incompatible with type 'BOOL'", - }, - { - sqls: sqls( - "select a % b from binoptestb_b;", - ), - expErr: "operator '%' incompatible with type 'BOOL'", - }, - { - sqls: sqls( - "select a || b from binoptestb_b;", - ), - expErr: "operator '||' incompatible with type 'BOOL'", - }, - }, -} - -var binOpExprWithBoolID = tableTest{ - table: tbl( - "binoptestb_id", - srcHdrs( - srcHdr("_id", fldTypeID), - srcHdr("b", fldTypeBool), - ), - srcRows( - srcRow(int64(10), bool(true)), - ), - ), - sqlTests: []sqlTest{ - { - sqls: sqls( - "select b != _id from binoptestb_id;", - ), - expErr: "types 'BOOL' and 'ID' are not equatable", - }, - { - sqls: sqls( - "select b = _id from binoptestb_id;", - ), - expErr: "types 'BOOL' and 'ID' are not equatable", - }, - { - sqls: sqls( - "select b <= _id from binoptestb_id;", - ), - expErr: "operator '<=' incompatible with type 'BOOL'", - }, - { - sqls: sqls( - "select b >= _id from binoptestb_id;", - ), - expErr: "operator '>=' incompatible with type 'BOOL'", - }, - { - sqls: sqls( - "select b < _id from binoptestb_id;", - ), - expErr: "operator '<' incompatible with type 'BOOL'", - }, - { - sqls: sqls( - "select b > _id from binoptestb_id;", - ), - expErr: "operator '>' incompatible with type 'BOOL'", - }, - { - sqls: sqls( - "select b & _id from binoptestb_id;", - ), - expErr: "operator '&' incompatible with type 'BOOL'", - }, - { - sqls: sqls( - "select b | _id from binoptestb_id;", - ), - expErr: "operator '|' incompatible with type 'BOOL'", - }, - { - sqls: sqls( - "select b << _id from binoptestb_id;", - ), - expErr: "operator '<<' incompatible with type 'BOOL'", - }, - { - sqls: sqls( - "select b >> _id from binoptestb_id;", - ), - expErr: "operator '>>' incompatible with type 'BOOL'", - }, - { - sqls: sqls( - "select b + _id from binoptestb_id;", - ), - expErr: "operator '+' incompatible with type 'BOOL'", - }, - { - sqls: sqls( - "select b - _id from binoptestb_id;", - ), - expErr: "operator '-' incompatible with type 'BOOL'", - }, - { - sqls: sqls( - "select b * _id from binoptestb_id;", - ), - expErr: "operator '*' incompatible with type 'BOOL'", - }, - { - sqls: sqls( - "select b / _id from binoptestb_id;", - ), - expErr: "operator '/' incompatible with type 'BOOL'", - }, - { - sqls: sqls( - "select b % _id from binoptestb_id;", - ), - expErr: "operator '%' incompatible with type 'BOOL'", - }, - { - sqls: sqls( - "select b || _id from binoptestb_id;", - ), - expErr: "operator '||' incompatible with type 'BOOL'", - }, - }, -} - -var binOpExprWithBoolDecimal = tableTest{ - table: tbl( - "binoptestb_d", - srcHdrs( - srcHdr("_id", fldTypeID), - srcHdr("a", fldTypeBool), - srcHdr("d", fldTypeDecimal2), - ), - srcRows( - srcRow(int64(1), bool(true), float64(12.34)), - ), - ), - sqlTests: []sqlTest{ - { - sqls: sqls( - "select a != d from binoptestb_d;", - ), - expErr: "types 'BOOL' and 'DECIMAL(2)' are not equatable", - }, - { - sqls: sqls( - "select a = d from binoptestb_d;", - ), - expErr: "types 'BOOL' and 'DECIMAL(2)' are not equatable", - }, - { - sqls: sqls( - "select a <= d from binoptestb_d;", - ), - expErr: "operator '<=' incompatible with type 'BOOL'", - }, - { - sqls: sqls( - "select a >= d from binoptestb_d;", - ), - expErr: "operator '>=' incompatible with type 'BOOL'", - }, - { - sqls: sqls( - "select a < d from binoptestb_d;", - ), - expErr: "operator '<' incompatible with type 'BOOL'", - }, - { - sqls: sqls( - "select a > d from binoptestb_d;", - ), - expErr: "operator '>' incompatible with type 'BOOL'", - }, - { - sqls: sqls( - "select a & d from binoptestb_d;", - ), - expErr: "operator '&' incompatible with type 'BOOL'", - }, - { - sqls: sqls( - "select a | d from binoptestb_d;", - ), - expErr: "operator '|' incompatible with type 'BOOL'", - }, - { - sqls: sqls( - "select a << d from binoptestb_d;", - ), - expErr: "operator '<<' incompatible with type 'BOOL'", - }, - { - sqls: sqls( - "select a >> d from binoptestb_d;", - ), - expErr: "operator '>>' incompatible with type 'BOOL'", - }, - { - sqls: sqls( - "select a + d from binoptestb_d;", - ), - expErr: "operator '+' incompatible with type 'BOOL'", - }, - { - sqls: sqls( - "select a - d from binoptestb_d;", - ), - expErr: "operator '-' incompatible with type 'BOOL'", - }, - { - sqls: sqls( - "select a * d from binoptestb_d;", - ), - expErr: "operator '*' incompatible with type 'BOOL'", - }, - { - sqls: sqls( - "select a / d from binoptestb_d;", - ), - expErr: "operator '/' incompatible with type 'BOOL'", - }, - { - sqls: sqls( - "select a % d from binoptestb_d;", - ), - expErr: "operator '%' incompatible with type 'BOOL'", - }, - { - sqls: sqls( - "select a || d from binoptestb_d;", - ), - expErr: "operator '||' incompatible with type 'BOOL'", - }, - }, -} - -var binOpExprWithBoolTimestamp = tableTest{ - table: tbl( - "binoptestb_ts", - srcHdrs( - srcHdr("_id", fldTypeID), - srcHdr("a", fldTypeBool), - srcHdr("ts", fldTypeTimestamp), - ), - srcRows( - srcRow(int64(1), bool(true), time.Time(knownTimestamp())), - ), - ), - sqlTests: []sqlTest{ - { - sqls: sqls( - "select a != ts from binoptestb_ts;", - ), - expErr: "types 'BOOL' and 'TIMESTAMP' are not equatable", - }, - { - sqls: sqls( - "select a = ts from binoptestb_ts;", - ), - expErr: "types 'BOOL' and 'TIMESTAMP' are not equatable", - }, - { - sqls: sqls( - "select a <= ts from binoptestb_ts;", - ), - expErr: "operator '<=' incompatible with type 'BOOL'", - }, - { - sqls: sqls( - "select a >= ts from binoptestb_ts;", - ), - expErr: "operator '>=' incompatible with type 'BOOL'", - }, - { - sqls: sqls( - "select a < ts from binoptestb_ts;", - ), - expErr: "operator '<' incompatible with type 'BOOL'", - }, - { - sqls: sqls( - "select a > ts from binoptestb_ts;", - ), - expErr: "operator '>' incompatible with type 'BOOL'", - }, - { - sqls: sqls( - "select a & ts from binoptestb_ts;", - ), - expErr: "operator '&' incompatible with type 'BOOL'", - }, - { - sqls: sqls( - "select a | ts from binoptestb_ts;", - ), - expErr: "operator '|' incompatible with type 'BOOL'", - }, - { - sqls: sqls( - "select a << ts from binoptestb_ts;", - ), - expErr: "operator '<<' incompatible with type 'BOOL'", - }, - { - sqls: sqls( - "select a >> ts from binoptestb_ts;", - ), - expErr: "operator '>>' incompatible with type 'BOOL'", - }, - { - sqls: sqls( - "select a + ts from binoptestb_ts;", - ), - expErr: "operator '+' incompatible with type 'BOOL'", - }, - { - sqls: sqls( - "select a - ts from binoptestb_ts;", - ), - expErr: "operator '-' incompatible with type 'BOOL'", - }, - { - sqls: sqls( - "select a * ts from binoptestb_ts;", - ), - expErr: "operator '*' incompatible with type 'BOOL'", - }, - { - sqls: sqls( - "select a / ts from binoptestb_ts;", - ), - expErr: "operator '/' incompatible with type 'BOOL'", - }, - { - sqls: sqls( - "select a % ts from binoptestb_ts;", - ), - expErr: "operator '%' incompatible with type 'BOOL'", - }, - { - sqls: sqls( - "select a || ts from binoptestb_ts;", - ), - expErr: "operator '||' incompatible with type 'BOOL'", - }, - }, -} - -var binOpExprWithBoolIDSet = tableTest{ - table: tbl( - "binoptestb_ids", - srcHdrs( - srcHdr("_id", fldTypeID), - srcHdr("a", fldTypeBool), - srcHdr("b", fldTypeIDSet), - ), - srcRows( - srcRow(int64(1), bool(true), []int64{101, 102}), - ), - ), - sqlTests: []sqlTest{ - { - sqls: sqls( - "select a != b from binoptestb_ids;", - ), - expErr: "types 'BOOL' and 'IDSET' are not equatable", - }, - { - sqls: sqls( - "select a = b from binoptestb_ids;", - ), - expErr: "types 'BOOL' and 'IDSET' are not equatable", - }, - { - sqls: sqls( - "select a <= b from binoptestb_ids;", - ), - expErr: " operator '<=' incompatible with type 'BOOL'", - }, - { - sqls: sqls( - "select a >= b from binoptestb_ids;", - ), - expErr: " operator '>=' incompatible with type 'BOOL'", - }, - { - sqls: sqls( - "select a < b from binoptestb_ids;", - ), - expErr: " operator '<' incompatible with type 'BOOL'", - }, - { - sqls: sqls( - "select a > b from binoptestb_ids;", - ), - expErr: " operator '>' incompatible with type 'BOOL'", - }, - { - sqls: sqls( - "select a & b from binoptestb_ids;", - ), - expErr: " operator '&' incompatible with type 'BOOL'", - }, - { - sqls: sqls( - "select a | b from binoptestb_ids;", - ), - expErr: " operator '|' incompatible with type 'BOOL'", - }, - { - sqls: sqls( - "select a << b from binoptestb_ids;", - ), - expErr: " operator '<<' incompatible with type 'BOOL'", - }, - { - sqls: sqls( - "select a >> b from binoptestb_ids;", - ), - expErr: " operator '>>' incompatible with type 'BOOL'", - }, - { - sqls: sqls( - "select a + b from binoptestb_ids;", - ), - expErr: " operator '+' incompatible with type 'BOOL'", - }, - { - sqls: sqls( - "select a - b from binoptestb_ids;", - ), - expErr: " operator '-' incompatible with type 'BOOL'", - }, - { - sqls: sqls( - "select a * b from binoptestb_ids;", - ), - expErr: " operator '*' incompatible with type 'BOOL'", - }, - { - sqls: sqls( - "select a / b from binoptestb_ids;", - ), - expErr: " operator '/' incompatible with type 'BOOL'", - }, - { - sqls: sqls( - "select a % b from binoptestb_ids;", - ), - expErr: " operator '%' incompatible with type 'BOOL'", - }, - { - sqls: sqls( - "select a || b from binoptestb_ids;", - ), - expErr: "operator '||' incompatible with type 'BOOL'", - }, - }, -} - -var binOpExprWithBoolString = tableTest{ - table: tbl( - "binoptestb_s", - srcHdrs( - srcHdr("_id", fldTypeID), - srcHdr("a", fldTypeBool), - srcHdr("b", fldTypeString), - ), - srcRows( - srcRow(int64(1), bool(true), string("101")), - ), - ), - sqlTests: []sqlTest{ - { - sqls: sqls( - "select a != b from binoptestb_s;", - ), - expErr: "types 'BOOL' and 'STRING' are not equatable", - }, - { - sqls: sqls( - "select a = b from binoptestb_s;", - ), - expErr: "types 'BOOL' and 'STRING' are not equatable", - }, - { - sqls: sqls( - "select a <= b from binoptestb_s;", - ), - expErr: " operator '<=' incompatible with type 'BOOL'", - }, - { - sqls: sqls( - "select a >= b from binoptestb_s;", - ), - expErr: " operator '>=' incompatible with type 'BOOL'", - }, - { - sqls: sqls( - "select a < b from binoptestb_s;", - ), - expErr: " operator '<' incompatible with type 'BOOL'", - }, - { - sqls: sqls( - "select a > b from binoptestb_s;", - ), - expErr: " operator '>' incompatible with type 'BOOL'", - }, - { - sqls: sqls( - "select a & b from binoptestb_s;", - ), - expErr: " operator '&' incompatible with type 'BOOL'", - }, - { - sqls: sqls( - "select a | b from binoptestb_s;", - ), - expErr: " operator '|' incompatible with type 'BOOL'", - }, - { - sqls: sqls( - "select a << b from binoptestb_s;", - ), - expErr: " operator '<<' incompatible with type 'BOOL'", - }, - { - sqls: sqls( - "select a >> b from binoptestb_s;", - ), - expErr: " operator '>>' incompatible with type 'BOOL'", - }, - { - sqls: sqls( - "select a + b from binoptestb_s;", - ), - expErr: " operator '+' incompatible with type 'BOOL'", - }, - { - sqls: sqls( - "select a - b from binoptestb_s;", - ), - expErr: " operator '-' incompatible with type 'BOOL'", - }, - { - sqls: sqls( - "select a * b from binoptestb_s;", - ), - expErr: " operator '*' incompatible with type 'BOOL'", - }, - { - sqls: sqls( - "select a / b from binoptestb_s;", - ), - expErr: " operator '/' incompatible with type 'BOOL'", - }, - { - sqls: sqls( - "select a % b from binoptestb_s;", - ), - expErr: " operator '%' incompatible with type 'BOOL'", - }, - { - sqls: sqls( - "select a || b from binoptestb_s;", - ), - expErr: "operator '||' incompatible with type 'BOOL'", - }, - }, -} - -var binOpExprWithBoolStringSet = tableTest{ - table: tbl( - "binoptestb_ss", - srcHdrs( - srcHdr("_id", fldTypeID), - srcHdr("a", fldTypeBool), - srcHdr("b", fldTypeStringSet), - ), - srcRows( - srcRow(int64(1), bool(true), []string{"101", "102"}), - ), - ), - sqlTests: []sqlTest{ - { - sqls: sqls( - "select a != b from binoptestb_ss;", - ), - expErr: "types 'BOOL' and 'STRINGSET' are not equatable", - }, - { - sqls: sqls( - "select a = b from binoptestb_ss;", - ), - expErr: "types 'BOOL' and 'STRINGSET' are not equatable", - }, - { - sqls: sqls( - "select a <= b from binoptestb_ss;", - ), - expErr: " operator '<=' incompatible with type 'BOOL'", - }, - { - sqls: sqls( - "select a >= b from binoptestb_ss;", - ), - expErr: " operator '>=' incompatible with type 'BOOL'", - }, - { - sqls: sqls( - "select a < b from binoptestb_ss;", - ), - expErr: " operator '<' incompatible with type 'BOOL'", - }, - { - sqls: sqls( - "select a > b from binoptestb_ss;", - ), - expErr: " operator '>' incompatible with type 'BOOL'", - }, - { - sqls: sqls( - "select a & b from binoptestb_ss;", - ), - expErr: " operator '&' incompatible with type 'BOOL'", - }, - { - sqls: sqls( - "select a | b from binoptestb_ss;", - ), - expErr: " operator '|' incompatible with type 'BOOL'", - }, - { - sqls: sqls( - "select a << b from binoptestb_ss;", - ), - expErr: " operator '<<' incompatible with type 'BOOL'", - }, - { - sqls: sqls( - "select a >> b from binoptestb_ss;", - ), - expErr: " operator '>>' incompatible with type 'BOOL'", - }, - { - sqls: sqls( - "select a + b from binoptestb_ss;", - ), - expErr: " operator '+' incompatible with type 'BOOL'", - }, - { - sqls: sqls( - "select a - b from binoptestb_ss;", - ), - expErr: " operator '-' incompatible with type 'BOOL'", - }, - { - sqls: sqls( - "select a * b from binoptestb_ss;", - ), - expErr: " operator '*' incompatible with type 'BOOL'", - }, - { - sqls: sqls( - "select a / b from binoptestb_ss;", - ), - expErr: " operator '/' incompatible with type 'BOOL'", - }, - { - sqls: sqls( - "select a % b from binoptestb_ss;", - ), - expErr: " operator '%' incompatible with type 'BOOL'", - }, - { - sqls: sqls( - "select a || b from binoptestb_ss;", - ), - expErr: "operator '||' incompatible with type 'BOOL'", - }, - }, -} - -// ID bin op tests -var binOpExprWithIDInt = tableTest{ - table: tbl( - "binoptestid_i", - srcHdrs( - srcHdr("_id", fldTypeID), - srcHdr("b", fldTypeInt, "min 0", "max 1000"), - ), - srcRows( - srcRow(int64(10), int64(20)), - ), - ), - sqlTests: []sqlTest{ - { - sqls: sqls( - "select _id != b from binoptestid_i;", - ), - expHdrs: hdrs( - hdr("", fldTypeBool), - ), - expRows: rows( - row(bool(true)), - ), - compare: compareExactUnordered, - }, - { - sqls: sqls( - "select _id = b from binoptestid_i;", - ), - expHdrs: hdrs( - hdr("", fldTypeBool), - ), - expRows: rows( - row(bool(false)), - ), - compare: compareExactUnordered, - }, - { - sqls: sqls( - "select _id <= b from binoptestid_i;", - ), - expHdrs: hdrs( - hdr("", fldTypeBool), - ), - expRows: rows( - row(bool(true)), - ), - compare: compareExactUnordered, - }, - { - sqls: sqls( - "select _id >= b from binoptestid_i;", - ), - expHdrs: hdrs( - hdr("", fldTypeBool), - ), - expRows: rows( - row(bool(false)), - ), - compare: compareExactUnordered, - }, - { - sqls: sqls( - "select _id < b from binoptestid_i;", - ), - expHdrs: hdrs( - hdr("", fldTypeBool), - ), - expRows: rows( - row(bool(true)), - ), - compare: compareExactUnordered, - }, - { - sqls: sqls( - "select _id > b from binoptestid_i;", - ), - expHdrs: hdrs( - hdr("", fldTypeBool), - ), - expRows: rows( - row(bool(false)), - ), - compare: compareExactUnordered, - }, - { - sqls: sqls( - "select _id & b from binoptestid_i;", - ), - expHdrs: hdrs( - hdr("", fldTypeInt), - ), - expRows: rows( - row(int64(0)), - ), - compare: compareExactUnordered, - }, - { - sqls: sqls( - "select _id | b from binoptestid_i;", - ), - expHdrs: hdrs( - hdr("", fldTypeInt), - ), - expRows: rows( - row(int64(30)), - ), - compare: compareExactUnordered, - }, - { - sqls: sqls( - "select _id << b from binoptestid_i;", - ), - expHdrs: hdrs( - hdr("", fldTypeInt), - ), - expRows: rows( - row(int64(10485760)), - ), - compare: compareExactUnordered, - }, - { - sqls: sqls( - "select _id >> b from binoptestid_i;", - ), - expHdrs: hdrs( - hdr("", fldTypeInt), - ), - expRows: rows( - row(int64(0)), - ), - compare: compareExactUnordered, - }, - { - sqls: sqls( - "select _id + b from binoptestid_i;", - ), - expHdrs: hdrs( - hdr("", fldTypeInt), - ), - expRows: rows( - row(int64(30)), - ), - compare: compareExactUnordered, - }, - { - sqls: sqls( - "select _id - b from binoptestid_i;", - ), - expHdrs: hdrs( - hdr("", fldTypeInt), - ), - expRows: rows( - row(int64(-10)), - ), - compare: compareExactUnordered, - }, - { - sqls: sqls( - "select _id * b from binoptestid_i;", - ), - expHdrs: hdrs( - hdr("", fldTypeInt), - ), - expRows: rows( - row(int64(200)), - ), - compare: compareExactUnordered, - }, - { - sqls: sqls( - "select _id / b from binoptestid_i;", - ), - expHdrs: hdrs( - hdr("", fldTypeInt), - ), - expRows: rows( - row(int64(0)), - ), - compare: compareExactUnordered, - }, - { - sqls: sqls( - "select _id % b from binoptestid_i;", - ), - expHdrs: hdrs( - hdr("", fldTypeInt), - ), - expRows: rows( - row(int64(10)), - ), - compare: compareExactUnordered, - }, - { - sqls: sqls( - "select _id || b from binoptestid_i;", - ), - expErr: "operator '||' incompatible with type 'ID'", - }, - }, -} - -var binOpExprWithIDBool = tableTest{ - table: tbl( - "binoptestid_b", - srcHdrs( - srcHdr("_id", fldTypeID), - srcHdr("b", fldTypeBool), - ), - srcRows( - srcRow(int64(10), bool(true)), - ), - ), - sqlTests: []sqlTest{ - { - sqls: sqls( - "select _id != b from binoptestid_b;", - ), - expErr: "types 'ID' and 'BOOL' are not equatable", - }, - { - sqls: sqls( - "select _id = b from binoptestid_b;", - ), - expErr: "types 'ID' and 'BOOL' are not equatable", - }, - { - sqls: sqls( - "select _id <= b from binoptestid_b;", - ), - expErr: "operator '<=' incompatible with type 'BOOL'", - }, - { - sqls: sqls( - "select _id >= b from binoptestid_b;", - ), - expErr: "operator '>=' incompatible with type 'BOOL'", - }, - { - sqls: sqls( - "select _id < b from binoptestid_b;", - ), - expErr: "operator '<' incompatible with type 'BOOL'", - }, - { - sqls: sqls( - "select _id > b from binoptestid_b;", - ), - expErr: "operator '>' incompatible with type 'BOOL'", - }, - { - sqls: sqls( - "select _id & b from binoptestid_b;", - ), - expErr: "operator '&' incompatible with type 'BOOL'", - }, - { - sqls: sqls( - "select _id | b from binoptestid_b;", - ), - expErr: "operator '|' incompatible with type 'BOOL'", - }, - { - sqls: sqls( - "select _id << b from binoptestid_b;", - ), - expErr: "operator '<<' incompatible with type 'BOOL'", - }, - { - sqls: sqls( - "select _id >> b from binoptestid_b;", - ), - expErr: "operator '>>' incompatible with type 'BOOL'", - }, - { - sqls: sqls( - "select _id + b from binoptestid_b;", - ), - expErr: "operator '+' incompatible with type 'BOOL'", - }, - { - sqls: sqls( - "select _id - b from binoptestid_b;", - ), - expErr: "operator '-' incompatible with type 'BOOL'", - }, - { - sqls: sqls( - "select _id * b from binoptestid_b;", - ), - expErr: "operator '*' incompatible with type 'BOOL'", - }, - { - sqls: sqls( - "select _id / b from binoptestid_b;", - ), - expErr: "operator '/' incompatible with type 'BOOL'", - }, - { - sqls: sqls( - "select _id % b from binoptestid_b;", - ), - expErr: "operator '%' incompatible with type 'BOOL'", - }, - { - sqls: sqls( - "select _id || b from binoptestid_b;", - ), - expErr: "operator '||' incompatible with type 'ID'", - }, - }, -} - -var binOpExprWithIDID = tableTest{ - table: tbl( - "binoptestid_id", - srcHdrs( - srcHdr("_id", fldTypeID), - srcHdr("b", fldTypeID), - ), - srcRows( - srcRow(int64(10), int64(20)), - ), - ), - sqlTests: []sqlTest{ - { - sqls: sqls( - "select _id != b from binoptestid_id;", - ), - expHdrs: hdrs( - hdr("", fldTypeBool), - ), - expRows: rows( - row(bool(true)), - ), - compare: compareExactUnordered, - }, - { - sqls: sqls( - "select _id = b from binoptestid_id;", - ), - expHdrs: hdrs( - hdr("", fldTypeBool), - ), - expRows: rows( - row(bool(false)), - ), - compare: compareExactUnordered, - }, - { - sqls: sqls( - "select _id <= b from binoptestid_id;", - ), - expHdrs: hdrs( - hdr("", fldTypeBool), - ), - expRows: rows( - row(bool(true)), - ), - compare: compareExactUnordered, - }, - { - sqls: sqls( - "select _id >= b from binoptestid_id;", - ), - expHdrs: hdrs( - hdr("", fldTypeBool), - ), - expRows: rows( - row(bool(false)), - ), - compare: compareExactUnordered, - }, - { - sqls: sqls( - "select _id < b from binoptestid_id;", - ), - expHdrs: hdrs( - hdr("", fldTypeBool), - ), - expRows: rows( - row(bool(true)), - ), - compare: compareExactUnordered, - }, - { - sqls: sqls( - "select _id > b from binoptestid_id;", - ), - expHdrs: hdrs( - hdr("", fldTypeBool), - ), - expRows: rows( - row(bool(false)), - ), - compare: compareExactUnordered, - }, - { - sqls: sqls( - "select _id & b from binoptestid_id;", - ), - expHdrs: hdrs( - hdr("", fldTypeID), - ), - expRows: rows( - row(int64(0)), - ), - compare: compareExactUnordered, - }, - { - sqls: sqls( - "select _id | b from binoptestid_id;", - ), - expHdrs: hdrs( - hdr("", fldTypeID), - ), - expRows: rows( - row(int64(30)), - ), - compare: compareExactUnordered, - }, - { - sqls: sqls( - "select _id << b from binoptestid_id;", - ), - expHdrs: hdrs( - hdr("", fldTypeID), - ), - expRows: rows( - row(int64(10485760)), - ), - compare: compareExactUnordered, - }, - { - sqls: sqls( - "select _id >> b from binoptestid_id;", - ), - expHdrs: hdrs( - hdr("", fldTypeID), - ), - expRows: rows( - row(int64(0)), - ), - compare: compareExactUnordered, - }, - { - sqls: sqls( - "select _id + b from binoptestid_id;", - ), - expHdrs: hdrs( - hdr("", fldTypeID), - ), - expRows: rows( - row(int64(30)), - ), - compare: compareExactUnordered, - }, - { - sqls: sqls( - "select _id - b from binoptestid_id;", - ), - expHdrs: hdrs( - hdr("", fldTypeID), - ), - expRows: rows( - row(int64(-10)), - ), - compare: compareExactUnordered, - }, - { - sqls: sqls( - "select _id * b from binoptestid_id;", - ), - expHdrs: hdrs( - hdr("", fldTypeID), - ), - expRows: rows( - row(int64(200)), - ), - compare: compareExactUnordered, - }, - { - sqls: sqls( - "select _id / b from binoptestid_id;", - ), - expHdrs: hdrs( - hdr("", fldTypeID), - ), - expRows: rows( - row(int64(0)), - ), - compare: compareExactUnordered, - }, - { - sqls: sqls( - "select _id % b from binoptestid_id;", - ), - expHdrs: hdrs( - hdr("", fldTypeID), - ), - expRows: rows( - row(int64(10)), - ), - compare: compareExactUnordered, - }, - { - sqls: sqls( - "select _id || b from binoptestid_id;", - ), - expErr: "operator '||' incompatible with type 'ID'", - }, - }, -} - -var binOpExprWithIDDecimal = tableTest{ - table: tbl( - "binoptestid_d", - srcHdrs( - srcHdr("_id", fldTypeID), - srcHdr("a", fldTypeID), - srcHdr("d", fldTypeDecimal2), - ), - srcRows( - srcRow(int64(1), int64(20), float64(12.34)), - ), - ), - sqlTests: []sqlTest{ - { - sqls: sqls( - "select a != d from binoptesti_d;", - ), - expHdrs: hdrs( - hdr("", fldTypeBool), - ), - expRows: rows( - row(bool(true)), - ), - compare: compareExactUnordered, - }, - { - sqls: sqls( - "select a = d from binoptesti_d;", - ), - expHdrs: hdrs( - hdr("", fldTypeBool), - ), - expRows: rows( - row(bool(false)), - ), - compare: compareExactUnordered, - }, - { - sqls: sqls( - "select a <= d from binoptesti_d;", - ), - expHdrs: hdrs( - hdr("", fldTypeBool), - ), - expRows: rows( - row(bool(false)), - ), - compare: compareExactUnordered, - }, - { - sqls: sqls( - "select a >= d from binoptesti_d;", - ), - expHdrs: hdrs( - hdr("", fldTypeBool), - ), - expRows: rows( - row(bool(true)), - ), - compare: compareExactUnordered, - }, - { - sqls: sqls( - "select a < d from binoptesti_d;", - ), - expHdrs: hdrs( - hdr("", fldTypeBool), - ), - expRows: rows( - row(bool(false)), - ), - compare: compareExactUnordered, - }, - { - sqls: sqls( - "select a > d from binoptesti_d;", - ), - expHdrs: hdrs( - hdr("", fldTypeBool), - ), - expRows: rows( - row(bool(true)), - ), - compare: compareExactUnordered, - }, - { - sqls: sqls( - "select a & d from binoptesti_d;", - ), - expErr: "operator '&' incompatible with type 'DECIMAL(2)'", - }, - { - sqls: sqls( - "select a | d from binoptesti_d;", - ), - expErr: "operator '|' incompatible with type 'DECIMAL(2)'", - }, - { - sqls: sqls( - "select a << d from binoptesti_d;", - ), - expErr: "operator '<<' incompatible with type 'DECIMAL(2)'", - }, - { - sqls: sqls( - "select a >> d from binoptesti_d;", - ), - expErr: "operator '>>' incompatible with type 'DECIMAL(2)'", - }, - { - sqls: sqls( - "select a + d from binoptesti_d;", - ), - expHdrs: hdrs( - hdr("", fldTypeDecimal2), - ), - expRows: rows( - row(pql.NewDecimal(3234, 2)), - ), - compare: compareExactUnordered, - }, - { - sqls: sqls( - "select a - d from binoptesti_d;", - ), - expHdrs: hdrs( - hdr("", fldTypeDecimal2), - ), - expRows: rows( - row(pql.NewDecimal(766, 2)), - ), - compare: compareExactUnordered, - }, - { - sqls: sqls( - "select a * d from binoptesti_d;", - ), - expHdrs: hdrs( - hdr("", fldTypeDecimal2), - ), - expRows: rows( - row(pql.NewDecimal(24680, 2)), - ), - compare: compareExactUnordered, - }, - { - sqls: sqls( - "select a / d from binoptesti_d;", - ), - expHdrs: hdrs( - hdr("", fldTypeDecimal2), - ), - expRows: rows( - row(pql.NewDecimal(162, 2)), - ), - compare: compareExactUnordered, - }, - { - sqls: sqls( - "select a % d from binoptesti_d;", - ), - expErr: "operator '%' incompatible with type 'DECIMAL(2)'", - }, - { - sqls: sqls( - "select a || d from binoptesti_d;", - ), - expErr: "operator '||' incompatible with type 'INT'", - }, - }, -} - -var binOpExprWithIDTimestamp = tableTest{ - table: tbl( - "binoptestid_ts", - srcHdrs( - srcHdr("_id", fldTypeID), - srcHdr("a", fldTypeID), - srcHdr("ts", fldTypeTimestamp), - ), - srcRows( - srcRow(int64(1), int64(20), time.Time(knownTimestamp())), - ), - ), - sqlTests: []sqlTest{ - { - sqls: sqls( - "select a != ts from binoptesti_ts;", - ), - expErr: "types 'INT' and 'TIMESTAMP' are not equatable", - }, - { - sqls: sqls( - "select a = ts from binoptesti_ts;", - ), - expErr: "types 'INT' and 'TIMESTAMP' are not equatable", - }, - { - sqls: sqls( - "select a <= ts from binoptesti_ts;", - ), - expErr: "types 'INT' and 'TIMESTAMP' are not equatable", - }, - { - sqls: sqls( - "select a >= ts from binoptesti_ts;", - ), - expErr: "types 'INT' and 'TIMESTAMP' are not equatable", - }, - { - sqls: sqls( - "select a < ts from binoptesti_ts;", - ), - expErr: "types 'INT' and 'TIMESTAMP' are not equatable", - }, - { - sqls: sqls( - "select a > ts from binoptesti_ts;", - ), - expErr: "types 'INT' and 'TIMESTAMP' are not equatable", - }, - { - sqls: sqls( - "select a & ts from binoptesti_ts;", - ), - expErr: "operator '&' incompatible with type 'TIMESTAMP'", - }, - { - sqls: sqls( - "select a | ts from binoptesti_ts;", - ), - expErr: "operator '|' incompatible with type 'TIMESTAMP'", - }, - { - sqls: sqls( - "select a << ts from binoptesti_ts;", - ), - expErr: "operator '<<' incompatible with type 'TIMESTAMP'", - }, - { - sqls: sqls( - "select a >> ts from binoptesti_ts;", - ), - expErr: "operator '>>' incompatible with type 'TIMESTAMP'", - }, - { - sqls: sqls( - "select a + ts from binoptesti_ts;", - ), - expErr: "operator '+' incompatible with type 'TIMESTAMP'", - }, - { - sqls: sqls( - "select a - ts from binoptesti_ts;", - ), - expErr: "operator '-' incompatible with type 'TIMESTAMP'", - }, - { - sqls: sqls( - "select a * ts from binoptesti_ts;", - ), - expErr: "operator '*' incompatible with type 'TIMESTAMP'", - }, - { - sqls: sqls( - "select a / ts from binoptesti_ts;", - ), - expErr: "operator '/' incompatible with type 'TIMESTAMP'", - }, - { - sqls: sqls( - "select a % ts from binoptesti_ts;", - ), - expErr: "operator '%' incompatible with type 'TIMESTAMP'", - }, - { - sqls: sqls( - "select a || ts from binoptesti_ts;", - ), - expErr: "operator '||' incompatible with type 'INT'", - }, - }, -} - -var binOpExprWithIDIDSet = tableTest{ - table: tbl( - "binoptestid_ids", - srcHdrs( - srcHdr("_id", fldTypeID), - srcHdr("a", fldTypeID), - srcHdr("b", fldTypeIDSet), - ), - srcRows( - srcRow(int64(1), int64(20), []int64{101, 102}), - ), - ), - sqlTests: []sqlTest{ - { - sqls: sqls( - "select a != b from binoptesti_ids;", - ), - expErr: "types 'INT' and 'IDSET' are not equatable", - }, - { - sqls: sqls( - "select a = b from binoptesti_ids;", - ), - expErr: "types 'INT' and 'IDSET' are not equatable", - }, - { - sqls: sqls( - "select a <= b from binoptesti_ids;", - ), - expErr: " operator '<=' incompatible with type 'IDSET'", - }, - { - sqls: sqls( - "select a >= b from binoptesti_ids;", - ), - expErr: " operator '>=' incompatible with type 'IDSET'", - }, - { - sqls: sqls( - "select a < b from binoptesti_ids;", - ), - expErr: " operator '<' incompatible with type 'IDSET'", - }, - { - sqls: sqls( - "select a > b from binoptesti_ids;", - ), - expErr: " operator '>' incompatible with type 'IDSET'", - }, - { - sqls: sqls( - "select a & b from binoptesti_ids;", - ), - expErr: " operator '&' incompatible with type 'IDSET'", - }, - { - sqls: sqls( - "select a | b from binoptesti_ids;", - ), - expErr: " operator '|' incompatible with type 'IDSET'", - }, - { - sqls: sqls( - "select a << b from binoptesti_ids;", - ), - expErr: " operator '<<' incompatible with type 'IDSET'", - }, - { - sqls: sqls( - "select a >> b from binoptesti_ids;", - ), - expErr: " operator '>>' incompatible with type 'IDSET'", - }, - { - sqls: sqls( - "select a + b from binoptesti_ids;", - ), - expErr: " operator '+' incompatible with type 'IDSET'", - }, - { - sqls: sqls( - "select a - b from binoptesti_ids;", - ), - expErr: " operator '-' incompatible with type 'IDSET'", - }, - { - sqls: sqls( - "select a * b from binoptesti_ids;", - ), - expErr: " operator '*' incompatible with type 'IDSET'", - }, - { - sqls: sqls( - "select a / b from binoptesti_ids;", - ), - expErr: " operator '/' incompatible with type 'IDSET'", - }, - { - sqls: sqls( - "select a % b from binoptesti_ids;", - ), - expErr: " operator '%' incompatible with type 'IDSET'", - }, - { - sqls: sqls( - "select a || b from binoptesti_ids;", - ), - expErr: "operator '||' incompatible with type 'INT'", - }, - }, -} - -var binOpExprWithIDString = tableTest{ - table: tbl( - "binoptestid_s", - srcHdrs( - srcHdr("_id", fldTypeID), - srcHdr("a", fldTypeID), - srcHdr("b", fldTypeString), - ), - srcRows( - srcRow(int64(1), int64(20), string("101")), - ), - ), - sqlTests: []sqlTest{ - { - sqls: sqls( - "select a != b from binoptesti_s;", - ), - expErr: "types 'INT' and 'STRING' are not equatable", - }, - { - sqls: sqls( - "select a = b from binoptesti_s;", - ), - expErr: "types 'INT' and 'STRING' are not equatable", - }, - { - sqls: sqls( - "select a <= b from binoptesti_s;", - ), - expErr: " operator '<=' incompatible with type 'STRING'", - }, - { - sqls: sqls( - "select a >= b from binoptesti_s;", - ), - expErr: " operator '>=' incompatible with type 'STRING'", - }, - { - sqls: sqls( - "select a < b from binoptesti_s;", - ), - expErr: " operator '<' incompatible with type 'STRING'", - }, - { - sqls: sqls( - "select a > b from binoptesti_s;", - ), - expErr: " operator '>' incompatible with type 'STRING'", - }, - { - sqls: sqls( - "select a & b from binoptesti_s;", - ), - expErr: " operator '&' incompatible with type 'STRING'", - }, - { - sqls: sqls( - "select a | b from binoptesti_s;", - ), - expErr: " operator '|' incompatible with type 'STRING'", - }, - { - sqls: sqls( - "select a << b from binoptesti_s;", - ), - expErr: " operator '<<' incompatible with type 'STRING'", - }, - { - sqls: sqls( - "select a >> b from binoptesti_s;", - ), - expErr: " operator '>>' incompatible with type 'STRING'", - }, - { - sqls: sqls( - "select a + b from binoptesti_s;", - ), - expErr: " operator '+' incompatible with type 'STRING'", - }, - { - sqls: sqls( - "select a - b from binoptesti_s;", - ), - expErr: " operator '-' incompatible with type 'STRING'", - }, - { - sqls: sqls( - "select a * b from binoptesti_s;", - ), - expErr: " operator '*' incompatible with type 'STRING'", - }, - { - sqls: sqls( - "select a / b from binoptesti_s;", - ), - expErr: " operator '/' incompatible with type 'STRING'", - }, - { - sqls: sqls( - "select a % b from binoptesti_s;", - ), - expErr: " operator '%' incompatible with type 'STRING'", - }, - { - sqls: sqls( - "select a || b from binoptesti_s;", - ), - expErr: "operator '||' incompatible with type 'INT'", - }, - }, -} - -var binOpExprWithIDStringSet = tableTest{ - table: tbl( - "binoptestid_ss", - srcHdrs( - srcHdr("_id", fldTypeID), - srcHdr("a", fldTypeID), - srcHdr("b", fldTypeStringSet), - ), - srcRows( - srcRow(int64(1), int64(20), []string{"101", "102"}), - ), - ), - sqlTests: []sqlTest{ - { - sqls: sqls( - "select a != b from binoptesti_ss;", - ), - expErr: "types 'INT' and 'STRINGSET' are not equatable", - }, - { - sqls: sqls( - "select a = b from binoptesti_ss;", - ), - expErr: "types 'INT' and 'STRINGSET' are not equatable", - }, - { - sqls: sqls( - "select a <= b from binoptesti_ss;", - ), - expErr: " operator '<=' incompatible with type 'STRINGSET'", - }, - { - sqls: sqls( - "select a >= b from binoptesti_ss;", - ), - expErr: " operator '>=' incompatible with type 'STRINGSET'", - }, - { - sqls: sqls( - "select a < b from binoptesti_ss;", - ), - expErr: " operator '<' incompatible with type 'STRINGSET'", - }, - { - sqls: sqls( - "select a > b from binoptesti_ss;", - ), - expErr: " operator '>' incompatible with type 'STRINGSET'", - }, - { - sqls: sqls( - "select a & b from binoptesti_ss;", - ), - expErr: " operator '&' incompatible with type 'STRINGSET'", - }, - { - sqls: sqls( - "select a | b from binoptesti_ss;", - ), - expErr: " operator '|' incompatible with type 'STRINGSET'", - }, - { - sqls: sqls( - "select a << b from binoptesti_ss;", - ), - expErr: " operator '<<' incompatible with type 'STRINGSET'", - }, - { - sqls: sqls( - "select a >> b from binoptesti_ss;", - ), - expErr: " operator '>>' incompatible with type 'STRINGSET'", - }, - { - sqls: sqls( - "select a + b from binoptesti_ss;", - ), - expErr: " operator '+' incompatible with type 'STRINGSET'", - }, - { - sqls: sqls( - "select a - b from binoptesti_ss;", - ), - expErr: " operator '-' incompatible with type 'STRINGSET'", - }, - { - sqls: sqls( - "select a * b from binoptesti_ss;", - ), - expErr: " operator '*' incompatible with type 'STRINGSET'", - }, - { - sqls: sqls( - "select a / b from binoptesti_ss;", - ), - expErr: " operator '/' incompatible with type 'STRINGSET'", - }, - { - sqls: sqls( - "select a % b from binoptesti_ss;", - ), - expErr: " operator '%' incompatible with type 'STRINGSET'", - }, - { - sqls: sqls( - "select a || b from binoptesti_ss;", - ), - expErr: "operator '||' incompatible with type 'INT'", - }, - }, -} - -// DECIMAL bin op tests -var binOpExprWithDecInt = tableTest{ - table: tbl( - "binoptestdec_i", - srcHdrs( - srcHdr("_id", fldTypeID), - srcHdr("b", fldTypeInt, "min 0", "max 1000"), - srcHdr("d", fldTypeDecimal2), - ), - srcRows( - srcRow(int64(10), int64(20), float64(12.34)), - ), - ), - sqlTests: []sqlTest{ - { - sqls: sqls( - "select d != b from binoptestdec_i;", - ), - expHdrs: hdrs( - hdr("", fldTypeBool), - ), - expRows: rows( - row(bool(true)), - ), - compare: compareExactUnordered, - }, - { - sqls: sqls( - "select d = b from binoptestdec_i;", - ), - expHdrs: hdrs( - hdr("", fldTypeBool), - ), - expRows: rows( - row(bool(false)), - ), - compare: compareExactUnordered, - }, - { - sqls: sqls( - "select d <= b from binoptestdec_i;", - ), - expHdrs: hdrs( - hdr("", fldTypeBool), - ), - expRows: rows( - row(bool(true)), - ), - compare: compareExactUnordered, - }, - { - sqls: sqls( - "select d >= b from binoptestdec_i;", - ), - expHdrs: hdrs( - hdr("", fldTypeBool), - ), - expRows: rows( - row(bool(false)), - ), - compare: compareExactUnordered, - }, - { - sqls: sqls( - "select d < b from binoptestdec_i;", - ), - expHdrs: hdrs( - hdr("", fldTypeBool), - ), - expRows: rows( - row(bool(true)), - ), - compare: compareExactUnordered, - }, - { - sqls: sqls( - "select d > b from binoptestdec_i;", - ), - expHdrs: hdrs( - hdr("", fldTypeBool), - ), - expRows: rows( - row(bool(false)), - ), - compare: compareExactUnordered, - }, - { - sqls: sqls( - "select d & b from binoptestdec_i;", - ), - expErr: "operator '&' incompatible with type 'DECIMAL(2)'", - }, - { - sqls: sqls( - "select d | b from binoptestdec_i;", - ), - expErr: "operator '|' incompatible with type 'DECIMAL(2)'", - }, - { - sqls: sqls( - "select d << b from binoptestdec_i;", - ), - expErr: "operator '<<' incompatible with type 'DECIMAL(2)'", - }, - { - sqls: sqls( - "select d >> b from binoptestdec_i;", - ), - expErr: "operator '>>' incompatible with type 'DECIMAL(2)'", - }, - { - sqls: sqls( - "select d + b from binoptestdec_i;", - ), - expHdrs: hdrs( - hdr("", fldTypeDecimal2), - ), - expRows: rows( - row(pql.NewDecimal(3234, 2)), - ), - compare: compareExactUnordered, - }, - { - sqls: sqls( - "select d - b from binoptestdec_i;", - ), - expHdrs: hdrs( - hdr("", fldTypeDecimal2), - ), - expRows: rows( - row(pql.NewDecimal(-766, 2)), - ), - compare: compareExactUnordered, - }, - { - sqls: sqls( - "select d * b from binoptestdec_i;", - ), - expHdrs: hdrs( - hdr("", fldTypeDecimal2), - ), - expRows: rows( - row(pql.NewDecimal(24680, 2)), - ), - compare: compareExactUnordered, - }, - { - sqls: sqls( - "select d / b from binoptestdec_i;", - ), - expHdrs: hdrs( - hdr("", fldTypeDecimal2), - ), - expRows: rows( - row(pql.NewDecimal(61, 2)), - ), - compare: compareExactUnordered, - }, - { - sqls: sqls( - "select d % b from binoptestdec_i;", - ), - expErr: "operator '%' incompatible with type 'DECIMAL(2)'", - }, - { - sqls: sqls( - "select d || b from binoptestdec_i;", - ), - expErr: "operator '||' incompatible with type 'DECIMAL(2)'", - }, - }, -} - -var binOpExprWithDecBool = tableTest{ - table: tbl( - "binoptestdec_b", - srcHdrs( - srcHdr("_id", fldTypeID), - srcHdr("b", fldTypeBool), - srcHdr("d", fldTypeDecimal2), - ), - srcRows( - srcRow(int64(10), bool(true), float64(12.34)), - ), - ), - sqlTests: []sqlTest{ - { - sqls: sqls( - "select d != b from binoptestdec_b;", - ), - expErr: "types 'DECIMAL(2)' and 'BOOL' are not equatable", - }, - { - sqls: sqls( - "select d = b from binoptestdec_b;", - ), - expErr: "types 'DECIMAL(2)' and 'BOOL' are not equatable", - }, - { - sqls: sqls( - "select d <= b from binoptestdec_b;", - ), - expErr: "operator '<=' incompatible with type 'BOOL'", - }, - { - sqls: sqls( - "select d >= b from binoptestdec_b;", - ), - expErr: "operator '>=' incompatible with type 'BOOL'", - }, - { - sqls: sqls( - "select d < b from binoptestdec_b;", - ), - expErr: "operator '<' incompatible with type 'BOOL'", - }, - { - sqls: sqls( - "select d > b from binoptestdec_b;", - ), - expErr: "operator '>' incompatible with type 'BOOL'", - }, - { - sqls: sqls( - "select d & b from binoptestdec_b;", - ), - expErr: "operator '&' incompatible with type 'DECIMAL(2)'", - }, - { - sqls: sqls( - "select d | b from binoptestdec_b;", - ), - expErr: "operator '|' incompatible with type 'DECIMAL(2)'", - }, - { - sqls: sqls( - "select d << b from binoptestdec_b;", - ), - expErr: "operator '<<' incompatible with type 'DECIMAL(2)'", - }, - { - sqls: sqls( - "select d >> b from binoptestdec_b;", - ), - expErr: "operator '>>' incompatible with type 'DECIMAL(2)'", - }, - { - sqls: sqls( - "select d + b from binoptestdec_b;", - ), - expErr: "operator '+' incompatible with type 'BOOL'", - }, - { - sqls: sqls( - "select d - b from binoptestdec_b;", - ), - expErr: "operator '-' incompatible with type 'BOOL'", - }, - { - sqls: sqls( - "select d * b from binoptestdec_b;", - ), - expErr: "operator '*' incompatible with type 'BOOL'", - }, - { - sqls: sqls( - "select d / b from binoptestdec_b;", - ), - expErr: "operator '/' incompatible with type 'BOOL'", - }, - { - sqls: sqls( - "select d % b from binoptestdec_b;", - ), - expErr: "operator '%' incompatible with type 'DECIMAL(2)'", - }, - { - sqls: sqls( - "select d || b from binoptestdec_b;", - ), - expErr: "operator '||' incompatible with type 'DECIMAL(2)'", - }, - }, -} - -var binOpExprWithDecID = tableTest{ - table: tbl( - "binoptestdec_id", - srcHdrs( - srcHdr("_id", fldTypeID), - srcHdr("b", fldTypeID), - srcHdr("d", fldTypeDecimal2), - ), - srcRows( - srcRow(int64(10), int64(20), float64(12.34)), - ), - ), - sqlTests: []sqlTest{ - { - sqls: sqls( - "select d != b from binoptestdec_id;", - ), - expHdrs: hdrs( - hdr("", fldTypeBool), - ), - expRows: rows( - row(bool(true)), - ), - compare: compareExactUnordered, - }, - { - sqls: sqls( - "select d = b from binoptestdec_id;", - ), - expHdrs: hdrs( - hdr("", fldTypeBool), - ), - expRows: rows( - row(bool(false)), - ), - compare: compareExactUnordered, - }, - { - sqls: sqls( - "select d <= b from binoptestdec_id;", - ), - expHdrs: hdrs( - hdr("", fldTypeBool), - ), - expRows: rows( - row(bool(true)), - ), - compare: compareExactUnordered, - }, - { - sqls: sqls( - "select d >= b from binoptestdec_id;", - ), - expHdrs: hdrs( - hdr("", fldTypeBool), - ), - expRows: rows( - row(bool(false)), - ), - compare: compareExactUnordered, - }, - { - sqls: sqls( - "select d < b from binoptestdec_id;", - ), - expHdrs: hdrs( - hdr("", fldTypeBool), - ), - expRows: rows( - row(bool(true)), - ), - compare: compareExactUnordered, - }, - { - sqls: sqls( - "select d > b from binoptestdec_id;", - ), - expHdrs: hdrs( - hdr("", fldTypeBool), - ), - expRows: rows( - row(bool(false)), - ), - compare: compareExactUnordered, - }, - { - sqls: sqls( - "select d & b from binoptestdec_id;", - ), - expErr: "operator '&' incompatible with type 'DECIMAL(2)'", - }, - { - sqls: sqls( - "select d | b from binoptestdec_id;", - ), - expErr: "operator '|' incompatible with type 'DECIMAL(2)'", - }, - { - sqls: sqls( - "select d << b from binoptestdec_id;", - ), - expErr: "operator '<<' incompatible with type 'DECIMAL(2)'", - }, - { - sqls: sqls( - "select d >> b from binoptestdec_id;", - ), - expErr: "operator '>>' incompatible with type 'DECIMAL(2)'", - }, - { - sqls: sqls( - "select d + b from binoptestdec_id;", - ), - expHdrs: hdrs( - hdr("", fldTypeDecimal2), - ), - expRows: rows( - row(pql.NewDecimal(3234, 2)), - ), - compare: compareExactUnordered, - }, - { - sqls: sqls( - "select d - b from binoptestdec_id;", - ), - expHdrs: hdrs( - hdr("", fldTypeDecimal2), - ), - expRows: rows( - row(pql.NewDecimal(-766, 2)), - ), - compare: compareExactUnordered, - }, - { - sqls: sqls( - "select d * b from binoptestdec_id;", - ), - expHdrs: hdrs( - hdr("", fldTypeDecimal2), - ), - expRows: rows( - row(pql.NewDecimal(24680, 2)), - ), - compare: compareExactUnordered, - }, - { - sqls: sqls( - "select d / b from binoptestdec_id;", - ), - expHdrs: hdrs( - hdr("", fldTypeDecimal2), - ), - expRows: rows( - row(pql.NewDecimal(61, 2)), - ), - compare: compareExactUnordered, - }, - { - sqls: sqls( - "select d % b from binoptestdec_id;", - ), - expErr: "operator '%' incompatible with type 'DECIMAL(2)'", - }, - { - sqls: sqls( - "select d || b from binoptestdec_id;", - ), - expErr: "operator '||' incompatible with type 'DECIMAL(2)'", - }, - }, -} - -var binOpExprWithDecDecimal = tableTest{ - table: tbl( - "binoptestdec_d", - srcHdrs( - srcHdr("_id", fldTypeID), - srcHdr("a", fldTypeDecimal2), - srcHdr("d", fldTypeDecimal2), - ), - srcRows( - srcRow(int64(1), float64(20.00), float64(12.34)), - ), - ), - sqlTests: []sqlTest{ - { - sqls: sqls( - "select a != d from binoptestdec_d;", - ), - expHdrs: hdrs( - hdr("", fldTypeBool), - ), - expRows: rows( - row(bool(true)), - ), - compare: compareExactUnordered, - }, - { - sqls: sqls( - "select a = d from binoptestdec_d;", - ), - expHdrs: hdrs( - hdr("", fldTypeBool), - ), - expRows: rows( - row(bool(false)), - ), - compare: compareExactUnordered, - }, - { - sqls: sqls( - "select a <= d from binoptestdec_d;", - ), - expHdrs: hdrs( - hdr("", fldTypeBool), - ), - expRows: rows( - row(bool(false)), - ), - compare: compareExactUnordered, - }, - { - sqls: sqls( - "select a >= d from binoptestdec_d;", - ), - expHdrs: hdrs( - hdr("", fldTypeBool), - ), - expRows: rows( - row(bool(true)), - ), - compare: compareExactUnordered, - }, - { - sqls: sqls( - "select a < d from binoptestdec_d;", - ), - expHdrs: hdrs( - hdr("", fldTypeBool), - ), - expRows: rows( - row(bool(false)), - ), - compare: compareExactUnordered, - }, - { - sqls: sqls( - "select a > d from binoptestdec_d;", - ), - expHdrs: hdrs( - hdr("", fldTypeBool), - ), - expRows: rows( - row(bool(true)), - ), - compare: compareExactUnordered, - }, - { - sqls: sqls( - "select a & d from binoptestdec_d;", - ), - expErr: "operator '&' incompatible with type 'DECIMAL(2)'", - }, - { - sqls: sqls( - "select a | d from binoptestdec_d;", - ), - expErr: "operator '|' incompatible with type 'DECIMAL(2)'", - }, - { - sqls: sqls( - "select a << d from binoptestdec_d;", - ), - expErr: "operator '<<' incompatible with type 'DECIMAL(2)'", - }, - { - sqls: sqls( - "select a >> d from binoptestdec_d;", - ), - expErr: "operator '>>' incompatible with type 'DECIMAL(2)'", - }, - { - sqls: sqls( - "select a + d from binoptestdec_d;", - ), - expHdrs: hdrs( - hdr("", fldTypeDecimal2), - ), - expRows: rows( - row(pql.NewDecimal(3234, 2)), - ), - compare: compareExactUnordered, - }, - { - sqls: sqls( - "select a - d from binoptestdec_d;", - ), - expHdrs: hdrs( - hdr("", fldTypeDecimal2), - ), - expRows: rows( - row(pql.NewDecimal(766, 2)), - ), - compare: compareExactUnordered, - }, - { - sqls: sqls( - "select a * d from binoptestdec_d;", - ), - expHdrs: hdrs( - hdr("", fldTypeDecimal2), - ), - expRows: rows( - row(pql.NewDecimal(24680, 2)), - ), - compare: compareExactUnordered, - }, - { - sqls: sqls( - "select a / d from binoptestdec_d;", - ), - expHdrs: hdrs( - hdr("", fldTypeDecimal2), - ), - expRows: rows( - row(pql.NewDecimal(162, 2)), - ), - compare: compareExactUnordered, - }, - { - sqls: sqls( - "select a % d from binoptestdec_d;", - ), - expErr: "operator '%' incompatible with type 'DECIMAL(2)'", - }, - { - sqls: sqls( - "select a || d from binoptestdec_d;", - ), - expErr: "operator '||' incompatible with type 'DECIMAL(2)'", - }, - }, -} - -var binOpExprWithDecTimestamp = tableTest{ - table: tbl( - "binoptestdec_ts", - srcHdrs( - srcHdr("_id", fldTypeID), - srcHdr("a", fldTypeDecimal2), - srcHdr("ts", fldTypeTimestamp), - ), - srcRows( - srcRow(int64(1), float64(20.00), time.Time(knownTimestamp())), - ), - ), - sqlTests: []sqlTest{ - { - sqls: sqls( - "select a != ts from binoptestdec_ts;", - ), - expErr: "types 'DECIMAL(2)' and 'TIMESTAMP' are not equatable", - }, - { - sqls: sqls( - "select a = ts from binoptestdec_ts;", - ), - expErr: "types 'DECIMAL(2)' and 'TIMESTAMP' are not equatable", - }, - { - sqls: sqls( - "select a <= ts from binoptestdec_ts;", - ), - expErr: "types 'DECIMAL(2)' and 'TIMESTAMP' are not equatable", - }, - { - sqls: sqls( - "select a >= ts from binoptestdec_ts;", - ), - expErr: "types 'DECIMAL(2)' and 'TIMESTAMP' are not equatable", - }, - { - sqls: sqls( - "select a < ts from binoptestdec_ts;", - ), - expErr: "types 'DECIMAL(2)' and 'TIMESTAMP' are not equatable", - }, - { - sqls: sqls( - "select a > ts from binoptestdec_ts;", - ), - expErr: "types 'DECIMAL(2)' and 'TIMESTAMP' are not equatable", - }, - { - sqls: sqls( - "select a & ts from binoptestdec_ts;", - ), - expErr: "operator '&' incompatible with type 'DECIMAL(2)'", - }, - { - sqls: sqls( - "select a | ts from binoptestdec_ts;", - ), - expErr: "operator '|' incompatible with type 'DECIMAL(2)'", - }, - { - sqls: sqls( - "select a << ts from binoptestdec_ts;", - ), - expErr: "operator '<<' incompatible with type 'DECIMAL(2)'", - }, - { - sqls: sqls( - "select a >> ts from binoptestdec_ts;", - ), - expErr: "operator '>>' incompatible with type 'DECIMAL(2)'", - }, - { - sqls: sqls( - "select a + ts from binoptestdec_ts;", - ), - expErr: "operator '+' incompatible with type 'TIMESTAMP'", - }, - { - sqls: sqls( - "select a - ts from binoptestdec_ts;", - ), - expErr: "operator '-' incompatible with type 'TIMESTAMP'", - }, - { - sqls: sqls( - "select a * ts from binoptestdec_ts;", - ), - expErr: "operator '*' incompatible with type 'TIMESTAMP'", - }, - { - sqls: sqls( - "select a / ts from binoptestdec_ts;", - ), - expErr: "operator '/' incompatible with type 'TIMESTAMP'", - }, - { - sqls: sqls( - "select a % ts from binoptestdec_ts;", - ), - expErr: "operator '%' incompatible with type 'DECIMAL(2)'", - }, - { - sqls: sqls( - "select a || ts from binoptestdec_ts;", - ), - expErr: "operator '||' incompatible with type 'DECIMAL(2)'", - }, - }, -} - -var binOpExprWithDecIDSet = tableTest{ - table: tbl( - "binoptestdec_ids", - srcHdrs( - srcHdr("_id", fldTypeID), - srcHdr("a", fldTypeDecimal2), - srcHdr("b", fldTypeIDSet), - ), - srcRows( - srcRow(int64(1), float64(20.00), []int64{101, 102}), - ), - ), - sqlTests: []sqlTest{ - { - sqls: sqls( - "select a != b from binoptestdec_ids;", - ), - expErr: "types 'DECIMAL(2)' and 'IDSET' are not equatable", - }, - { - sqls: sqls( - "select a = b from binoptestdec_ids;", - ), - expErr: "types 'DECIMAL(2)' and 'IDSET' are not equatable", - }, - { - sqls: sqls( - "select a <= b from binoptestdec_ids;", - ), - expErr: " operator '<=' incompatible with type 'IDSET'", - }, - { - sqls: sqls( - "select a >= b from binoptestdec_ids;", - ), - expErr: " operator '>=' incompatible with type 'IDSET'", - }, - { - sqls: sqls( - "select a < b from binoptestdec_ids;", - ), - expErr: " operator '<' incompatible with type 'IDSET'", - }, - { - sqls: sqls( - "select a > b from binoptestdec_ids;", - ), - expErr: " operator '>' incompatible with type 'IDSET'", - }, - { - sqls: sqls( - "select a & b from binoptestdec_ids;", - ), - expErr: " operator '&' incompatible with type 'DECIMAL(2)'", - }, - { - sqls: sqls( - "select a | b from binoptestdec_ids;", - ), - expErr: " operator '|' incompatible with type 'DECIMAL(2)'", - }, - { - sqls: sqls( - "select a << b from binoptestdec_ids;", - ), - expErr: " operator '<<' incompatible with type 'DECIMAL(2)'", - }, - { - sqls: sqls( - "select a >> b from binoptestdec_ids;", - ), - expErr: " operator '>>' incompatible with type 'DECIMAL(2)'", - }, - { - sqls: sqls( - "select a + b from binoptestdec_ids;", - ), - expErr: " operator '+' incompatible with type 'IDSET'", - }, - { - sqls: sqls( - "select a - b from binoptestdec_ids;", - ), - expErr: " operator '-' incompatible with type 'IDSET'", - }, - { - sqls: sqls( - "select a * b from binoptestdec_ids;", - ), - expErr: " operator '*' incompatible with type 'IDSET'", - }, - { - sqls: sqls( - "select a / b from binoptestdec_ids;", - ), - expErr: " operator '/' incompatible with type 'IDSET'", - }, - { - sqls: sqls( - "select a % b from binoptestdec_ids;", - ), - expErr: " operator '%' incompatible with type 'DECIMAL(2)'", - }, - { - sqls: sqls( - "select a || b from binoptestdec_ids;", - ), - expErr: "operator '||' incompatible with type 'DECIMAL(2)'", - }, - }, -} - -var binOpExprWithDecString = tableTest{ - table: tbl( - "binoptestdec_s", - srcHdrs( - srcHdr("_id", fldTypeID), - srcHdr("a", fldTypeDecimal2), - srcHdr("b", fldTypeString), - ), - srcRows( - srcRow(int64(1), float64(20.00), string("101")), - ), - ), - sqlTests: []sqlTest{ - { - sqls: sqls( - "select a != b from binoptestdec_s;", - ), - expErr: "types 'DECIMAL(2)' and 'STRING' are not equatable", - }, - { - sqls: sqls( - "select a = b from binoptestdec_s;", - ), - expErr: "types 'DECIMAL(2)' and 'STRING' are not equatable", - }, - { - sqls: sqls( - "select a <= b from binoptestdec_s;", - ), - expErr: " operator '<=' incompatible with type 'STRING'", - }, - { - sqls: sqls( - "select a >= b from binoptestdec_s;", - ), - expErr: " operator '>=' incompatible with type 'STRING'", - }, - { - sqls: sqls( - "select a < b from binoptestdec_s;", - ), - expErr: " operator '<' incompatible with type 'STRING'", - }, - { - sqls: sqls( - "select a > b from binoptestdec_s;", - ), - expErr: " operator '>' incompatible with type 'STRING'", - }, - { - sqls: sqls( - "select a & b from binoptestdec_s;", - ), - expErr: " operator '&' incompatible with type 'DECIMAL(2)'", - }, - { - sqls: sqls( - "select a | b from binoptestdec_s;", - ), - expErr: " operator '|' incompatible with type 'DECIMAL(2)'", - }, - { - sqls: sqls( - "select a << b from binoptestdec_s;", - ), - expErr: " operator '<<' incompatible with type 'DECIMAL(2)'", - }, - { - sqls: sqls( - "select a >> b from binoptestdec_s;", - ), - expErr: " operator '>>' incompatible with type 'DECIMAL(2)'", - }, - { - sqls: sqls( - "select a + b from binoptestdec_s;", - ), - expErr: " operator '+' incompatible with type 'STRING'", - }, - { - sqls: sqls( - "select a - b from binoptestdec_s;", - ), - expErr: " operator '-' incompatible with type 'STRING'", - }, - { - sqls: sqls( - "select a * b from binoptestdec_s;", - ), - expErr: " operator '*' incompatible with type 'STRING'", - }, - { - sqls: sqls( - "select a / b from binoptestdec_s;", - ), - expErr: " operator '/' incompatible with type 'STRING'", - }, - { - sqls: sqls( - "select a % b from binoptestdec_s;", - ), - expErr: " operator '%' incompatible with type 'DECIMAL(2)'", - }, - { - sqls: sqls( - "select a || b from binoptestdec_s;", - ), - expErr: "operator '||' incompatible with type 'DECIMAL(2)'", - }, - }, -} - -var binOpExprWithDecStringSet = tableTest{ - table: tbl( - "binoptestdec_ss", - srcHdrs( - srcHdr("_id", fldTypeID), - srcHdr("a", fldTypeDecimal2), - srcHdr("b", fldTypeStringSet), - ), - srcRows( - srcRow(int64(1), float64(20.00), []string{"101", "102"}), - ), - ), - sqlTests: []sqlTest{ - { - sqls: sqls( - "select a != b from binoptestdec_ss;", - ), - expErr: "types 'DECIMAL(2)' and 'STRINGSET' are not equatable", - }, - { - sqls: sqls( - "select a = b from binoptestdec_ss;", - ), - expErr: "types 'DECIMAL(2)' and 'STRINGSET' are not equatable", - }, - { - sqls: sqls( - "select a <= b from binoptestdec_ss;", - ), - expErr: " operator '<=' incompatible with type 'STRINGSET'", - }, - { - sqls: sqls( - "select a >= b from binoptestdec_ss;", - ), - expErr: " operator '>=' incompatible with type 'STRINGSET'", - }, - { - sqls: sqls( - "select a < b from binoptestdec_ss;", - ), - expErr: " operator '<' incompatible with type 'STRINGSET'", - }, - { - sqls: sqls( - "select a > b from binoptestdec_ss;", - ), - expErr: " operator '>' incompatible with type 'STRINGSET'", - }, - { - sqls: sqls( - "select a & b from binoptestdec_ss;", - ), - expErr: " operator '&' incompatible with type 'DECIMAL(2)'", - }, - { - sqls: sqls( - "select a | b from binoptestdec_ss;", - ), - expErr: " operator '|' incompatible with type 'DECIMAL(2)'", - }, - { - sqls: sqls( - "select a << b from binoptestdec_ss;", - ), - expErr: " operator '<<' incompatible with type 'DECIMAL(2)'", - }, - { - sqls: sqls( - "select a >> b from binoptestdec_ss;", - ), - expErr: " operator '>>' incompatible with type 'DECIMAL(2)'", - }, - { - sqls: sqls( - "select a + b from binoptestdec_ss;", - ), - expErr: " operator '+' incompatible with type 'STRINGSET'", - }, - { - sqls: sqls( - "select a - b from binoptestdec_ss;", - ), - expErr: " operator '-' incompatible with type 'STRINGSET'", - }, - { - sqls: sqls( - "select a * b from binoptestdec_ss;", - ), - expErr: " operator '*' incompatible with type 'STRINGSET'", - }, - { - sqls: sqls( - "select a / b from binoptestdec_ss;", - ), - expErr: " operator '/' incompatible with type 'STRINGSET'", - }, - { - sqls: sqls( - "select a % b from binoptestdec_ss;", - ), - expErr: " operator '%' incompatible with type 'DECIMAL(2)'", - }, - { - sqls: sqls( - "select a || b from binoptestdec_ss;", - ), - expErr: "operator '||' incompatible with type 'DECIMAL(2)'", - }, - }, -} - -// TIMESTAMP bin op tests -var binOpExprWithTSInt = tableTest{ - table: tbl( - "binoptestts_i", - srcHdrs( - srcHdr("_id", fldTypeID), - srcHdr("b", fldTypeInt, "min 0", "max 1000"), - srcHdr("d", fldTypeTimestamp), - ), - srcRows( - srcRow(int64(10), int64(20), time.Time(knownTimestamp())), - ), - ), - sqlTests: []sqlTest{ - { - sqls: sqls( - "select d != b from binoptestts_i;", - ), - expErr: "types 'TIMESTAMP' and 'INT' are not equatable", - }, - { - sqls: sqls( - "select d = b from binoptestts_i;", - ), - expErr: "types 'TIMESTAMP' and 'INT' are not equatable", - }, - { - sqls: sqls( - "select d <= b from binoptestts_i;", - ), - expErr: "types 'TIMESTAMP' and 'INT' are not equatable", - }, - { - sqls: sqls( - "select d >= b from binoptestts_i;", - ), - expErr: "types 'TIMESTAMP' and 'INT' are not equatable", - }, - { - sqls: sqls( - "select d < b from binoptestts_i;", - ), - expErr: "types 'TIMESTAMP' and 'INT' are not equatable", - }, - { - sqls: sqls( - "select d > b from binoptestts_i;", - ), - expErr: "types 'TIMESTAMP' and 'INT' are not equatable", - }, - { - sqls: sqls( - "select d & b from binoptestts_i;", - ), - expErr: "operator '&' incompatible with type 'TIMESTAMP'", - }, - { - sqls: sqls( - "select d | b from binoptestts_i;", - ), - expErr: "operator '|' incompatible with type 'TIMESTAMP'", - }, - { - sqls: sqls( - "select d << b from binoptestts_i;", - ), - expErr: "operator '<<' incompatible with type 'TIMESTAMP'", - }, - { - sqls: sqls( - "select d >> b from binoptestts_i;", - ), - expErr: "operator '>>' incompatible with type 'TIMESTAMP'", - }, - { - sqls: sqls( - "select d + b from binoptestts_i;", - ), - expErr: "operator '+' incompatible with type 'TIMESTAMP'", - }, - { - sqls: sqls( - "select d - b from binoptestts_i;", - ), - expErr: "operator '-' incompatible with type 'TIMESTAMP'", - }, - { - sqls: sqls( - "select d * b from binoptestts_i;", - ), - expErr: "operator '*' incompatible with type 'TIMESTAMP'", - }, - { - sqls: sqls( - "select d / b from binoptestts_i;", - ), - expErr: "operator '/' incompatible with type 'TIMESTAMP'", - }, - { - sqls: sqls( - "select d % b from binoptestts_i;", - ), - expErr: "operator '%' incompatible with type 'TIMESTAMP'", - }, - { - sqls: sqls( - "select d || b from binoptestts_i;", - ), - expErr: "operator '||' incompatible with type 'TIMESTAMP'", - }, - }, -} - -var binOpExprWithTSBool = tableTest{ - table: tbl( - "binoptestts_b", - srcHdrs( - srcHdr("_id", fldTypeID), - srcHdr("b", fldTypeBool), - srcHdr("d", fldTypeTimestamp), - ), - srcRows( - srcRow(int64(10), bool(true), time.Time(knownTimestamp())), - ), - ), - sqlTests: []sqlTest{ - { - sqls: sqls( - "select d != b from binoptestts_b;", - ), - expErr: "types 'TIMESTAMP' and 'BOOL' are not equatable", - }, - { - sqls: sqls( - "select d = b from binoptestts_b;", - ), - expErr: "types 'TIMESTAMP' and 'BOOL' are not equatable", - }, - { - sqls: sqls( - "select d <= b from binoptestts_b;", - ), - expErr: "operator '<=' incompatible with type 'BOOL'", - }, - { - sqls: sqls( - "select d >= b from binoptestts_b;", - ), - expErr: "operator '>=' incompatible with type 'BOOL'", - }, - { - sqls: sqls( - "select d < b from binoptestts_b;", - ), - expErr: "operator '<' incompatible with type 'BOOL'", - }, - { - sqls: sqls( - "select d > b from binoptestts_b;", - ), - expErr: "operator '>' incompatible with type 'BOOL'", - }, - { - sqls: sqls( - "select d & b from binoptestts_b;", - ), - expErr: "operator '&' incompatible with type 'TIMESTAMP'", - }, - { - sqls: sqls( - "select d | b from binoptestts_b;", - ), - expErr: "operator '|' incompatible with type 'TIMESTAMP'", - }, - { - sqls: sqls( - "select d << b from binoptestts_b;", - ), - expErr: "operator '<<' incompatible with type 'TIMESTAMP'", - }, - { - sqls: sqls( - "select d >> b from binoptestts_b;", - ), - expErr: "operator '>>' incompatible with type 'TIMESTAMP'", - }, - { - sqls: sqls( - "select d + b from binoptestts_b;", - ), - expErr: "operator '+' incompatible with type 'TIMESTAMP'", - }, - { - sqls: sqls( - "select d - b from binoptestts_b;", - ), - expErr: "operator '-' incompatible with type 'TIMESTAMP'", - }, - { - sqls: sqls( - "select d * b from binoptestts_b;", - ), - expErr: "operator '*' incompatible with type 'TIMESTAMP'", - }, - { - sqls: sqls( - "select d / b from binoptestts_b;", - ), - expErr: "operator '/' incompatible with type 'TIMESTAMP'", - }, - { - sqls: sqls( - "select d % b from binoptestts_b;", - ), - expErr: "operator '%' incompatible with type 'TIMESTAMP'", - }, - { - sqls: sqls( - "select d || b from binoptestts_b;", - ), - expErr: "operator '||' incompatible with type 'TIMESTAMP'", - }, - }, -} - -var binOpExprWithTSID = tableTest{ - table: tbl( - "binoptestts_id", - srcHdrs( - srcHdr("_id", fldTypeID), - srcHdr("b", fldTypeID), - srcHdr("d", fldTypeTimestamp), - ), - srcRows( - srcRow(int64(10), int64(20), time.Time(knownTimestamp())), - ), - ), - sqlTests: []sqlTest{ - { - sqls: sqls( - "select d != b from binoptestts_id;", - ), - expErr: "types 'TIMESTAMP' and 'ID' are not equatable", - }, - { - sqls: sqls( - "select d = b from binoptestts_id;", - ), - expErr: "types 'TIMESTAMP' and 'ID' are not equatable", - }, - { - sqls: sqls( - "select d <= b from binoptestts_id;", - ), - expErr: "types 'TIMESTAMP' and 'ID' are not equatable", - }, - { - sqls: sqls( - "select d >= b from binoptestts_id;", - ), - expErr: "types 'TIMESTAMP' and 'ID' are not equatable", - }, - { - sqls: sqls( - "select d < b from binoptestts_id;", - ), - expErr: "types 'TIMESTAMP' and 'ID' are not equatable", - }, - { - sqls: sqls( - "select d > b from binoptestts_id;", - ), - expErr: "types 'TIMESTAMP' and 'ID' are not equatable", - }, - { - sqls: sqls( - "select d & b from binoptestts_id;", - ), - expErr: "operator '&' incompatible with type 'TIMESTAMP'", - }, - { - sqls: sqls( - "select d | b from binoptestts_id;", - ), - expErr: "operator '|' incompatible with type 'TIMESTAMP'", - }, - { - sqls: sqls( - "select d << b from binoptestts_id;", - ), - expErr: "operator '<<' incompatible with type 'TIMESTAMP'", - }, - { - sqls: sqls( - "select d >> b from binoptestts_id;", - ), - expErr: "operator '>>' incompatible with type 'TIMESTAMP'", - }, - { - sqls: sqls( - "select d + b from binoptestts_id;", - ), - expErr: "operator '+' incompatible with type 'TIMESTAMP'", - }, - { - sqls: sqls( - "select d - b from binoptestts_id;", - ), - expErr: "operator '-' incompatible with type 'TIMESTAMP'", - }, - { - sqls: sqls( - "select d * b from binoptestts_id;", - ), - expErr: "operator '*' incompatible with type 'TIMESTAMP'", - }, - { - sqls: sqls( - "select d / b from binoptestts_id;", - ), - expErr: "operator '/' incompatible with type 'TIMESTAMP'", - }, - { - sqls: sqls( - "select d % b from binoptestts_id;", - ), - expErr: "operator '%' incompatible with type 'TIMESTAMP'", - }, - { - sqls: sqls( - "select d || b from binoptestts_id;", - ), - expErr: "operator '||' incompatible with type 'TIMESTAMP'", - }, - }, -} - -var binOpExprWithTSDecimal = tableTest{ - table: tbl( - "binoptestts_d", - srcHdrs( - srcHdr("_id", fldTypeID), - srcHdr("a", fldTypeTimestamp), - srcHdr("d", fldTypeDecimal2), - ), - srcRows( - srcRow(int64(1), time.Time(knownTimestamp()), float64(12.34)), - ), - ), - sqlTests: []sqlTest{ - { - sqls: sqls( - "select a != d from binoptestts_d;", - ), - expErr: "types 'TIMESTAMP' and 'DECIMAL(2)' are not equatable", - }, - { - sqls: sqls( - "select a = d from binoptestts_d;", - ), - expErr: "types 'TIMESTAMP' and 'DECIMAL(2)' are not equatable", - }, - { - sqls: sqls( - "select a <= d from binoptestts_d;", - ), - expErr: "types 'TIMESTAMP' and 'DECIMAL(2)' are not equatable", - }, - { - sqls: sqls( - "select a >= d from binoptestts_d;", - ), - expErr: "types 'TIMESTAMP' and 'DECIMAL(2)' are not equatable", - }, - { - sqls: sqls( - "select a < d from binoptestts_d;", - ), - expErr: "types 'TIMESTAMP' and 'DECIMAL(2)' are not equatable", - }, - { - sqls: sqls( - "select a > d from binoptestts_d;", - ), - expErr: "types 'TIMESTAMP' and 'DECIMAL(2)' are not equatable", - }, - { - sqls: sqls( - "select a & d from binoptestts_d;", - ), - expErr: "operator '&' incompatible with type 'TIMESTAMP'", - }, - { - sqls: sqls( - "select a | d from binoptestts_d;", - ), - expErr: "operator '|' incompatible with type 'TIMESTAMP'", - }, - { - sqls: sqls( - "select a << d from binoptestts_d;", - ), - expErr: "operator '<<' incompatible with type 'TIMESTAMP'", - }, - { - sqls: sqls( - "select a >> d from binoptestts_d;", - ), - expErr: "operator '>>' incompatible with type 'TIMESTAMP'", - }, - { - sqls: sqls( - "select a + d from binoptestts_d;", - ), - expErr: "operator '+' incompatible with type 'TIMESTAMP'", - }, - { - sqls: sqls( - "select a - d from binoptestts_d;", - ), - expErr: "operator '-' incompatible with type 'TIMESTAMP'", - }, - { - sqls: sqls( - "select a * d from binoptestts_d;", - ), - expErr: "operator '*' incompatible with type 'TIMESTAMP'", - }, - { - sqls: sqls( - "select a / d from binoptestts_d;", - ), - expErr: "operator '/' incompatible with type 'TIMESTAMP'", - }, - { - sqls: sqls( - "select a % d from binoptestts_d;", - ), - expErr: "operator '%' incompatible with type 'TIMESTAMP'", - }, - { - sqls: sqls( - "select a || d from binoptestts_d;", - ), - expErr: "operator '||' incompatible with type 'TIMESTAMP'", - }, - }, -} - -var binOpExprWithTSTimestamp = tableTest{ - table: tbl( - "binoptestts_ts", - srcHdrs( - srcHdr("_id", fldTypeID), - srcHdr("a", fldTypeTimestamp), - srcHdr("ts", fldTypeTimestamp), - ), - srcRows( - srcRow(int64(1), time.Time(knownTimestamp()), time.Time(knownTimestamp())), - ), - ), - sqlTests: []sqlTest{ - { - sqls: sqls( - "select a != ts from binoptestts_ts;", - ), - expHdrs: hdrs( - hdr("", fldTypeBool), - ), - expRows: rows( - row(bool(false)), - ), - compare: compareExactUnordered}, - { - sqls: sqls( - "select a = ts from binoptestts_ts;", - ), - expHdrs: hdrs( - hdr("", fldTypeBool), - ), - expRows: rows( - row(bool(true)), - ), - compare: compareExactUnordered}, - { - sqls: sqls( - "select a <= ts from binoptestts_ts;", - ), - expHdrs: hdrs( - hdr("", fldTypeBool), - ), - expRows: rows( - row(bool(true)), - ), - compare: compareExactUnordered, - }, - { - sqls: sqls( - "select a >= ts from binoptestts_ts;", - ), - expHdrs: hdrs( - hdr("", fldTypeBool), - ), - expRows: rows( - row(bool(true)), - ), - compare: compareExactUnordered}, - { - sqls: sqls( - "select a < ts from binoptestts_ts;", - ), - expHdrs: hdrs( - hdr("", fldTypeBool), - ), - expRows: rows( - row(bool(false)), - ), - compare: compareExactUnordered}, - { - sqls: sqls( - "select a > ts from binoptestts_ts;", - ), - expHdrs: hdrs( - hdr("", fldTypeBool), - ), - expRows: rows( - row(bool(false)), - ), - compare: compareExactUnordered}, - { - sqls: sqls( - "select a & ts from binoptestts_ts;", - ), - expErr: "operator '&' incompatible with type 'TIMESTAMP'", - }, - { - sqls: sqls( - "select a | ts from binoptestts_ts;", - ), - expErr: "operator '|' incompatible with type 'TIMESTAMP'", - }, - { - sqls: sqls( - "select a << ts from binoptestts_ts;", - ), - expErr: "operator '<<' incompatible with type 'TIMESTAMP'", - }, - { - sqls: sqls( - "select a >> ts from binoptestts_ts;", - ), - expErr: "operator '>>' incompatible with type 'TIMESTAMP'", - }, - { - sqls: sqls( - "select a + ts from binoptestts_ts;", - ), - expErr: "operator '+' incompatible with type 'TIMESTAMP'", - }, - { - sqls: sqls( - "select a - ts from binoptestts_ts;", - ), - expErr: "operator '-' incompatible with type 'TIMESTAMP'", - }, - { - sqls: sqls( - "select a * ts from binoptestts_ts;", - ), - expErr: "operator '*' incompatible with type 'TIMESTAMP'", - }, - { - sqls: sqls( - "select a / ts from binoptestts_ts;", - ), - expErr: "operator '/' incompatible with type 'TIMESTAMP'", - }, - { - sqls: sqls( - "select a % ts from binoptestts_ts;", - ), - expErr: "operator '%' incompatible with type 'TIMESTAMP'", - }, - { - sqls: sqls( - "select a || ts from binoptestts_ts;", - ), - expErr: "operator '||' incompatible with type 'TIMESTAMP'", - }, - }, -} - -var binOpExprWithTSIDSet = tableTest{ - table: tbl( - "binoptestts_ids", - srcHdrs( - srcHdr("_id", fldTypeID), - srcHdr("a", fldTypeTimestamp), - srcHdr("b", fldTypeIDSet), - ), - srcRows( - srcRow(int64(1), time.Time(knownTimestamp()), []int64{101, 102}), - ), - ), - sqlTests: []sqlTest{ - { - sqls: sqls( - "select a != b from binoptestts_ids;", - ), - expErr: "types 'TIMESTAMP' and 'IDSET' are not equatable", - }, - { - sqls: sqls( - "select a = b from binoptestts_ids;", - ), - expErr: "types 'TIMESTAMP' and 'IDSET' are not equatable", - }, - { - sqls: sqls( - "select a <= b from binoptestts_ids;", - ), - expErr: " operator '<=' incompatible with type 'IDSET'", - }, - { - sqls: sqls( - "select a >= b from binoptestts_ids;", - ), - expErr: " operator '>=' incompatible with type 'IDSET'", - }, - { - sqls: sqls( - "select a < b from binoptestts_ids;", - ), - expErr: " operator '<' incompatible with type 'IDSET'", - }, - { - sqls: sqls( - "select a > b from binoptestts_ids;", - ), - expErr: " operator '>' incompatible with type 'IDSET'", - }, - { - sqls: sqls( - "select a & b from binoptestts_ids;", - ), - expErr: " operator '&' incompatible with type 'TIMESTAMP'", - }, - { - sqls: sqls( - "select a | b from binoptestts_ids;", - ), - expErr: " operator '|' incompatible with type 'TIMESTAMP'", - }, - { - sqls: sqls( - "select a << b from binoptestts_ids;", - ), - expErr: " operator '<<' incompatible with type 'TIMESTAMP'", - }, - { - sqls: sqls( - "select a >> b from binoptestts_ids;", - ), - expErr: " operator '>>' incompatible with type 'TIMESTAMP'", - }, - { - sqls: sqls( - "select a + b from binoptestts_ids;", - ), - expErr: " operator '+' incompatible with type 'TIMESTAMP'", - }, - { - sqls: sqls( - "select a - b from binoptestts_ids;", - ), - expErr: " operator '-' incompatible with type 'TIMESTAMP'", - }, - { - sqls: sqls( - "select a * b from binoptestts_ids;", - ), - expErr: " operator '*' incompatible with type 'TIMESTAMP'", - }, - { - sqls: sqls( - "select a / b from binoptestts_ids;", - ), - expErr: " operator '/' incompatible with type 'TIMESTAMP'", - }, - { - sqls: sqls( - "select a % b from binoptestts_ids;", - ), - expErr: " operator '%' incompatible with type 'TIMESTAMP'", - }, - { - sqls: sqls( - "select a || b from binoptestts_ids;", - ), - expErr: "operator '||' incompatible with type 'TIMESTAMP'", - }, - }, -} - -var binOpExprWithTSString = tableTest{ - table: tbl( - "binoptestts_s", - srcHdrs( - srcHdr("_id", fldTypeID), - srcHdr("a", fldTypeTimestamp), - srcHdr("b", fldTypeString), - ), - srcRows( - srcRow(int64(1), time.Time(knownTimestamp()), string("101")), - ), - ), - sqlTests: []sqlTest{ - { - sqls: sqls( - "select a != b from binoptestts_s;", - ), - expErr: "types 'TIMESTAMP' and 'STRING' are not equatable", - }, - { - sqls: sqls( - "select a = b from binoptestts_s;", - ), - expErr: "types 'TIMESTAMP' and 'STRING' are not equatable", - }, - { - sqls: sqls( - "select a <= b from binoptestts_s;", - ), - expErr: " operator '<=' incompatible with type 'STRING'", - }, - { - sqls: sqls( - "select a >= b from binoptestts_s;", - ), - expErr: " operator '>=' incompatible with type 'STRING'", - }, - { - sqls: sqls( - "select a < b from binoptestts_s;", - ), - expErr: " operator '<' incompatible with type 'STRING'", - }, - { - sqls: sqls( - "select a > b from binoptestts_s;", - ), - expErr: " operator '>' incompatible with type 'STRING'", - }, - { - sqls: sqls( - "select a & b from binoptestts_s;", - ), - expErr: " operator '&' incompatible with type 'TIMESTAMP'", - }, - { - sqls: sqls( - "select a | b from binoptestts_s;", - ), - expErr: " operator '|' incompatible with type 'TIMESTAMP'", - }, - { - sqls: sqls( - "select a << b from binoptestts_s;", - ), - expErr: " operator '<<' incompatible with type 'TIMESTAMP'", - }, - { - sqls: sqls( - "select a >> b from binoptestts_s;", - ), - expErr: " operator '>>' incompatible with type 'TIMESTAMP'", - }, - { - sqls: sqls( - "select a + b from binoptestts_s;", - ), - expErr: " operator '+' incompatible with type 'TIMESTAMP'", - }, - { - sqls: sqls( - "select a - b from binoptestts_s;", - ), - expErr: " operator '-' incompatible with type 'TIMESTAMP'", - }, - { - sqls: sqls( - "select a * b from binoptestts_s;", - ), - expErr: " operator '*' incompatible with type 'TIMESTAMP'", - }, - { - sqls: sqls( - "select a / b from binoptestts_s;", - ), - expErr: " operator '/' incompatible with type 'TIMESTAMP'", - }, - { - sqls: sqls( - "select a % b from binoptestts_s;", - ), - expErr: " operator '%' incompatible with type 'TIMESTAMP'", - }, - { - sqls: sqls( - "select a || b from binoptestts_s;", - ), - expErr: "operator '||' incompatible with type 'TIMESTAMP'", - }, - }, -} - -var binOpExprWithTSStringSet = tableTest{ - table: tbl( - "binoptestts_ss", - srcHdrs( - srcHdr("_id", fldTypeID), - srcHdr("a", fldTypeTimestamp), - srcHdr("b", fldTypeStringSet), - ), - srcRows( - srcRow(int64(1), time.Time(knownTimestamp()), []string{"101", "102"}), - ), - ), - sqlTests: []sqlTest{ - { - sqls: sqls( - "select a != b from binoptestts_ss;", - ), - expErr: "types 'TIMESTAMP' and 'STRINGSET' are not equatable", - }, - { - sqls: sqls( - "select a = b from binoptestts_ss;", - ), - expErr: "types 'TIMESTAMP' and 'STRINGSET' are not equatable", - }, - { - sqls: sqls( - "select a <= b from binoptestts_ss;", - ), - expErr: " operator '<=' incompatible with type 'STRINGSET'", - }, - { - sqls: sqls( - "select a >= b from binoptestts_ss;", - ), - expErr: " operator '>=' incompatible with type 'STRINGSET'", - }, - { - sqls: sqls( - "select a < b from binoptestts_ss;", - ), - expErr: " operator '<' incompatible with type 'STRINGSET'", - }, - { - sqls: sqls( - "select a > b from binoptestts_ss;", - ), - expErr: " operator '>' incompatible with type 'STRINGSET'", - }, - { - sqls: sqls( - "select a & b from binoptestts_ss;", - ), - expErr: " operator '&' incompatible with type 'TIMESTAMP'", - }, - { - sqls: sqls( - "select a | b from binoptestts_ss;", - ), - expErr: " operator '|' incompatible with type 'TIMESTAMP'", - }, - { - sqls: sqls( - "select a << b from binoptestts_ss;", - ), - expErr: " operator '<<' incompatible with type 'TIMESTAMP'", - }, - { - sqls: sqls( - "select a >> b from binoptestts_ss;", - ), - expErr: " operator '>>' incompatible with type 'TIMESTAMP'", - }, - { - sqls: sqls( - "select a + b from binoptestts_ss;", - ), - expErr: " operator '+' incompatible with type 'TIMESTAMP'", - }, - { - sqls: sqls( - "select a - b from binoptestts_ss;", - ), - expErr: " operator '-' incompatible with type 'TIMESTAMP'", - }, - { - sqls: sqls( - "select a * b from binoptestts_ss;", - ), - expErr: " operator '*' incompatible with type 'TIMESTAMP'", - }, - { - sqls: sqls( - "select a / b from binoptestts_ss;", - ), - expErr: " operator '/' incompatible with type 'TIMESTAMP'", - }, - { - sqls: sqls( - "select a % b from binoptestts_ss;", - ), - expErr: " operator '%' incompatible with type 'TIMESTAMP'", - }, - { - sqls: sqls( - "select a || b from binoptestts_ss;", - ), - expErr: "operator '||' incompatible with type 'TIMESTAMP'", - }, - }, -} - -// IDSET bin op tests -var binOpExprWithIDSetInt = tableTest{ - table: tbl( - "binoptestids_i", - srcHdrs( - srcHdr("_id", fldTypeID), - srcHdr("b", fldTypeInt), - srcHdr("d", fldTypeIDSet), - ), - srcRows( - srcRow(int64(10), int64(20), []int64{20, 21}), - ), - ), - sqlTests: []sqlTest{ - { - sqls: sqls( - "select d != b from binoptestids_i;", - ), - expErr: "types 'IDSET' and 'INT' are not equatable", - }, - { - sqls: sqls( - "select d = b from binoptestids_i;", - ), - expErr: "types 'IDSET' and 'INT' are not equatable", - }, - { - sqls: sqls( - "select d <= b from binoptestids_i;", - ), - expErr: "operator '<=' incompatible with type 'IDSET'", - }, - { - sqls: sqls( - "select d >= b from binoptestids_i;", - ), - expErr: "operator '>=' incompatible with type 'IDSET'", - }, - { - sqls: sqls( - "select d < b from binoptestids_i;", - ), - expErr: "operator '<' incompatible with type 'IDSET'", - }, - { - sqls: sqls( - "select d > b from binoptestids_i;", - ), - expErr: "operator '>' incompatible with type 'IDSET'", - }, - { - sqls: sqls( - "select d & b from binoptestids_i;", - ), - expErr: "operator '&' incompatible with type 'IDSET'", - }, - { - sqls: sqls( - "select d | b from binoptestids_i;", - ), - expErr: "operator '|' incompatible with type 'IDSET'", - }, - { - sqls: sqls( - "select d << b from binoptestids_i;", - ), - expErr: "operator '<<' incompatible with type 'IDSET'", - }, - { - sqls: sqls( - "select d >> b from binoptestids_i;", - ), - expErr: "operator '>>' incompatible with type 'IDSET'", - }, - { - sqls: sqls( - "select d + b from binoptestids_i;", - ), - expErr: "operator '+' incompatible with type 'IDSET'", - }, - { - sqls: sqls( - "select d - b from binoptestids_i;", - ), - expErr: "operator '-' incompatible with type 'IDSET'", - }, - { - sqls: sqls( - "select d * b from binoptestids_i;", - ), - expErr: "operator '*' incompatible with type 'IDSET'", - }, - { - sqls: sqls( - "select d / b from binoptestids_i;", - ), - expErr: "operator '/' incompatible with type 'IDSET'", - }, - { - sqls: sqls( - "select d % b from binoptestids_i;", - ), - expErr: "operator '%' incompatible with type 'IDSET'", - }, - { - sqls: sqls( - "select d || b from binoptestids_i;", - ), - expErr: "operator '||' incompatible with type 'IDSET'", - }, - }, -} - -var binOpExprWithIDSetBool = tableTest{ - table: tbl( - "binoptestids_b", - srcHdrs( - srcHdr("_id", fldTypeID), - srcHdr("b", fldTypeBool), - srcHdr("d", fldTypeIDSet), - ), - srcRows( - srcRow(int64(10), bool(true), []int64{20, 21}), - ), - ), - sqlTests: []sqlTest{ - { - sqls: sqls( - "select d != b from binoptestids_b;", - ), - expErr: "types 'IDSET' and 'BOOL' are not equatable", - }, - { - sqls: sqls( - "select d = b from binoptestids_b;", - ), - expErr: "types 'IDSET' and 'BOOL' are not equatable", - }, - { - sqls: sqls( - "select d <= b from binoptestids_b;", - ), - expErr: "operator '<=' incompatible with type 'IDSET'", - }, - { - sqls: sqls( - "select d >= b from binoptestids_b;", - ), - expErr: "operator '>=' incompatible with type 'IDSET'", - }, - { - sqls: sqls( - "select d < b from binoptestids_b;", - ), - expErr: "operator '<' incompatible with type 'IDSET'", - }, - { - sqls: sqls( - "select d > b from binoptestids_b;", - ), - expErr: "operator '>' incompatible with type 'IDSET'", - }, - { - sqls: sqls( - "select d & b from binoptestids_b;", - ), - expErr: "operator '&' incompatible with type 'IDSET'", - }, - { - sqls: sqls( - "select d | b from binoptestids_b;", - ), - expErr: "operator '|' incompatible with type 'IDSET'", - }, - { - sqls: sqls( - "select d << b from binoptestids_b;", - ), - expErr: "operator '<<' incompatible with type 'IDSET'", - }, - { - sqls: sqls( - "select d >> b from binoptestids_b;", - ), - expErr: "operator '>>' incompatible with type 'IDSET'", - }, - { - sqls: sqls( - "select d + b from binoptestids_b;", - ), - expErr: "operator '+' incompatible with type 'IDSET'", - }, - { - sqls: sqls( - "select d - b from binoptestids_b;", - ), - expErr: "operator '-' incompatible with type 'IDSET'", - }, - { - sqls: sqls( - "select d * b from binoptestids_b;", - ), - expErr: "operator '*' incompatible with type 'IDSET'", - }, - { - sqls: sqls( - "select d / b from binoptestids_b;", - ), - expErr: "operator '/' incompatible with type 'IDSET'", - }, - { - sqls: sqls( - "select d % b from binoptestids_b;", - ), - expErr: "operator '%' incompatible with type 'IDSET'", - }, - { - sqls: sqls( - "select d || b from binoptestids_b;", - ), - expErr: "operator '||' incompatible with type 'IDSET'", - }, - }, -} - -var binOpExprWithIDSetID = tableTest{ - table: tbl( - "binoptestids_id", - srcHdrs( - srcHdr("_id", fldTypeID), - srcHdr("b", fldTypeID), - srcHdr("d", fldTypeIDSet), - ), - srcRows( - srcRow(int64(10), int64(20), []int64{20, 21}), - ), - ), - sqlTests: []sqlTest{ - { - sqls: sqls( - "select d != b from binoptestids_id;", - ), - expErr: "types 'IDSET' and 'ID' are not equatable", - }, - { - sqls: sqls( - "select d = b from binoptestids_id;", - ), - expErr: "types 'IDSET' and 'ID' are not equatable", - }, - { - sqls: sqls( - "select d <= b from binoptestids_id;", - ), - expErr: "operator '<=' incompatible with type 'IDSET'", - }, - { - sqls: sqls( - "select d >= b from binoptestids_id;", - ), - expErr: "operator '>=' incompatible with type 'IDSET'", - }, - { - sqls: sqls( - "select d < b from binoptestids_id;", - ), - expErr: "operator '<' incompatible with type 'IDSET'", - }, - { - sqls: sqls( - "select d > b from binoptestids_id;", - ), - expErr: "operator '>' incompatible with type 'IDSET'", - }, - { - sqls: sqls( - "select d & b from binoptestids_id;", - ), - expErr: "operator '&' incompatible with type 'IDSET'", - }, - { - sqls: sqls( - "select d | b from binoptestids_id;", - ), - expErr: "operator '|' incompatible with type 'IDSET'", - }, - { - sqls: sqls( - "select d << b from binoptestids_id;", - ), - expErr: "operator '<<' incompatible with type 'IDSET'", - }, - { - sqls: sqls( - "select d >> b from binoptestids_id;", - ), - expErr: "operator '>>' incompatible with type 'IDSET'", - }, - { - sqls: sqls( - "select d + b from binoptestids_id;", - ), - expErr: "operator '+' incompatible with type 'IDSET'", - }, - { - sqls: sqls( - "select d - b from binoptestids_id;", - ), - expErr: "operator '-' incompatible with type 'IDSET'", - }, - { - sqls: sqls( - "select d * b from binoptestids_id;", - ), - expErr: "operator '*' incompatible with type 'IDSET'", - }, - { - sqls: sqls( - "select d / b from binoptestids_id;", - ), - expErr: "operator '/' incompatible with type 'IDSET'", - }, - { - sqls: sqls( - "select d % b from binoptestids_id;", - ), - expErr: "operator '%' incompatible with type 'IDSET'", - }, - { - sqls: sqls( - "select d || b from binoptestids_id;", - ), - expErr: "operator '||' incompatible with type 'IDSET'", - }, - }, -} - -var binOpExprWithIDSetDecimal = tableTest{ - table: tbl( - "binoptestids_d", - srcHdrs( - srcHdr("_id", fldTypeID), - srcHdr("a", fldTypeIDSet), - srcHdr("d", fldTypeDecimal2), - ), - srcRows( - srcRow(int64(1), []int64{20, 21}, float64(12.34)), - ), - ), - sqlTests: []sqlTest{ - { - sqls: sqls( - "select a != d from binoptestids_d;", - ), - expErr: "types 'IDSET' and 'DECIMAL(2)' are not equatable", - }, - { - sqls: sqls( - "select a = d from binoptestids_d;", - ), - expErr: "types 'IDSET' and 'DECIMAL(2)' are not equatable", - }, - { - sqls: sqls( - "select a <= d from binoptestids_d;", - ), - expErr: "operator '<=' incompatible with type 'IDSET'", - }, - { - sqls: sqls( - "select a >= d from binoptestids_d;", - ), - expErr: "operator '>=' incompatible with type 'IDSET'", - }, - { - sqls: sqls( - "select a < d from binoptestids_d;", - ), - expErr: "operator '<' incompatible with type 'IDSET'", - }, - { - sqls: sqls( - "select a > d from binoptestids_d;", - ), - expErr: "operator '>' incompatible with type 'IDSET'", - }, - { - sqls: sqls( - "select a & d from binoptestids_d;", - ), - expErr: "operator '&' incompatible with type 'IDSET'", - }, - { - sqls: sqls( - "select a | d from binoptestids_d;", - ), - expErr: "operator '|' incompatible with type 'IDSET'", - }, - { - sqls: sqls( - "select a << d from binoptestids_d;", - ), - expErr: "operator '<<' incompatible with type 'IDSET'", - }, - { - sqls: sqls( - "select a >> d from binoptestids_d;", - ), - expErr: "operator '>>' incompatible with type 'IDSET'", - }, - { - sqls: sqls( - "select a + d from binoptestids_d;", - ), - expErr: "operator '+' incompatible with type 'IDSET'", - }, - { - sqls: sqls( - "select a - d from binoptestids_d;", - ), - expErr: "operator '-' incompatible with type 'IDSET'", - }, - { - sqls: sqls( - "select a * d from binoptestids_d;", - ), - expErr: "operator '*' incompatible with type 'IDSET'", - }, - { - sqls: sqls( - "select a / d from binoptestids_d;", - ), - expErr: "operator '/' incompatible with type 'IDSET'", - }, - { - sqls: sqls( - "select a % d from binoptestids_d;", - ), - expErr: "operator '%' incompatible with type 'IDSET'", - }, - { - sqls: sqls( - "select a || d from binoptestids_d;", - ), - expErr: "operator '||' incompatible with type 'IDSET'", - }, - }, -} - -var binOpExprWithIDSetTimestamp = tableTest{ - table: tbl( - "binoptestids_ts", - srcHdrs( - srcHdr("_id", fldTypeID), - srcHdr("a", fldTypeIDSet), - srcHdr("ts", fldTypeTimestamp), - ), - srcRows( - srcRow(int64(1), []int64{20, 21}, time.Time(knownTimestamp())), - ), - ), - sqlTests: []sqlTest{ - { - sqls: sqls( - "select a != ts from binoptestids_ts;", - ), - expErr: "types 'IDSET' and 'TIMESTAMP' are not equatable", - }, - { - sqls: sqls( - "select a = ts from binoptestids_ts;", - ), - expErr: "types 'IDSET' and 'TIMESTAMP' are not equatable", - }, - { - sqls: sqls( - "select a <= ts from binoptestids_ts;", - ), - expErr: " operator '<=' incompatible with type 'IDSET'", - }, - { - sqls: sqls( - "select a >= ts from binoptestids_ts;", - ), - expErr: " operator '>=' incompatible with type 'IDSET'", - }, - { - sqls: sqls( - "select a < ts from binoptestids_ts;", - ), - expErr: " operator '<' incompatible with type 'IDSET'", - }, - { - sqls: sqls( - "select a > ts from binoptestids_ts;", - ), - expErr: " operator '>' incompatible with type 'IDSET'", - }, - { - sqls: sqls( - "select a & ts from binoptestids_ts;", - ), - expErr: "operator '&' incompatible with type 'IDSET'", - }, - { - sqls: sqls( - "select a | ts from binoptestids_ts;", - ), - expErr: "operator '|' incompatible with type 'IDSET'", - }, - { - sqls: sqls( - "select a << ts from binoptestids_ts;", - ), - expErr: "operator '<<' incompatible with type 'IDSET'", - }, - { - sqls: sqls( - "select a >> ts from binoptestids_ts;", - ), - expErr: "operator '>>' incompatible with type 'IDSET'", - }, - { - sqls: sqls( - "select a + ts from binoptestids_ts;", - ), - expErr: "operator '+' incompatible with type 'IDSET'", - }, - { - sqls: sqls( - "select a - ts from binoptestids_ts;", - ), - expErr: "operator '-' incompatible with type 'IDSET'", - }, - { - sqls: sqls( - "select a * ts from binoptestids_ts;", - ), - expErr: "operator '*' incompatible with type 'IDSET'", - }, - { - sqls: sqls( - "select a / ts from binoptestids_ts;", - ), - expErr: "operator '/' incompatible with type 'IDSET'", - }, - { - sqls: sqls( - "select a % ts from binoptestids_ts;", - ), - expErr: "operator '%' incompatible with type 'IDSET'", - }, - { - sqls: sqls( - "select a || ts from binoptestids_ts;", - ), - expErr: "operator '||' incompatible with type 'IDSET'", - }, - }, -} - -var binOpExprWithIDSetIDSet = tableTest{ - table: tbl( - "binoptestids_ids", - srcHdrs( - srcHdr("_id", fldTypeID), - srcHdr("a", fldTypeIDSet), - srcHdr("b", fldTypeIDSet), - ), - srcRows( - srcRow(int64(1), []int64{101, 103}, []int64{101, 102}), - ), - ), - sqlTests: []sqlTest{ - { - sqls: sqls( - "select a != b from binoptestids_ids;", - ), - expHdrs: hdrs( - hdr("", fldTypeBool), - ), - expRows: rows( - row(bool(true)), - ), - compare: compareExactUnordered, - }, - { - sqls: sqls( - "select a = b from binoptestids_ids;", - ), - expHdrs: hdrs( - hdr("", fldTypeBool), - ), - expRows: rows( - row(bool(false)), - ), - compare: compareExactUnordered, - }, - { - sqls: sqls( - "select a <= b from binoptestids_ids;", - ), - expErr: " operator '<=' incompatible with type 'IDSET'", - }, - { - sqls: sqls( - "select a >= b from binoptestids_ids;", - ), - expErr: " operator '>=' incompatible with type 'IDSET'", - }, - { - sqls: sqls( - "select a < b from binoptestids_ids;", - ), - expErr: " operator '<' incompatible with type 'IDSET'", - }, - { - sqls: sqls( - "select a > b from binoptestids_ids;", - ), - expErr: " operator '>' incompatible with type 'IDSET'", - }, - { - sqls: sqls( - "select a & b from binoptestids_ids;", - ), - expErr: " operator '&' incompatible with type 'IDSET'", - }, - { - sqls: sqls( - "select a | b from binoptestids_ids;", - ), - expErr: " operator '|' incompatible with type 'IDSET'", - }, - { - sqls: sqls( - "select a << b from binoptestids_ids;", - ), - expErr: " operator '<<' incompatible with type 'IDSET'", - }, - { - sqls: sqls( - "select a >> b from binoptestids_ids;", - ), - expErr: " operator '>>' incompatible with type 'IDSET'", - }, - { - sqls: sqls( - "select a + b from binoptestids_ids;", - ), - expErr: " operator '+' incompatible with type 'IDSET'", - }, - { - sqls: sqls( - "select a - b from binoptestids_ids;", - ), - expErr: " operator '-' incompatible with type 'IDSET'", - }, - { - sqls: sqls( - "select a * b from binoptestids_ids;", - ), - expErr: " operator '*' incompatible with type 'IDSET'", - }, - { - sqls: sqls( - "select a / b from binoptestids_ids;", - ), - expErr: " operator '/' incompatible with type 'IDSET'", - }, - { - sqls: sqls( - "select a % b from binoptestids_ids;", - ), - expErr: " operator '%' incompatible with type 'IDSET'", - }, - { - sqls: sqls( - "select a || b from binoptestids_ids;", - ), - expErr: "operator '||' incompatible with type 'IDSET'", - }, - }, -} - -var binOpExprWithIDSetString = tableTest{ - table: tbl( - "binoptestids_s", - srcHdrs( - srcHdr("_id", fldTypeID), - srcHdr("a", fldTypeIDSet), - srcHdr("b", fldTypeString), - ), - srcRows( - srcRow(int64(1), []int64{101, 102}, string("101")), - ), - ), - sqlTests: []sqlTest{ - { - sqls: sqls( - "select a != b from binoptestids_s;", - ), - expErr: "types 'IDSET' and 'STRING' are not equatable", - }, - { - sqls: sqls( - "select a = b from binoptestids_s;", - ), - expErr: "types 'IDSET' and 'STRING' are not equatable", - }, - { - sqls: sqls( - "select a <= b from binoptestids_s;", - ), - expErr: " operator '<=' incompatible with type 'IDSET'", - }, - { - sqls: sqls( - "select a >= b from binoptestids_s;", - ), - expErr: " operator '>=' incompatible with type 'IDSET'", - }, - { - sqls: sqls( - "select a < b from binoptestids_s;", - ), - expErr: " operator '<' incompatible with type 'IDSET'", - }, - { - sqls: sqls( - "select a > b from binoptestids_s;", - ), - expErr: " operator '>' incompatible with type 'IDSET'", - }, - { - sqls: sqls( - "select a & b from binoptestids_s;", - ), - expErr: " operator '&' incompatible with type 'IDSET'", - }, - { - sqls: sqls( - "select a | b from binoptestids_s;", - ), - expErr: " operator '|' incompatible with type 'IDSET'", - }, - { - sqls: sqls( - "select a << b from binoptestids_s;", - ), - expErr: " operator '<<' incompatible with type 'IDSET'", - }, - { - sqls: sqls( - "select a >> b from binoptestids_s;", - ), - expErr: " operator '>>' incompatible with type 'IDSET'", - }, - { - sqls: sqls( - "select a + b from binoptestids_s;", - ), - expErr: " operator '+' incompatible with type 'IDSET'", - }, - { - sqls: sqls( - "select a - b from binoptestids_s;", - ), - expErr: " operator '-' incompatible with type 'IDSET'", - }, - { - sqls: sqls( - "select a * b from binoptestids_s;", - ), - expErr: " operator '*' incompatible with type 'IDSET'", - }, - { - sqls: sqls( - "select a / b from binoptestids_s;", - ), - expErr: " operator '/' incompatible with type 'IDSET'", - }, - { - sqls: sqls( - "select a % b from binoptestids_s;", - ), - expErr: " operator '%' incompatible with type 'IDSET'", - }, - { - sqls: sqls( - "select a || b from binoptestids_s;", - ), - expErr: "operator '||' incompatible with type 'IDSET'", - }, - }, -} - -var binOpExprWithIDSetStringSet = tableTest{ - table: tbl( - "binoptestids_ss", - srcHdrs( - srcHdr("_id", fldTypeID), - srcHdr("a", fldTypeIDSet), - srcHdr("b", fldTypeStringSet), - ), - srcRows( - srcRow(int64(1), []int64{102, 103}, []string{"101", "102"}), - ), - ), - sqlTests: []sqlTest{ - { - sqls: sqls( - "select a != b from binoptestids_ss;", - ), - expErr: "types 'IDSET' and 'STRINGSET' are not equatable", - }, - { - sqls: sqls( - "select a = b from binoptestids_ss;", - ), - expErr: "types 'IDSET' and 'STRINGSET' are not equatable", - }, - { - sqls: sqls( - "select a <= b from binoptestids_ss;", - ), - expErr: " operator '<=' incompatible with type 'IDSET'", - }, - { - sqls: sqls( - "select a >= b from binoptestids_ss;", - ), - expErr: " operator '>=' incompatible with type 'IDSET'", - }, - { - sqls: sqls( - "select a < b from binoptestids_ss;", - ), - expErr: " operator '<' incompatible with type 'IDSET'", - }, - { - sqls: sqls( - "select a > b from binoptestids_ss;", - ), - expErr: " operator '>' incompatible with type 'IDSET'", - }, - { - sqls: sqls( - "select a & b from binoptestids_ss;", - ), - expErr: " operator '&' incompatible with type 'IDSET'", - }, - { - sqls: sqls( - "select a | b from binoptestids_ss;", - ), - expErr: " operator '|' incompatible with type 'IDSET'", - }, - { - sqls: sqls( - "select a << b from binoptestids_ss;", - ), - expErr: " operator '<<' incompatible with type 'IDSET'", - }, - { - sqls: sqls( - "select a >> b from binoptestids_ss;", - ), - expErr: " operator '>>' incompatible with type 'IDSET'", - }, - { - sqls: sqls( - "select a + b from binoptestids_ss;", - ), - expErr: " operator '+' incompatible with type 'IDSET'", - }, - { - sqls: sqls( - "select a - b from binoptestids_ss;", - ), - expErr: " operator '-' incompatible with type 'IDSET'", - }, - { - sqls: sqls( - "select a * b from binoptestids_ss;", - ), - expErr: " operator '*' incompatible with type 'IDSET'", - }, - { - sqls: sqls( - "select a / b from binoptestids_ss;", - ), - expErr: " operator '/' incompatible with type 'IDSET'", - }, - { - sqls: sqls( - "select a % b from binoptestids_ss;", - ), - expErr: " operator '%' incompatible with type 'IDSET'", - }, - { - sqls: sqls( - "select a || b from binoptestids_ss;", - ), - expErr: "operator '||' incompatible with type 'IDSET'", - }, - }, -} - -// STRING bin op tests -var binOpExprWithStringInt = tableTest{ - table: tbl( - "binoptests_i", - srcHdrs( - srcHdr("_id", fldTypeID), - srcHdr("b", fldTypeInt), - srcHdr("d", fldTypeString), - ), - srcRows( - srcRow(int64(10), int64(20), string("foo")), - ), - ), - sqlTests: []sqlTest{ - { - sqls: sqls( - "select d != b from binoptests_i;", - ), - expErr: "types 'STRING' and 'INT' are not equatable", - }, - { - sqls: sqls( - "select d = b from binoptests_i;", - ), - expErr: "types 'STRING' and 'INT' are not equatable", - }, - { - sqls: sqls( - "select d <= b from binoptests_i;", - ), - expErr: "operator '<=' incompatible with type 'STRING'", - }, - { - sqls: sqls( - "select d >= b from binoptests_i;", - ), - expErr: "operator '>=' incompatible with type 'STRING'", - }, - { - sqls: sqls( - "select d < b from binoptests_i;", - ), - expErr: "operator '<' incompatible with type 'STRING'", - }, - { - sqls: sqls( - "select d > b from binoptests_i;", - ), - expErr: "operator '>' incompatible with type 'STRING'", - }, - { - sqls: sqls( - "select d & b from binoptests_i;", - ), - expErr: "operator '&' incompatible with type 'STRING'", - }, - { - sqls: sqls( - "select d | b from binoptests_i;", - ), - expErr: "operator '|' incompatible with type 'STRING'", - }, - { - sqls: sqls( - "select d << b from binoptests_i;", - ), - expErr: "operator '<<' incompatible with type 'STRING'", - }, - { - sqls: sqls( - "select d >> b from binoptests_i;", - ), - expErr: "operator '>>' incompatible with type 'STRING'", - }, - { - sqls: sqls( - "select d + b from binoptests_i;", - ), - expErr: "operator '+' incompatible with type 'STRING'", - }, - { - sqls: sqls( - "select d - b from binoptests_i;", - ), - expErr: "operator '-' incompatible with type 'STRING'", - }, - { - sqls: sqls( - "select d * b from binoptests_i;", - ), - expErr: "operator '*' incompatible with type 'STRING'", - }, - { - sqls: sqls( - "select d / b from binoptests_i;", - ), - expErr: "operator '/' incompatible with type 'STRING'", - }, - { - sqls: sqls( - "select d % b from binoptests_i;", - ), - expErr: "operator '%' incompatible with type 'STRING'", - }, - { - sqls: sqls( - "select d || b from binoptests_i;", - ), - expErr: "operator '||' incompatible with type 'INT'", - }, - }, -} - -var binOpExprWithStringBool = tableTest{ - table: tbl( - "binoptests_b", - srcHdrs( - srcHdr("_id", fldTypeID), - srcHdr("b", fldTypeBool), - srcHdr("d", fldTypeString), - ), - srcRows( - srcRow(int64(10), bool(true), string("foo")), - ), - ), - sqlTests: []sqlTest{ - { - sqls: sqls( - "select d != b from binoptests_b;", - ), - expErr: "types 'STRING' and 'BOOL' are not equatable", - }, - { - sqls: sqls( - "select d = b from binoptests_b;", - ), - expErr: "types 'STRING' and 'BOOL' are not equatable", - }, - { - sqls: sqls( - "select d <= b from binoptests_b;", - ), - expErr: "operator '<=' incompatible with type 'STRING'", - }, - { - sqls: sqls( - "select d >= b from binoptests_b;", - ), - expErr: "operator '>=' incompatible with type 'STRING'", - }, - { - sqls: sqls( - "select d < b from binoptests_b;", - ), - expErr: "operator '<' incompatible with type 'STRING'", - }, - { - sqls: sqls( - "select d > b from binoptests_b;", - ), - expErr: "operator '>' incompatible with type 'STRING'", - }, - { - sqls: sqls( - "select d & b from binoptests_b;", - ), - expErr: "operator '&' incompatible with type 'STRING'", - }, - { - sqls: sqls( - "select d | b from binoptests_b;", - ), - expErr: "operator '|' incompatible with type 'STRING'", - }, - { - sqls: sqls( - "select d << b from binoptests_b;", - ), - expErr: "operator '<<' incompatible with type 'STRING'", - }, - { - sqls: sqls( - "select d >> b from binoptests_b;", - ), - expErr: "operator '>>' incompatible with type 'STRING'", - }, - { - sqls: sqls( - "select d + b from binoptests_b;", - ), - expErr: "operator '+' incompatible with type 'STRING'", - }, - { - sqls: sqls( - "select d - b from binoptests_b;", - ), - expErr: "operator '-' incompatible with type 'STRING'", - }, - { - sqls: sqls( - "select d * b from binoptests_b;", - ), - expErr: "operator '*' incompatible with type 'STRING'", - }, - { - sqls: sqls( - "select d / b from binoptests_b;", - ), - expErr: "operator '/' incompatible with type 'STRING'", - }, - { - sqls: sqls( - "select d % b from binoptests_b;", - ), - expErr: "operator '%' incompatible with type 'STRING'", - }, - { - sqls: sqls( - "select d || b from binoptests_b;", - ), - expErr: "operator '||' incompatible with type 'BOOL'", - }, - }, -} - -var binOpExprWithStringID = tableTest{ - table: tbl( - "binoptests_id", - srcHdrs( - srcHdr("_id", fldTypeID), - srcHdr("b", fldTypeID), - srcHdr("d", fldTypeString), - ), - srcRows( - srcRow(int64(10), int64(20), string("foo")), - ), - ), - sqlTests: []sqlTest{ - { - sqls: sqls( - "select d != b from binoptests_id;", - ), - expErr: "types 'STRING' and 'ID' are not equatable", - }, - { - sqls: sqls( - "select d = b from binoptests_id;", - ), - expErr: "types 'STRING' and 'ID' are not equatable", - }, - { - sqls: sqls( - "select d <= b from binoptests_id;", - ), - expErr: "operator '<=' incompatible with type 'STRING'", - }, - { - sqls: sqls( - "select d >= b from binoptests_id;", - ), - expErr: "operator '>=' incompatible with type 'STRING'", - }, - { - sqls: sqls( - "select d < b from binoptests_id;", - ), - expErr: "operator '<' incompatible with type 'STRING'", - }, - { - sqls: sqls( - "select d > b from binoptests_id;", - ), - expErr: "operator '>' incompatible with type 'STRING'", - }, - { - sqls: sqls( - "select d & b from binoptests_id;", - ), - expErr: "operator '&' incompatible with type 'STRING'", - }, - { - sqls: sqls( - "select d | b from binoptests_id;", - ), - expErr: "operator '|' incompatible with type 'STRING'", - }, - { - sqls: sqls( - "select d << b from binoptests_id;", - ), - expErr: "operator '<<' incompatible with type 'STRING'", - }, - { - sqls: sqls( - "select d >> b from binoptests_id;", - ), - expErr: "operator '>>' incompatible with type 'STRING'", - }, - { - sqls: sqls( - "select d + b from binoptests_id;", - ), - expErr: "operator '+' incompatible with type 'STRING'", - }, - { - sqls: sqls( - "select d - b from binoptests_id;", - ), - expErr: "operator '-' incompatible with type 'STRING'", - }, - { - sqls: sqls( - "select d * b from binoptests_id;", - ), - expErr: "operator '*' incompatible with type 'STRING'", - }, - { - sqls: sqls( - "select d / b from binoptests_id;", - ), - expErr: "operator '/' incompatible with type 'STRING'", - }, - { - sqls: sqls( - "select d % b from binoptests_id;", - ), - expErr: "operator '%' incompatible with type 'STRING'", - }, - { - sqls: sqls( - "select d || b from binoptests_id;", - ), - expErr: "operator '||' incompatible with type 'ID'", - }, - }, -} - -var binOpExprWithStringDecimal = tableTest{ - table: tbl( - "binoptests_d", - srcHdrs( - srcHdr("_id", fldTypeID), - srcHdr("a", fldTypeString), - srcHdr("d", fldTypeDecimal2), - ), - srcRows( - srcRow(int64(1), string("foo"), float64(12.34)), - ), - ), - sqlTests: []sqlTest{ - { - sqls: sqls( - "select a != d from binoptests_d;", - ), - expErr: "types 'STRING' and 'DECIMAL(2)' are not equatable", - }, - { - sqls: sqls( - "select a = d from binoptests_d;", - ), - expErr: "types 'STRING' and 'DECIMAL(2)' are not equatable", - }, - { - sqls: sqls( - "select a <= d from binoptests_d;", - ), - expErr: "operator '<=' incompatible with type 'STRING'", - }, - { - sqls: sqls( - "select a >= d from binoptests_d;", - ), - expErr: "operator '>=' incompatible with type 'STRING'", - }, - { - sqls: sqls( - "select a < d from binoptests_d;", - ), - expErr: "operator '<' incompatible with type 'STRING'", - }, - { - sqls: sqls( - "select a > d from binoptests_d;", - ), - expErr: "operator '>' incompatible with type 'STRING'", - }, - { - sqls: sqls( - "select a & d from binoptests_d;", - ), - expErr: "operator '&' incompatible with type 'STRING'", - }, - { - sqls: sqls( - "select a | d from binoptests_d;", - ), - expErr: "operator '|' incompatible with type 'STRING'", - }, - { - sqls: sqls( - "select a << d from binoptests_d;", - ), - expErr: "operator '<<' incompatible with type 'STRING'", - }, - { - sqls: sqls( - "select a >> d from binoptests_d;", - ), - expErr: "operator '>>' incompatible with type 'STRING'", - }, - { - sqls: sqls( - "select a + d from binoptests_d;", - ), - expErr: "operator '+' incompatible with type 'STRING'", - }, - { - sqls: sqls( - "select a - d from binoptests_d;", - ), - expErr: "operator '-' incompatible with type 'STRING'", - }, - { - sqls: sqls( - "select a * d from binoptests_d;", - ), - expErr: "operator '*' incompatible with type 'STRING'", - }, - { - sqls: sqls( - "select a / d from binoptests_d;", - ), - expErr: "operator '/' incompatible with type 'STRING'", - }, - { - sqls: sqls( - "select a % d from binoptests_d;", - ), - expErr: "operator '%' incompatible with type 'STRING'", - }, - { - sqls: sqls( - "select a || d from binoptests_d;", - ), - expErr: "operator '||' incompatible with type 'DECIMAL(2)'", - }, - }, -} - -var binOpExprWithStringTimestamp = tableTest{ - table: tbl( - "binoptests_ts", - srcHdrs( - srcHdr("_id", fldTypeID), - srcHdr("a", fldTypeString), - srcHdr("ts", fldTypeTimestamp), - ), - srcRows( - srcRow(int64(1), string("foo"), time.Time(knownTimestamp())), - ), - ), - sqlTests: []sqlTest{ - { - sqls: sqls( - "select a != ts from binoptests_ts;", - ), - expErr: "types 'STRING' and 'TIMESTAMP' are not equatable", - }, - { - sqls: sqls( - "select a = ts from binoptests_ts;", - ), - expErr: "types 'STRING' and 'TIMESTAMP' are not equatable", - }, - { - sqls: sqls( - "select a <= ts from binoptests_ts;", - ), - expErr: " operator '<=' incompatible with type 'STRING'", - }, - { - sqls: sqls( - "select a >= ts from binoptests_ts;", - ), - expErr: " operator '>=' incompatible with type 'STRING'", - }, - { - sqls: sqls( - "select a < ts from binoptests_ts;", - ), - expErr: " operator '<' incompatible with type 'STRING'", - }, - { - sqls: sqls( - "select a > ts from binoptests_ts;", - ), - expErr: " operator '>' incompatible with type 'STRING'", - }, - { - sqls: sqls( - "select a & ts from binoptests_ts;", - ), - expErr: "operator '&' incompatible with type 'STRING'", - }, - { - sqls: sqls( - "select a | ts from binoptests_ts;", - ), - expErr: "operator '|' incompatible with type 'STRING'", - }, - { - sqls: sqls( - "select a << ts from binoptests_ts;", - ), - expErr: "operator '<<' incompatible with type 'STRING'", - }, - { - sqls: sqls( - "select a >> ts from binoptests_ts;", - ), - expErr: "operator '>>' incompatible with type 'STRING'", - }, - { - sqls: sqls( - "select a + ts from binoptests_ts;", - ), - expErr: "operator '+' incompatible with type 'STRING'", - }, - { - sqls: sqls( - "select a - ts from binoptests_ts;", - ), - expErr: "operator '-' incompatible with type 'STRING'", - }, - { - sqls: sqls( - "select a * ts from binoptests_ts;", - ), - expErr: "operator '*' incompatible with type 'STRING'", - }, - { - sqls: sqls( - "select a / ts from binoptests_ts;", - ), - expErr: "operator '/' incompatible with type 'STRING'", - }, - { - sqls: sqls( - "select a % ts from binoptests_ts;", - ), - expErr: "operator '%' incompatible with type 'STRING'", - }, - { - sqls: sqls( - "select a || ts from binoptests_ts;", - ), - expErr: "operator '||' incompatible with type 'TIMESTAMP'", - }, - }, -} - -var binOpExprWithStringIDSet = tableTest{ - table: tbl( - "binoptests_ids", - srcHdrs( - srcHdr("_id", fldTypeID), - srcHdr("a", fldTypeString), - srcHdr("b", fldTypeIDSet), - ), - srcRows( - srcRow(int64(1), string("foo"), []int64{101, 102}), - ), - ), - sqlTests: []sqlTest{ - { - sqls: sqls( - "select a != b from binoptests_ids;", - ), - expErr: "types 'STRING' and 'IDSET' are not equatable", - }, - { - sqls: sqls( - "select a = b from binoptests_ids;", - ), - expErr: "types 'STRING' and 'IDSET' are not equatable", - }, - { - sqls: sqls( - "select a <= b from binoptests_ids;", - ), - expErr: " operator '<=' incompatible with type 'STRING'", - }, - { - sqls: sqls( - "select a >= b from binoptests_ids;", - ), - expErr: " operator '>=' incompatible with type 'STRING'", - }, - { - sqls: sqls( - "select a < b from binoptests_ids;", - ), - expErr: " operator '<' incompatible with type 'STRING'", - }, - { - sqls: sqls( - "select a > b from binoptests_ids;", - ), - expErr: " operator '>' incompatible with type 'STRING'", - }, - { - sqls: sqls( - "select a & b from binoptests_ids;", - ), - expErr: " operator '&' incompatible with type 'STRING'", - }, - { - sqls: sqls( - "select a | b from binoptests_ids;", - ), - expErr: " operator '|' incompatible with type 'STRING'", - }, - { - sqls: sqls( - "select a << b from binoptests_ids;", - ), - expErr: " operator '<<' incompatible with type 'STRING'", - }, - { - sqls: sqls( - "select a >> b from binoptests_ids;", - ), - expErr: " operator '>>' incompatible with type 'STRING'", - }, - { - sqls: sqls( - "select a + b from binoptests_ids;", - ), - expErr: " operator '+' incompatible with type 'STRING'", - }, - { - sqls: sqls( - "select a - b from binoptests_ids;", - ), - expErr: " operator '-' incompatible with type 'STRING'", - }, - { - sqls: sqls( - "select a * b from binoptests_ids;", - ), - expErr: " operator '*' incompatible with type 'STRING'", - }, - { - sqls: sqls( - "select a / b from binoptests_ids;", - ), - expErr: " operator '/' incompatible with type 'STRING'", - }, - { - sqls: sqls( - "select a % b from binoptests_ids;", - ), - expErr: " operator '%' incompatible with type 'STRING'", - }, - { - sqls: sqls( - "select a || b from binoptests_ids;", - ), - expErr: "operator '||' incompatible with type 'IDSET'", - }, - }, -} - -var binOpExprWithStringString = tableTest{ - table: tbl( - "binoptests_s", - srcHdrs( - srcHdr("_id", fldTypeID), - srcHdr("a", fldTypeString), - srcHdr("b", fldTypeString), - ), - srcRows( - srcRow(int64(1), string("foo"), string("101")), - ), - ), - sqlTests: []sqlTest{ - { - sqls: sqls( - "select a != b from binoptests_s;", - ), - expHdrs: hdrs( - hdr("", fldTypeBool), - ), - expRows: rows( - row(bool(true)), - ), - compare: compareExactUnordered, - }, - { - sqls: sqls( - "select a = b from binoptests_s;", - ), - expHdrs: hdrs( - hdr("", fldTypeBool), - ), - expRows: rows( - row(bool(false)), - ), - compare: compareExactUnordered, - }, - { - sqls: sqls( - "select a <= b from binoptests_s;", - ), - expErr: " operator '<=' incompatible with type 'STRING'", - }, - { - sqls: sqls( - "select a >= b from binoptests_s;", - ), - expErr: " operator '>=' incompatible with type 'STRING'", - }, - { - sqls: sqls( - "select a < b from binoptests_s;", - ), - expErr: " operator '<' incompatible with type 'STRING'", - }, - { - sqls: sqls( - "select a > b from binoptests_s;", - ), - expErr: " operator '>' incompatible with type 'STRING'", - }, - { - sqls: sqls( - "select a & b from binoptests_s;", - ), - expErr: " operator '&' incompatible with type 'STRING'", - }, - { - sqls: sqls( - "select a | b from binoptests_s;", - ), - expErr: " operator '|' incompatible with type 'STRING'", - }, - { - sqls: sqls( - "select a << b from binoptests_s;", - ), - expErr: " operator '<<' incompatible with type 'STRING'", - }, - { - sqls: sqls( - "select a >> b from binoptests_s;", - ), - expErr: " operator '>>' incompatible with type 'STRING'", - }, - { - sqls: sqls( - "select a + b from binoptests_s;", - ), - expErr: " operator '+' incompatible with type 'STRING'", - }, - { - sqls: sqls( - "select a - b from binoptests_s;", - ), - expErr: " operator '-' incompatible with type 'STRING'", - }, - { - sqls: sqls( - "select a * b from binoptests_s;", - ), - expErr: " operator '*' incompatible with type 'STRING'", - }, - { - sqls: sqls( - "select a / b from binoptests_s;", - ), - expErr: " operator '/' incompatible with type 'STRING'", - }, - { - sqls: sqls( - "select a % b from binoptests_s;", - ), - expErr: " operator '%' incompatible with type 'STRING'", - }, - { - sqls: sqls( - "select a || b from binoptests_s;", - ), - expHdrs: hdrs( - hdr("", fldTypeString), - ), - expRows: rows( - row(string("foo101")), - ), - compare: compareExactUnordered, - }, - }, -} - -var binOpExprWithStringStringSet = tableTest{ - table: tbl( - "binoptests_ss", - srcHdrs( - srcHdr("_id", fldTypeID), - srcHdr("a", fldTypeString), - srcHdr("b", fldTypeStringSet), - ), - srcRows( - srcRow(int64(1), string("foo"), []string{"101", "102"}), - ), - ), - sqlTests: []sqlTest{ - { - sqls: sqls( - "select a != b from binoptests_ss;", - ), - expErr: "types 'STRING' and 'STRINGSET' are not equatable", - }, - { - sqls: sqls( - "select a = b from binoptests_ss;", - ), - expErr: "types 'STRING' and 'STRINGSET' are not equatable", - }, - { - sqls: sqls( - "select a <= b from binoptests_ss;", - ), - expErr: " operator '<=' incompatible with type 'STRING'", - }, - { - sqls: sqls( - "select a >= b from binoptests_ss;", - ), - expErr: " operator '>=' incompatible with type 'STRING'", - }, - { - sqls: sqls( - "select a < b from binoptests_ss;", - ), - expErr: " operator '<' incompatible with type 'STRING'", - }, - { - sqls: sqls( - "select a > b from binoptests_ss;", - ), - expErr: " operator '>' incompatible with type 'STRING'", - }, - { - sqls: sqls( - "select a & b from binoptests_ss;", - ), - expErr: " operator '&' incompatible with type 'STRING'", - }, - { - sqls: sqls( - "select a | b from binoptests_ss;", - ), - expErr: " operator '|' incompatible with type 'STRING'", - }, - { - sqls: sqls( - "select a << b from binoptests_ss;", - ), - expErr: " operator '<<' incompatible with type 'STRING'", - }, - { - sqls: sqls( - "select a >> b from binoptests_ss;", - ), - expErr: " operator '>>' incompatible with type 'STRING'", - }, - { - sqls: sqls( - "select a + b from binoptests_ss;", - ), - expErr: " operator '+' incompatible with type 'STRING'", - }, - { - sqls: sqls( - "select a - b from binoptests_ss;", - ), - expErr: " operator '-' incompatible with type 'STRING'", - }, - { - sqls: sqls( - "select a * b from binoptests_ss;", - ), - expErr: " operator '*' incompatible with type 'STRING'", - }, - { - sqls: sqls( - "select a / b from binoptests_ss;", - ), - expErr: " operator '/' incompatible with type 'STRING'", - }, - { - sqls: sqls( - "select a % b from binoptests_ss;", - ), - expErr: " operator '%' incompatible with type 'STRING'", - }, - { - sqls: sqls( - "select a || b from binoptests_ss;", - ), - expErr: "operator '||' incompatible with type 'STRINGSET'", - }, - }, -} - -// STRINGSET bin op tests -var binOpExprWithStringSetInt = tableTest{ - table: tbl( - "binoptestss_i", - srcHdrs( - srcHdr("_id", fldTypeID), - srcHdr("b", fldTypeInt), - srcHdr("d", fldTypeStringSet), - ), - srcRows( - srcRow(int64(10), int64(20), []string{"20", "21"}), - ), - ), - sqlTests: []sqlTest{ - { - sqls: sqls( - "select d != b from binoptestss_i;", - ), - expErr: "types 'STRINGSET' and 'INT' are not equatable", - }, - { - sqls: sqls( - "select d = b from binoptestss_i;", - ), - expErr: "types 'STRINGSET' and 'INT' are not equatable", - }, - { - sqls: sqls( - "select d <= b from binoptestss_i;", - ), - expErr: "operator '<=' incompatible with type 'STRINGSET'", - }, - { - sqls: sqls( - "select d >= b from binoptestss_i;", - ), - expErr: "operator '>=' incompatible with type 'STRINGSET'", - }, - { - sqls: sqls( - "select d < b from binoptestss_i;", - ), - expErr: "operator '<' incompatible with type 'STRINGSET'", - }, - { - sqls: sqls( - "select d > b from binoptestss_i;", - ), - expErr: "operator '>' incompatible with type 'STRINGSET'", - }, - { - sqls: sqls( - "select d & b from binoptestss_i;", - ), - expErr: "operator '&' incompatible with type 'STRINGSET'", - }, - { - sqls: sqls( - "select d | b from binoptestss_i;", - ), - expErr: "operator '|' incompatible with type 'STRINGSET'", - }, - { - sqls: sqls( - "select d << b from binoptestss_i;", - ), - expErr: "operator '<<' incompatible with type 'STRINGSET'", - }, - { - sqls: sqls( - "select d >> b from binoptestss_i;", - ), - expErr: "operator '>>' incompatible with type 'STRINGSET'", - }, - { - sqls: sqls( - "select d + b from binoptestss_i;", - ), - expErr: "operator '+' incompatible with type 'STRINGSET'", - }, - { - sqls: sqls( - "select d - b from binoptestss_i;", - ), - expErr: "operator '-' incompatible with type 'STRINGSET'", - }, - { - sqls: sqls( - "select d * b from binoptestss_i;", - ), - expErr: "operator '*' incompatible with type 'STRINGSET'", - }, - { - sqls: sqls( - "select d / b from binoptestss_i;", - ), - expErr: "operator '/' incompatible with type 'STRINGSET'", - }, - { - sqls: sqls( - "select d % b from binoptestss_i;", - ), - expErr: "operator '%' incompatible with type 'STRINGSET'", - }, - { - sqls: sqls( - "select d || b from binoptestss_i;", - ), - expErr: "operator '||' incompatible with type 'STRINGSET'", - }, - }, -} - -var binOpExprWithStringSetBool = tableTest{ - table: tbl( - "binoptestss_b", - srcHdrs( - srcHdr("_id", fldTypeID), - srcHdr("b", fldTypeBool), - srcHdr("d", fldTypeStringSet), - ), - srcRows( - srcRow(int64(10), bool(true), []string{"20", "21"}), - ), - ), - sqlTests: []sqlTest{ - { - sqls: sqls( - "select d != b from binoptestss_b;", - ), - expErr: "types 'STRINGSET' and 'BOOL' are not equatable", - }, - { - sqls: sqls( - "select d = b from binoptestss_b;", - ), - expErr: "types 'STRINGSET' and 'BOOL' are not equatable", - }, - { - sqls: sqls( - "select d <= b from binoptestss_b;", - ), - expErr: "operator '<=' incompatible with type 'STRINGSET'", - }, - { - sqls: sqls( - "select d >= b from binoptestss_b;", - ), - expErr: "operator '>=' incompatible with type 'STRINGSET'", - }, - { - sqls: sqls( - "select d < b from binoptestss_b;", - ), - expErr: "operator '<' incompatible with type 'STRINGSET'", - }, - { - sqls: sqls( - "select d > b from binoptestss_b;", - ), - expErr: "operator '>' incompatible with type 'STRINGSET'", - }, - { - sqls: sqls( - "select d & b from binoptestss_b;", - ), - expErr: "operator '&' incompatible with type 'STRINGSET'", - }, - { - sqls: sqls( - "select d | b from binoptestss_b;", - ), - expErr: "operator '|' incompatible with type 'STRINGSET'", - }, - { - sqls: sqls( - "select d << b from binoptestss_b;", - ), - expErr: "operator '<<' incompatible with type 'STRINGSET'", - }, - { - sqls: sqls( - "select d >> b from binoptestss_b;", - ), - expErr: "operator '>>' incompatible with type 'STRINGSET'", - }, - { - sqls: sqls( - "select d + b from binoptestss_b;", - ), - expErr: "operator '+' incompatible with type 'STRINGSET'", - }, - { - sqls: sqls( - "select d - b from binoptestss_b;", - ), - expErr: "operator '-' incompatible with type 'STRINGSET'", - }, - { - sqls: sqls( - "select d * b from binoptestss_b;", - ), - expErr: "operator '*' incompatible with type 'STRINGSET'", - }, - { - sqls: sqls( - "select d / b from binoptestss_b;", - ), - expErr: "operator '/' incompatible with type 'STRINGSET'", - }, - { - sqls: sqls( - "select d % b from binoptestss_b;", - ), - expErr: "operator '%' incompatible with type 'STRINGSET'", - }, - { - sqls: sqls( - "select d || b from binoptestss_b;", - ), - expErr: "operator '||' incompatible with type 'STRINGSET'", - }, - }, -} - -var binOpExprWithStringSetID = tableTest{ - table: tbl( - "binoptestss_id", - srcHdrs( - srcHdr("_id", fldTypeID), - srcHdr("b", fldTypeID), - srcHdr("d", fldTypeStringSet), - ), - srcRows( - srcRow(int64(10), int64(20), []string{"20", "21"}), - ), - ), - sqlTests: []sqlTest{ - { - sqls: sqls( - "select d != b from binoptestss_id;", - ), - expErr: "types 'STRINGSET' and 'ID' are not equatable", - }, - { - sqls: sqls( - "select d = b from binoptestss_id;", - ), - expErr: "types 'STRINGSET' and 'ID' are not equatable", - }, - { - sqls: sqls( - "select d <= b from binoptestss_id;", - ), - expErr: "operator '<=' incompatible with type 'STRINGSET'", - }, - { - sqls: sqls( - "select d >= b from binoptestss_id;", - ), - expErr: "operator '>=' incompatible with type 'STRINGSET'", - }, - { - sqls: sqls( - "select d < b from binoptestss_id;", - ), - expErr: "operator '<' incompatible with type 'STRINGSET'", - }, - { - sqls: sqls( - "select d > b from binoptestss_id;", - ), - expErr: "operator '>' incompatible with type 'STRINGSET'", - }, - { - sqls: sqls( - "select d & b from binoptestss_id;", - ), - expErr: "operator '&' incompatible with type 'STRINGSET'", - }, - { - sqls: sqls( - "select d | b from binoptestss_id;", - ), - expErr: "operator '|' incompatible with type 'STRINGSET'", - }, - { - sqls: sqls( - "select d << b from binoptestss_id;", - ), - expErr: "operator '<<' incompatible with type 'STRINGSET'", - }, - { - sqls: sqls( - "select d >> b from binoptestss_id;", - ), - expErr: "operator '>>' incompatible with type 'STRINGSET'", - }, - { - sqls: sqls( - "select d + b from binoptestss_id;", - ), - expErr: "operator '+' incompatible with type 'STRINGSET'", - }, - { - sqls: sqls( - "select d - b from binoptestss_id;", - ), - expErr: "operator '-' incompatible with type 'STRINGSET'", - }, - { - sqls: sqls( - "select d * b from binoptestss_id;", - ), - expErr: "operator '*' incompatible with type 'STRINGSET'", - }, - { - sqls: sqls( - "select d / b from binoptestss_id;", - ), - expErr: "operator '/' incompatible with type 'STRINGSET'", - }, - { - sqls: sqls( - "select d % b from binoptestss_id;", - ), - expErr: "operator '%' incompatible with type 'STRINGSET'", - }, - { - sqls: sqls( - "select d || b from binoptestss_id;", - ), - expErr: "operator '||' incompatible with type 'STRINGSET'", - }, - }, -} - -var binOpExprWithStringSetDecimal = tableTest{ - table: tbl( - "binoptestss_d", - srcHdrs( - srcHdr("_id", fldTypeID), - srcHdr("a", fldTypeStringSet), - srcHdr("d", fldTypeDecimal2), - ), - srcRows( - srcRow(int64(1), []string{"20", "21"}, float64(12.34)), - ), - ), - sqlTests: []sqlTest{ - { - sqls: sqls( - "select a != d from binoptestss_d;", - ), - expErr: "types 'STRINGSET' and 'DECIMAL(2)' are not equatable", - }, - { - sqls: sqls( - "select a = d from binoptestss_d;", - ), - expErr: "types 'STRINGSET' and 'DECIMAL(2)' are not equatable", - }, - { - sqls: sqls( - "select a <= d from binoptestss_d;", - ), - expErr: "operator '<=' incompatible with type 'STRINGSET'", - }, - { - sqls: sqls( - "select a >= d from binoptestss_d;", - ), - expErr: "operator '>=' incompatible with type 'STRINGSET'", - }, - { - sqls: sqls( - "select a < d from binoptestss_d;", - ), - expErr: "operator '<' incompatible with type 'STRINGSET'", - }, - { - sqls: sqls( - "select a > d from binoptestss_d;", - ), - expErr: "operator '>' incompatible with type 'STRINGSET'", - }, - { - sqls: sqls( - "select a & d from binoptestss_d;", - ), - expErr: "operator '&' incompatible with type 'STRINGSET'", - }, - { - sqls: sqls( - "select a | d from binoptestss_d;", - ), - expErr: "operator '|' incompatible with type 'STRINGSET'", - }, - { - sqls: sqls( - "select a << d from binoptestss_d;", - ), - expErr: "operator '<<' incompatible with type 'STRINGSET'", - }, - { - sqls: sqls( - "select a >> d from binoptestss_d;", - ), - expErr: "operator '>>' incompatible with type 'STRINGSET'", - }, - { - sqls: sqls( - "select a + d from binoptestss_d;", - ), - expErr: "operator '+' incompatible with type 'STRINGSET'", - }, - { - sqls: sqls( - "select a - d from binoptestss_d;", - ), - expErr: "operator '-' incompatible with type 'STRINGSET'", - }, - { - sqls: sqls( - "select a * d from binoptestss_d;", - ), - expErr: "operator '*' incompatible with type 'STRINGSET'", - }, - { - sqls: sqls( - "select a / d from binoptestss_d;", - ), - expErr: "operator '/' incompatible with type 'STRINGSET'", - }, - { - sqls: sqls( - "select a % d from binoptestss_d;", - ), - expErr: "operator '%' incompatible with type 'STRINGSET'", - }, - { - sqls: sqls( - "select a || d from binoptestss_d;", - ), - expErr: "operator '||' incompatible with type 'STRINGSET'", - }, - }, -} - -var binOpExprWithStringSetTimestamp = tableTest{ - table: tbl( - "binoptestss_ts", - srcHdrs( - srcHdr("_id", fldTypeID), - srcHdr("a", fldTypeStringSet), - srcHdr("ts", fldTypeTimestamp), - ), - srcRows( - srcRow(int64(1), []string{"20", "21"}, time.Time(knownTimestamp())), - ), - ), - sqlTests: []sqlTest{ - { - sqls: sqls( - "select a != ts from binoptestss_ts;", - ), - expErr: "types 'STRINGSET' and 'TIMESTAMP' are not equatable", - }, - { - sqls: sqls( - "select a = ts from binoptestss_ts;", - ), - expErr: "types 'STRINGSET' and 'TIMESTAMP' are not equatable", - }, - { - sqls: sqls( - "select a <= ts from binoptestss_ts;", - ), - expErr: " operator '<=' incompatible with type 'STRINGSET'", - }, - { - sqls: sqls( - "select a >= ts from binoptestss_ts;", - ), - expErr: " operator '>=' incompatible with type 'STRINGSET'", - }, - { - sqls: sqls( - "select a < ts from binoptestss_ts;", - ), - expErr: " operator '<' incompatible with type 'STRINGSET'", - }, - { - sqls: sqls( - "select a > ts from binoptestss_ts;", - ), - expErr: " operator '>' incompatible with type 'STRINGSET'", - }, - { - sqls: sqls( - "select a & ts from binoptestss_ts;", - ), - expErr: "operator '&' incompatible with type 'STRINGSET'", - }, - { - sqls: sqls( - "select a | ts from binoptestss_ts;", - ), - expErr: "operator '|' incompatible with type 'STRINGSET'", - }, - { - sqls: sqls( - "select a << ts from binoptestss_ts;", - ), - expErr: "operator '<<' incompatible with type 'STRINGSET'", - }, - { - sqls: sqls( - "select a >> ts from binoptestss_ts;", - ), - expErr: "operator '>>' incompatible with type 'STRINGSET'", - }, - { - sqls: sqls( - "select a + ts from binoptestss_ts;", - ), - expErr: "operator '+' incompatible with type 'STRINGSET'", - }, - { - sqls: sqls( - "select a - ts from binoptestss_ts;", - ), - expErr: "operator '-' incompatible with type 'STRINGSET'", - }, - { - sqls: sqls( - "select a * ts from binoptestss_ts;", - ), - expErr: "operator '*' incompatible with type 'STRINGSET'", - }, - { - sqls: sqls( - "select a / ts from binoptestss_ts;", - ), - expErr: "operator '/' incompatible with type 'STRINGSET'", - }, - { - sqls: sqls( - "select a % ts from binoptestss_ts;", - ), - expErr: "operator '%' incompatible with type 'STRINGSET'", - }, - { - sqls: sqls( - "select a || ts from binoptestss_ts;", - ), - expErr: "operator '||' incompatible with type 'STRINGSET'", - }, - }, -} - -var binOpExprWithStringSetIDSet = tableTest{ - table: tbl( - "binoptestss_ids", - srcHdrs( - srcHdr("_id", fldTypeID), - srcHdr("a", fldTypeStringSet), - srcHdr("b", fldTypeIDSet), - ), - srcRows( - srcRow(int64(1), []string{"101", "103"}, []int64{101, 102}), - ), - ), - sqlTests: []sqlTest{ - { - sqls: sqls( - "select a != b from binoptestss_ids;", - ), - expErr: "types 'STRINGSET' and 'IDSET' are not equatable", - }, - { - sqls: sqls( - "select a = b from binoptestss_ids;", - ), - expErr: "types 'STRINGSET' and 'IDSET' are not equatable", - }, - { - sqls: sqls( - "select a <= b from binoptestss_ids;", - ), - expErr: " operator '<=' incompatible with type 'STRINGSET'", - }, - { - sqls: sqls( - "select a >= b from binoptestss_ids;", - ), - expErr: " operator '>=' incompatible with type 'STRINGSET'", - }, - { - sqls: sqls( - "select a < b from binoptestss_ids;", - ), - expErr: " operator '<' incompatible with type 'STRINGSET'", - }, - { - sqls: sqls( - "select a > b from binoptestss_ids;", - ), - expErr: " operator '>' incompatible with type 'STRINGSET'", - }, - { - sqls: sqls( - "select a & b from binoptestss_ids;", - ), - expErr: " operator '&' incompatible with type 'STRINGSET'", - }, - { - sqls: sqls( - "select a | b from binoptestss_ids;", - ), - expErr: " operator '|' incompatible with type 'STRINGSET'", - }, - { - sqls: sqls( - "select a << b from binoptestss_ids;", - ), - expErr: " operator '<<' incompatible with type 'STRINGSET'", - }, - { - sqls: sqls( - "select a >> b from binoptestss_ids;", - ), - expErr: " operator '>>' incompatible with type 'STRINGSET'", - }, - { - sqls: sqls( - "select a + b from binoptestss_ids;", - ), - expErr: " operator '+' incompatible with type 'STRINGSET'", - }, - { - sqls: sqls( - "select a - b from binoptestss_ids;", - ), - expErr: " operator '-' incompatible with type 'STRINGSET'", - }, - { - sqls: sqls( - "select a * b from binoptestss_ids;", - ), - expErr: " operator '*' incompatible with type 'STRINGSET'", - }, - { - sqls: sqls( - "select a / b from binoptestss_ids;", - ), - expErr: " operator '/' incompatible with type 'STRINGSET'", - }, - { - sqls: sqls( - "select a % b from binoptestss_ids;", - ), - expErr: " operator '%' incompatible with type 'STRINGSET'", - }, - { - sqls: sqls( - "select a || b from binoptestss_ids;", - ), - expErr: "operator '||' incompatible with type 'STRINGSET'", - }, - }, -} - -var binOpExprWithStringSetString = tableTest{ - table: tbl( - "binoptestss_s", - srcHdrs( - srcHdr("_id", fldTypeID), - srcHdr("a", fldTypeStringSet), - srcHdr("b", fldTypeString), - ), - srcRows( - srcRow(int64(1), []string{"101", "102"}, string("101")), - ), - ), - sqlTests: []sqlTest{ - { - sqls: sqls( - "select a != b from binoptestss_s;", - ), - expErr: "types 'STRINGSET' and 'STRING' are not equatable", - }, - { - sqls: sqls( - "select a = b from binoptestss_s;", - ), - expErr: "types 'STRINGSET' and 'STRING' are not equatable", - }, - { - sqls: sqls( - "select a <= b from binoptestss_s;", - ), - expErr: " operator '<=' incompatible with type 'STRINGSET'", - }, - { - sqls: sqls( - "select a >= b from binoptestss_s;", - ), - expErr: " operator '>=' incompatible with type 'STRINGSET'", - }, - { - sqls: sqls( - "select a < b from binoptestss_s;", - ), - expErr: " operator '<' incompatible with type 'STRINGSET'", - }, - { - sqls: sqls( - "select a > b from binoptestss_s;", - ), - expErr: " operator '>' incompatible with type 'STRINGSET'", - }, - { - sqls: sqls( - "select a & b from binoptestss_s;", - ), - expErr: " operator '&' incompatible with type 'STRINGSET'", - }, - { - sqls: sqls( - "select a | b from binoptestss_s;", - ), - expErr: " operator '|' incompatible with type 'STRINGSET'", - }, - { - sqls: sqls( - "select a << b from binoptestss_s;", - ), - expErr: " operator '<<' incompatible with type 'STRINGSET'", - }, - { - sqls: sqls( - "select a >> b from binoptestss_s;", - ), - expErr: " operator '>>' incompatible with type 'STRINGSET'", - }, - { - sqls: sqls( - "select a + b from binoptestss_s;", - ), - expErr: " operator '+' incompatible with type 'STRINGSET'", - }, - { - sqls: sqls( - "select a - b from binoptestss_s;", - ), - expErr: " operator '-' incompatible with type 'STRINGSET'", - }, - { - sqls: sqls( - "select a * b from binoptestss_s;", - ), - expErr: " operator '*' incompatible with type 'STRINGSET'", - }, - { - sqls: sqls( - "select a / b from binoptestss_s;", - ), - expErr: " operator '/' incompatible with type 'STRINGSET'", - }, - { - sqls: sqls( - "select a % b from binoptestss_s;", - ), - expErr: " operator '%' incompatible with type 'STRINGSET'", - }, - { - sqls: sqls( - "select a || b from binoptestss_s;", - ), - expErr: "operator '||' incompatible with type 'STRINGSET'", - }, - }, -} - -var binOpExprWithStringSetStringSet = tableTest{ - table: tbl( - "binoptestss_ss", - srcHdrs( - srcHdr("_id", fldTypeID), - srcHdr("a", fldTypeStringSet), - srcHdr("b", fldTypeStringSet), - ), - srcRows( - srcRow(int64(1), []string{"102", "103"}, []string{"101", "102"}), - ), - ), - sqlTests: []sqlTest{ - { - sqls: sqls( - "select a != b from binoptestss_ss;", - ), - expHdrs: hdrs( - hdr("", fldTypeBool), - ), - expRows: rows( - row(bool(true)), - ), - compare: compareExactUnordered, - }, - { - sqls: sqls( - "select a = b from binoptestss_ss;", - ), - expHdrs: hdrs( - hdr("", fldTypeBool), - ), - expRows: rows( - row(bool(false)), - ), - compare: compareExactUnordered, - }, - { - sqls: sqls( - "select a <= b from binoptestss_ss;", - ), - expErr: " operator '<=' incompatible with type 'STRINGSET'", - }, - { - sqls: sqls( - "select a >= b from binoptestss_ss;", - ), - expErr: " operator '>=' incompatible with type 'STRINGSET'", - }, - { - sqls: sqls( - "select a < b from binoptestss_ss;", - ), - expErr: " operator '<' incompatible with type 'STRINGSET'", - }, - { - sqls: sqls( - "select a > b from binoptestss_ss;", - ), - expErr: " operator '>' incompatible with type 'STRINGSET'", - }, - { - sqls: sqls( - "select a & b from binoptestss_ss;", - ), - expErr: " operator '&' incompatible with type 'STRINGSET'", - }, - { - sqls: sqls( - "select a | b from binoptestss_ss;", - ), - expErr: " operator '|' incompatible with type 'STRINGSET'", - }, - { - sqls: sqls( - "select a << b from binoptestss_ss;", - ), - expErr: " operator '<<' incompatible with type 'STRINGSET'", - }, - { - sqls: sqls( - "select a >> b from binoptestss_ss;", - ), - expErr: " operator '>>' incompatible with type 'STRINGSET'", - }, - { - sqls: sqls( - "select a + b from binoptestss_ss;", - ), - expErr: " operator '+' incompatible with type 'STRINGSET'", - }, - { - sqls: sqls( - "select a - b from binoptestss_ss;", - ), - expErr: " operator '-' incompatible with type 'STRINGSET'", - }, - { - sqls: sqls( - "select a * b from binoptestss_ss;", - ), - expErr: " operator '*' incompatible with type 'STRINGSET'", - }, - { - sqls: sqls( - "select a / b from binoptestss_ss;", - ), - expErr: " operator '/' incompatible with type 'STRINGSET'", - }, - { - sqls: sqls( - "select a % b from binoptestss_ss;", - ), - expErr: " operator '%' incompatible with type 'STRINGSET'", - }, - { - sqls: sqls( - "select a || b from binoptestss_ss;", - ), - expErr: "operator '||' incompatible with type 'STRINGSET'", - }, - }, -} diff --git a/sql3/sql_test.go b/sql3/sql_test.go index 429a3861c..f21a2f0c6 100644 --- a/sql3/sql_test.go +++ b/sql3/sql_test.go @@ -5,13 +5,10 @@ import ( "fmt" "log" "sort" - "strings" "testing" - "time" - "github.com/molecula/featurebase/v3/sql3/parser" - planner_types "github.com/molecula/featurebase/v3/sql3/planner/types" sql_test "github.com/molecula/featurebase/v3/sql3/test" + "github.com/molecula/featurebase/v3/sql3/test/defs" "github.com/molecula/featurebase/v3/test" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -23,42 +20,32 @@ func TestSQL_Execute(t *testing.T) { svr := c.GetNode(0).Server - for i, test := range tableTests { - tableTestName := fmt.Sprintf("table-%d", i) - if test.name != "" { - tableTestName = test.name - } else if test.table.name != "" { - tableTestName = test.table.name - } - t.Run(tableTestName, func(t *testing.T) { + for i, test := range defs.TableTests { + t.Run(test.Name(i), func(t *testing.T) { // Create a table with all field types. - if test.table.columns != nil { - _, _, err := sql_test.MustQueryRows(t, svr, test.table.createTable()) + if test.HasTable() { + _, _, err := sql_test.MustQueryRows(t, svr, test.CreateTable()) assert.NoError(t, err) } - if len(test.table.rows) > 0 { + if test.HasTable() && test.HasData() { // Populate fields with data. - _, _, err := sql_test.MustQueryRows(t, svr, test.table.insertInto(t)) + _, _, err := sql_test.MustQueryRows(t, svr, test.InsertInto(t)) assert.NoError(t, err) } - for i, sqltest := range test.sqlTests { - sqlTestName := fmt.Sprintf("test-%d", i) - if sqltest.name != "" { - sqlTestName = sqltest.name - } - t.Run(sqlTestName, func(t *testing.T) { - for _, sql := range sqltest.sqls { + for i, sqltest := range test.SQLTests { + t.Run(sqltest.Name(i), func(t *testing.T) { + for _, sql := range sqltest.SQLs { t.Run(fmt.Sprintf("sql-%s", sql), func(t *testing.T) { log.Printf("SQL: %s", sql) rows, headers, err := sql_test.MustQueryRows(t, svr, sql) // Check expected error instead of results. - if sqltest.expErr != "" { + if sqltest.ExpErr != "" { if assert.Error(t, err) { - assert.Contains(t, err.Error(), sqltest.expErr) + assert.Contains(t, err.Error(), sqltest.ExpErr) } return } @@ -66,7 +53,7 @@ func TestSQL_Execute(t *testing.T) { require.NoError(t, err) // Check headers. - assert.ElementsMatch(t, sqltest.expHdrs, headers) + assert.ElementsMatch(t, sqltest.ExpHdrs, headers) // make a map of column name to header index m := make(map[string]int) @@ -76,30 +63,30 @@ func TestSQL_Execute(t *testing.T) { // Put the expRows in the same column order as the headers returned // by the query. - exp := make([][]interface{}, len(sqltest.expRows)) - for i := range sqltest.expRows { + exp := make([][]interface{}, len(sqltest.ExpRows)) + for i := range sqltest.ExpRows { exp[i] = make([]interface{}, len(headers)) - for j := range sqltest.expHdrs { - targetIdx := m[sqltest.expHdrs[j].ColumnName] - assert.GreaterOrEqual(t, len(sqltest.expRows[i]), len(headers), + for j := range sqltest.ExpHdrs { + targetIdx := m[sqltest.ExpHdrs[j].ColumnName] + assert.GreaterOrEqual(t, len(sqltest.ExpRows[i]), len(headers), "expected row set has fewer columns than returned headers") - exp[i][targetIdx] = sqltest.expRows[i][j] + exp[i][targetIdx] = sqltest.ExpRows[i][j] } } - if sqltest.sortStringKeys { + if sqltest.SortStringKeys { sortStringKeys(rows) } - switch sqltest.compare { - case compareExactOrdered: - assert.Equal(t, len(sqltest.expRows), len(rows)) + switch sqltest.Compare { + case defs.CompareExactOrdered: + assert.Equal(t, len(sqltest.ExpRows), len(rows)) assert.EqualValues(t, exp, rows) - case compareExactUnordered: - assert.Equal(t, len(sqltest.expRows), len(rows)) + case defs.CompareExactUnordered: + assert.Equal(t, len(sqltest.ExpRows), len(rows)) assert.ElementsMatch(t, exp, rows) - case compareIncludedIn: - assert.Equal(t, sqltest.expRowCount, len(rows)) + case defs.CompareIncludedIn: + assert.Equal(t, sqltest.ExpRowCount, len(rows)) for _, row := range rows { assert.Contains(t, exp, row) } @@ -128,195 +115,3 @@ func sortStringKeys(in [][]interface{}) { } } } - -////////////////////////////////////////////////////////////////////// - -type fldType parser.ExprDataType - -// fldType constants are providing a map of a defined test type to the -// parser.ExprDataType -var ( - fldTypeID fldType = parser.NewDataTypeID() - fldTypeBool fldType = parser.NewDataTypeBool() - fldTypeIDSet fldType = parser.NewDataTypeIDSet() - fldTypeInt fldType = parser.NewDataTypeInt() - fldTypeDecimal2 fldType = parser.NewDataTypeDecimal(2) - fldTypeString fldType = parser.NewDataTypeString() - fldTypeStringSet fldType = parser.NewDataTypeStringSet() - fldTypeTimestamp fldType = parser.NewDataTypeTimestamp() -) - -type compareMethod string - -const ( - compareExactOrdered compareMethod = "exactOrdered" - compareExactUnordered compareMethod = "exactUnordered" - compareIncludedIn compareMethod = "includedIn" -) - -type tableTest struct { - name string - table source - sqlTests []sqlTest -} - -type sqlTest struct { - name string - sqls []string - expHdrs []*planner_types.PlannerColumn - expRows [][]interface{} - expErr string - compare compareMethod - sortStringKeys bool - expRowCount int -} - -// The following "source" types are helpers for creating a test table. -type sourceColumn struct { - name string - typ fldType - options string -} - -func tbl(name string, columns []sourceColumn, rows []sourceRow) source { - return source{ - name: name, - columns: columns, - rows: rows, - } -} - -func srcHdrs(hdrs ...sourceColumn) []sourceColumn { - return hdrs -} - -func srcHdr(name string, typ fldType, opts ...string) sourceColumn { - return sourceColumn{ - name: name, - typ: typ, - options: strings.Join(opts, " "), - } -} - -func srcRows(rows ...sourceRow) []sourceRow { - return rows -} -func srcRow(cells ...interface{}) sourceRow { - return cells -} - -type sourceRow []interface{} - -type sourceRows []sourceRow - -// insertTuples returns the list of tuples (as a single string) to use as the -// VALUES value in an INSERT INTO statement. -func (sr sourceRows) insertTuples(t *testing.T) string { - var afterFirstRow bool - var sb strings.Builder - for _, row := range sr { - if afterFirstRow { - sb.WriteString(",") - } - - var afterFirstCell bool - sb.WriteString("(") - - for _, cell := range row { - if afterFirstCell { - sb.WriteString(",") - } - switch v := cell.(type) { - case string: - sb.WriteString("'" + v + "'") - case int64: - sb.WriteString(fmt.Sprintf("%d", v)) - case float64: - sb.WriteString(fmt.Sprintf("%.2f", v)) - case []int64: - strs := make([]string, len(v)) - for i := range v { - strs[i] = fmt.Sprintf("%d", v[i]) - } - sb.WriteString("[" + strings.Join(strs, ",") + "]") - case []string: - if len(v) == 0 { - sb.WriteString("[]") - } else { - sb.WriteString("['" + strings.Join(v, "','") + "']") - } - case bool: - sb.WriteString(fmt.Sprintf("%v", v)) - case nil: - sb.WriteString("null") - case time.Time: - sb.WriteString("'" + v.Format(time.RFC3339) + "'") - - default: - t.Fatalf("unsupported cell type: %T", cell) - } - afterFirstCell = true - } - - sb.WriteString(")") - afterFirstRow = true - } - return sb.String() -} - -type source struct { - name string - columns []sourceColumn - rows []sourceRow -} - -func (s source) createTable() string { - ct := "CREATE TABLE " + s.name + " (" - - cols := []string{} - for _, col := range s.columns { - f := col.name + " " + col.typ.TypeName() - if col.options != "" { - f += " " + col.options - } - cols = append(cols, f) - } - ct += strings.Join(cols, ",") - - ct += `)` - - log.Printf("CREATE: %s", ct) - return ct -} - -func (s source) insertInto(t *testing.T) string { - ii := "INSERT INTO " + s.name + " VALUES " - ii += sourceRows(s.rows).insertTuples(t) - return ii -} - -// hdrs is just a helper function to make the test definition look cleaner. -func hdrs(hdrs ...*planner_types.PlannerColumn) []*planner_types.PlannerColumn { - return hdrs -} - -// hdr is just a helper function to make the test definition look cleaner. -func hdr(name string, typ fldType) *planner_types.PlannerColumn { - return &planner_types.PlannerColumn{ - ColumnName: name, - Type: typ, - } -} - -// row helpers for expected results -func rows(rows ...[]interface{}) [][]interface{} { - return rows -} - -func row(cells ...interface{}) []interface{} { - return cells -} - -func sqls(sqls ...string) []string { - return sqls -} diff --git a/sql3/test/defs/defs.go b/sql3/test/defs/defs.go new file mode 100644 index 000000000..2a7c9e2e0 --- /dev/null +++ b/sql3/test/defs/defs.go @@ -0,0 +1,168 @@ +// Copyright 2021 Molecula Corp. All rights reserved. +package defs + +import ( + "time" +) + +// TableTests is the list of tests which get run by TestSQL_Execute in +// sql_test.go. They're defined here just to keep the test definitions separate +// from the test execution logic. +var TableTests []TableTest = []TableTest{ + minmaxnegatives, + unkeyed, + keyed, + + setLiteralTests, + setFunctionTests, + setParameterTests, + datePartTests, + + insertTest, + keyedInsertTest, + timestampLiterals, + unaryOpExprWithInt, + unaryOpExprWithID, + unaryOpExprWithBool, + unaryOpExprWithDecimal, + unaryOpExprWithTimestamp, + unaryOpExprWithIDSet, + unaryOpExprWithString, + unaryOpExprWithStringSet, + + binOpExprWithIntInt, + binOpExprWithIntBool, + binOpExprWithIntID, + binOpExprWithIntDecimal, + binOpExprWithIntTimestamp, + binOpExprWithIntIDSet, + binOpExprWithIntString, + binOpExprWithIntStringSet, + + binOpExprWithBoolInt, + binOpExprWithBoolBool, + binOpExprWithBoolID, + binOpExprWithBoolDecimal, + binOpExprWithBoolTimestamp, + binOpExprWithBoolIDSet, + binOpExprWithBoolString, + binOpExprWithBoolStringSet, + + binOpExprWithIDInt, + binOpExprWithIDBool, + binOpExprWithIDID, + binOpExprWithIDDecimal, + binOpExprWithIDTimestamp, + binOpExprWithIDIDSet, + binOpExprWithIDString, + binOpExprWithIDStringSet, + + binOpExprWithDecInt, + binOpExprWithDecBool, + binOpExprWithDecID, + binOpExprWithDecDecimal, + binOpExprWithDecTimestamp, + binOpExprWithDecIDSet, + binOpExprWithDecString, + binOpExprWithDecStringSet, + + binOpExprWithTSInt, + binOpExprWithTSBool, + binOpExprWithTSID, + binOpExprWithTSDecimal, + binOpExprWithTSTimestamp, + binOpExprWithTSIDSet, + binOpExprWithTSString, + binOpExprWithTSStringSet, + + binOpExprWithIDSetInt, + binOpExprWithIDSetBool, + binOpExprWithIDSetID, + binOpExprWithIDSetDecimal, + binOpExprWithIDSetTimestamp, + binOpExprWithIDSetIDSet, + binOpExprWithIDSetString, + binOpExprWithIDSetStringSet, + + binOpExprWithStringInt, + binOpExprWithStringBool, + binOpExprWithStringID, + binOpExprWithStringDecimal, + binOpExprWithStringTimestamp, + binOpExprWithStringIDSet, + binOpExprWithStringString, + binOpExprWithStringStringSet, + + binOpExprWithStringSetInt, + binOpExprWithStringSetBool, + binOpExprWithStringSetID, + binOpExprWithStringSetDecimal, + binOpExprWithStringSetTimestamp, + binOpExprWithStringSetIDSet, + binOpExprWithStringSetString, + binOpExprWithStringSetStringSet, + + //cast tests + castIntLiteral, + castInt, + + castBool, + castDecimal, + castID, + castIDSet, + castString, + castStringSet, + castTimestamp, + + //like tests + likeTests, + notLikeTests, + + //null tests + nullTests, + notNullTests, + + //null filter tests + nullFilterTests, + + //between tests + betweenTests, + notBetweenTests, + + //in tests + inTests, + notInTests, + + //aggregate tests + countTests, + countDistinctTests, + sumTests, + avgTests, + percentileTests, + minmaxTests, + + //groupby tests + groupByTests, + + //create table tests + createTable, + + //joins + joinTestsUsers, + joinTestsOrders, + joinTests, + + //bool (batch logic) + boolTests, + + //time quantums + // Skip for now - timeQuantumInsertTest, +} + +func knownTimestamp() time.Time { + tm, err := time.ParseInLocation(time.RFC3339, "2012-11-01T22:08:41+00:00", time.UTC) + if err != nil { + panic(err.Error()) + } + return tm +} diff --git a/sql3/sql_defs_aggregate_test.go b/sql3/test/defs/defs_aggregate.go similarity index 70% rename from sql3/sql_defs_aggregate_test.go rename to sql3/test/defs/defs_aggregate.go index d11910f23..757b1401a 100644 --- a/sql3/sql_defs_aggregate_test.go +++ b/sql3/test/defs/defs_aggregate.go @@ -1,4 +1,4 @@ -package sql3_test +package defs import ( "github.com/molecula/featurebase/v3/pql" @@ -6,8 +6,8 @@ import ( ) // aggregate function tests -var countTests = tableTest{ - table: tbl( +var countTests = TableTest{ + Table: tbl( "count_test", srcHdrs( srcHdr("_id", fldTypeID), @@ -24,134 +24,134 @@ var countTests = tableTest{ srcRow(int64(6), int64(13), float64(13), nil), ), ), - sqlTests: []sqlTest{ + SQLTests: []SQLTest{ { - sqls: sqls( + SQLs: sqls( "SELECT COUNT(i1, d1) AS count_rows FROM count_test", ), - expErr: "count of formal parameters (1) does not match count of actual parameters (2)", + ExpErr: "count of formal parameters (1) does not match count of actual parameters (2)", }, { - sqls: sqls( + SQLs: sqls( "SELECT COUNT(1) AS count_rows FROM count_test", ), - expErr: "column reference expected", + ExpErr: "column reference expected", }, { - sqls: sqls( + SQLs: sqls( "SELECT COUNT(*) AS count_rows FROM count_test", "SELECT COUNT(_id) AS count_rows FROM count_test", ), - expHdrs: hdrs( + ExpHdrs: hdrs( hdr("count_rows", fldTypeInt), ), - expRows: rows( + ExpRows: rows( row(int64(6)), ), - compare: compareExactUnordered, + Compare: CompareExactUnordered, }, { - sqls: sqls( + SQLs: sqls( "SELECT COUNT(i1) as a, COUNT(i2) as b FROM count_test", ), - expHdrs: hdrs( + ExpHdrs: hdrs( hdr("a", fldTypeInt), hdr("b", fldTypeInt), ), - expRows: rows( + ExpRows: rows( row(int64(6), int64(2)), ), - compare: compareExactUnordered, + Compare: CompareExactUnordered, }, { - sqls: sqls( + SQLs: sqls( "SELECT COUNT(*) + 10 - 11 * 2 AS count_rows FROM count_test", ), - expHdrs: hdrs( + ExpHdrs: hdrs( hdr("count_rows", fldTypeInt), ), - expRows: rows( + ExpRows: rows( row(int64(-6)), ), - compare: compareExactUnordered, + Compare: CompareExactUnordered, }, { - sqls: sqls( + SQLs: sqls( "SELECT COUNT(*) AS count_rows FROM count_test WHERE i1 = 10", ), - expHdrs: hdrs( + ExpHdrs: hdrs( hdr("count_rows", fldTypeInt), ), - expRows: rows( + ExpRows: rows( row(int64(2)), ), - compare: compareExactUnordered, + Compare: CompareExactUnordered, }, { - sqls: sqls( + SQLs: sqls( "SELECT COUNT(*) AS count_rows FROM count_test WHERE i1 != 10", ), - expHdrs: hdrs( + ExpHdrs: hdrs( hdr("count_rows", fldTypeInt), ), - expRows: rows( + ExpRows: rows( row(int64(4)), ), - compare: compareExactUnordered, + Compare: CompareExactUnordered, }, { - sqls: sqls( + SQLs: sqls( "SELECT COUNT(*) AS count_rows FROM count_test WHERE i1 < 12", ), - expHdrs: hdrs( + ExpHdrs: hdrs( hdr("count_rows", fldTypeInt), ), - expRows: rows( + ExpRows: rows( row(int64(3)), ), - compare: compareExactUnordered, + Compare: CompareExactUnordered, }, { - sqls: sqls( + SQLs: sqls( "SELECT COUNT(*) AS count_rows FROM count_test WHERE i1 > 12", ), - expHdrs: hdrs( + ExpHdrs: hdrs( hdr("count_rows", fldTypeInt), ), - expRows: rows( + ExpRows: rows( row(int64(1)), ), - compare: compareExactUnordered, + Compare: CompareExactUnordered, }, { - sqls: sqls( + SQLs: sqls( "SELECT COUNT(*) AS count_rows FROM count_test WHERE i1 = 10 AND i2 = 100", ), - expHdrs: hdrs( + ExpHdrs: hdrs( hdr("count_rows", fldTypeInt), ), - expRows: rows( + ExpRows: rows( row(int64(1)), ), - compare: compareExactUnordered, + Compare: CompareExactUnordered, }, { - sqls: sqls( + SQLs: sqls( "SELECT COUNT(*) AS count_rows FROM count_test WHERE i1 = 10 OR i1 = 200 OR i1 = 12", ), - expHdrs: hdrs( + ExpHdrs: hdrs( hdr("count_rows", fldTypeInt), ), - expRows: rows( + ExpRows: rows( row(int64(4)), ), - compare: compareExactUnordered, + Compare: CompareExactUnordered, }, }, } -var countDistinctTests = tableTest{ - table: tbl( +var countDistinctTests = TableTest{ + Table: tbl( "count_d_test", srcHdrs( srcHdr("_id", fldTypeID), @@ -167,49 +167,49 @@ var countDistinctTests = tableTest{ srcRow(int64(6), int64(13), nil), ), ), - sqlTests: []sqlTest{ + SQLTests: []SQLTest{ { - sqls: sqls( + SQLs: sqls( "SELECT COUNT(distinct i1) AS count_rows FROM count_d_test", ), - expHdrs: hdrs( + ExpHdrs: hdrs( hdr("count_rows", fldTypeInt), ), - expRows: rows( + ExpRows: rows( row(int64(4)), ), - compare: compareExactUnordered, + Compare: CompareExactUnordered, }, { - sqls: sqls( + SQLs: sqls( "SELECT COUNT(distinct i1) AS count_rows FROM count_d_test where i1 > 11", ), - expHdrs: hdrs( + ExpHdrs: hdrs( hdr("count_rows", fldTypeInt), ), - expRows: rows( + ExpRows: rows( row(int64(2)), ), - compare: compareExactUnordered, + Compare: CompareExactUnordered, }, { - sqls: sqls( + SQLs: sqls( "SELECT COUNT(distinct i1) AS count_rows, sum(i1) as sum_rows FROM count_d_test where i1 > 11", ), - expHdrs: hdrs( + ExpHdrs: hdrs( hdr("count_rows", fldTypeInt), hdr("sum_rows", fldTypeInt), ), - expRows: rows( + ExpRows: rows( row(int64(2), int64(37)), ), - compare: compareExactUnordered, + Compare: CompareExactUnordered, }, }, } -var sumTests = tableTest{ - table: tbl( +var sumTests = TableTest{ + Table: tbl( "sum_test", srcHdrs( srcHdr("_id", fldTypeID), @@ -227,60 +227,60 @@ var sumTests = tableTest{ srcRow(int64(6), int64(13), float64(13), nil, string("foo")), ), ), - sqlTests: []sqlTest{ + SQLTests: []SQLTest{ { - sqls: sqls( + SQLs: sqls( "SELECT sum(*) AS sum_rows FROM sum_test", ), - expErr: "column reference expected", + ExpErr: "column reference expected", }, { - sqls: sqls( + SQLs: sqls( "SELECT sum(_id) AS sum_rows FROM sum_test", ), - expErr: "_id column cannot be used in aggregate function 'sum'", + ExpErr: "_id column cannot be used in aggregate function 'sum'", }, { - sqls: sqls( + SQLs: sqls( "SELECT sum(1) AS sum_rows FROM sum_test", ), - expErr: "column reference expected", + ExpErr: "column reference expected", }, { - sqls: sqls( + SQLs: sqls( "SELECT sum(i1, d1) AS sum_rows FROM sum_test", ), - expErr: "count of formal parameters (1) does not match count of actual parameters (2)", + ExpErr: "count of formal parameters (1) does not match count of actual parameters (2)", }, { - sqls: sqls( + SQLs: sqls( "SELECT sum(i1) AS sum_rows FROM sum_test", ), - expHdrs: hdrs( + ExpHdrs: hdrs( hdr("sum_rows", fldTypeInt), ), - expRows: rows( + ExpRows: rows( row(int64(68)), ), - compare: compareExactUnordered, + Compare: CompareExactUnordered, }, { - sqls: sqls( + SQLs: sqls( "SELECT sum(d1) AS sum_rows FROM sum_test", ), - expHdrs: hdrs( + ExpHdrs: hdrs( hdr("sum_rows", fldTypeDecimal2), ), - expRows: rows( + ExpRows: rows( row(pql.NewDecimal(6800, 2)), ), - compare: compareExactUnordered, + Compare: CompareExactUnordered, }, }, } -var avgTests = tableTest{ - table: tbl( +var avgTests = TableTest{ + Table: tbl( "avg_test", srcHdrs( srcHdr("_id", fldTypeID), @@ -297,49 +297,49 @@ var avgTests = tableTest{ srcRow(int64(6), int64(13), float64(13), string("foo")), ), ), - sqlTests: []sqlTest{ + SQLTests: []SQLTest{ { - sqls: sqls( + SQLs: sqls( "SELECT avg(*) AS avg_rows FROM avg_test", ), - expErr: "column reference expected", + ExpErr: "column reference expected", }, { - sqls: sqls( + SQLs: sqls( "SELECT avg(_id) AS avg_rows FROM avg_test", ), - expErr: "_id column cannot be used in aggregate function 'avg'", + ExpErr: "_id column cannot be used in aggregate function 'avg'", }, { - sqls: sqls( + SQLs: sqls( "SELECT avg(i1, d1) AS avg_rows FROM avg_test", ), - expErr: "count of formal parameters (1) does not match count of actual parameters (2)", + ExpErr: "count of formal parameters (1) does not match count of actual parameters (2)", }, { - sqls: sqls( + SQLs: sqls( "SELECT avg(s1) AS avg_rows FROM avg_test", ), - expErr: "integer or decimal expression expected", + ExpErr: "integer or decimal expression expected", }, { - sqls: sqls( + SQLs: sqls( "SELECT avg(i1) AS avg_rows FROM avg_test", "SELECT avg(d1) AS avg_rows FROM avg_test", ), - expHdrs: hdrs( + ExpHdrs: hdrs( hdr("avg_rows", parser.NewDataTypeDecimal(4)), ), - expRows: rows( + ExpRows: rows( row(pql.NewDecimal(113333, 4)), ), - compare: compareExactUnordered, + Compare: CompareExactUnordered, }, }, } -var percentileTests = tableTest{ - table: tbl( +var percentileTests = TableTest{ + Table: tbl( "percentile_test", srcHdrs( srcHdr("_id", fldTypeID), @@ -356,66 +356,66 @@ var percentileTests = tableTest{ srcRow(int64(6), int64(13), float64(13), string("foo")), ), ), - sqlTests: []sqlTest{ + SQLTests: []SQLTest{ { - sqls: sqls( + SQLs: sqls( "SELECT percentile(*) AS avg_rows FROM percentile_test", ), - expErr: "column reference expected", + ExpErr: "column reference expected", }, { - sqls: sqls( + SQLs: sqls( "SELECT percentile(10, i1) AS avg_rows FROM percentile_test", ), - expErr: "column reference expected", + ExpErr: "column reference expected", }, { - sqls: sqls( + SQLs: sqls( "SELECT percentile(_id, 50) AS avg_rows FROM percentile_test", ), - expErr: "_id column cannot be used in aggregate function 'percentile'", + ExpErr: "_id column cannot be used in aggregate function 'percentile'", }, { - sqls: sqls( + SQLs: sqls( "SELECT percentile(i1, d1) AS avg_rows FROM percentile_test", ), - expErr: "literal expression expected", + ExpErr: "literal expression expected", }, { - sqls: sqls( + SQLs: sqls( "SELECT percentile(s1, 50) AS avg_rows FROM percentile_test", ), - expErr: "integer, decimal or timestamp expression expected", + ExpErr: "integer, decimal or timestamp expression expected", }, { - sqls: sqls( + SQLs: sqls( "SELECT percentile(i1, 50) AS p_rows FROM percentile_test", ), - expHdrs: hdrs( + ExpHdrs: hdrs( hdr("p_rows", fldTypeInt), ), - expRows: rows( + ExpRows: rows( row(int64(12)), ), - compare: compareExactUnordered, + Compare: CompareExactUnordered, }, { - sqls: sqls( + SQLs: sqls( "SELECT percentile(d1, 50) AS p_rows FROM percentile_test", ), - expHdrs: hdrs( + ExpHdrs: hdrs( hdr("p_rows", fldTypeDecimal2), ), - expRows: rows( + ExpRows: rows( row(pql.NewDecimal(1000, 2)), ), - compare: compareExactUnordered, + Compare: CompareExactUnordered, }, }, } -var minmaxTests = tableTest{ - table: tbl( +var minmaxTests = TableTest{ + Table: tbl( "minmax_test", srcHdrs( srcHdr("_id", fldTypeID), @@ -432,89 +432,89 @@ var minmaxTests = tableTest{ srcRow(int64(6), int64(13), float64(13), string("foo")), ), ), - sqlTests: []sqlTest{ + SQLTests: []SQLTest{ { - sqls: sqls( + SQLs: sqls( "SELECT min(*) AS p_rows FROM minmax_test", "SELECT max(*) AS p_rows FROM minmax_test", ), - expErr: "column reference expected", + ExpErr: "column reference expected", }, { - sqls: sqls( + SQLs: sqls( "SELECT min(i1, d1) AS p_rows FROM minmax_test", "SELECT max(i1, d1) AS p_rows FROM minmax_test", ), - expErr: "count of formal parameters (1) does not match count of actual parameters (2)", + ExpErr: "count of formal parameters (1) does not match count of actual parameters (2)", }, { - sqls: sqls( + SQLs: sqls( "SELECT min(1) AS p_rows FROM minmax_test", "SELECT max(1) AS p_rows FROM minmax_test", ), - expErr: "column reference expected", + ExpErr: "column reference expected", }, { - sqls: sqls( + SQLs: sqls( "SELECT min(_id) AS p_rows FROM minmax_test", "SELECT max(_id) AS p_rows FROM minmax_test", ), - expErr: "_id column cannot be used in aggregate function", + ExpErr: "_id column cannot be used in aggregate function", }, { - sqls: sqls( + SQLs: sqls( "SELECT min(s1) AS p_rows FROM minmax_test", "SELECT max(s1) AS p_rows FROM minmax_test", ), - expErr: "integer, decimal or timestamp expression expected", + ExpErr: "integer, decimal or timestamp expression expected", }, { - sqls: sqls( + SQLs: sqls( "SELECT min(i1) AS p_rows FROM minmax_test", ), - expHdrs: hdrs( + ExpHdrs: hdrs( hdr("p_rows", fldTypeInt), ), - expRows: rows( + ExpRows: rows( row(int64(10)), ), - compare: compareExactUnordered, + Compare: CompareExactUnordered, }, { - sqls: sqls( + SQLs: sqls( "SELECT max(i1) AS p_rows FROM minmax_test", ), - expHdrs: hdrs( + ExpHdrs: hdrs( hdr("p_rows", fldTypeInt), ), - expRows: rows( + ExpRows: rows( row(int64(13)), ), - compare: compareExactUnordered, + Compare: CompareExactUnordered, }, { - sqls: sqls( + SQLs: sqls( "SELECT min(d1) AS p_rows FROM minmax_test", ), - expHdrs: hdrs( + ExpHdrs: hdrs( hdr("p_rows", fldTypeDecimal2), ), - expRows: rows( + ExpRows: rows( row(pql.NewDecimal(1000, 2)), ), - compare: compareExactUnordered, + Compare: CompareExactUnordered, }, { - sqls: sqls( + SQLs: sqls( "SELECT max(d1) AS p_rows FROM minmax_test", ), - expHdrs: hdrs( + ExpHdrs: hdrs( hdr("p_rows", fldTypeDecimal2), ), - expRows: rows( + ExpRows: rows( row(pql.NewDecimal(1300, 2)), ), - compare: compareExactUnordered, + Compare: CompareExactUnordered, }, }, } diff --git a/sql3/sql_defs_between_test.go b/sql3/test/defs/defs_between.go similarity index 66% rename from sql3/sql_defs_between_test.go rename to sql3/test/defs/defs_between.go index 2f63fcff0..059a68de7 100644 --- a/sql3/sql_defs_between_test.go +++ b/sql3/test/defs/defs_between.go @@ -1,8 +1,8 @@ -package sql3_test +package defs // BETWEEN tests -var betweenTests = tableTest{ - table: tbl( +var betweenTests = TableTest{ + Table: tbl( "between_all_types", srcHdrs( srcHdr("_id", fldTypeID), @@ -19,91 +19,91 @@ var betweenTests = tableTest{ srcRow(int64(1), int64(1000), bool(true), float64(12.34), int64(20), []int64{101, 102}, string("foo"), []string{"101", "102"}, knownTimestamp()), ), ), - sqlTests: []sqlTest{ + SQLTests: []SQLTest{ { - sqls: sqls( + SQLs: sqls( "select _id between 1 and 10 from between_all_types", ), - expHdrs: hdrs( + ExpHdrs: hdrs( hdr("", fldTypeBool), ), - expRows: rows( + ExpRows: rows( row(bool(true)), ), - compare: compareExactUnordered, + Compare: CompareExactUnordered, }, { - sqls: sqls( + SQLs: sqls( "select i1 between 1 and 10 from between_all_types", ), - expHdrs: hdrs( + ExpHdrs: hdrs( hdr("", fldTypeBool), ), - expRows: rows( + ExpRows: rows( row(bool(false)), ), - compare: compareExactUnordered, + Compare: CompareExactUnordered, }, { - sqls: sqls( + SQLs: sqls( "select b1 between true and false from between_all_types", ), - expErr: "type 'BOOL' cannot be used a range subscript", + ExpErr: "type 'BOOL' cannot be used a range subscript", }, { - sqls: sqls( + SQLs: sqls( "select d1 between 1.23 and 4.56 from between_all_types", ), - expErr: "type 'DECIMAL(2)' cannot be used a range subscript", + ExpErr: "type 'DECIMAL(2)' cannot be used a range subscript", }, { - sqls: sqls( + SQLs: sqls( "select id1 between 3 and 7 from between_all_types", ), - expHdrs: hdrs( + ExpHdrs: hdrs( hdr("", fldTypeBool), ), - expRows: rows( + ExpRows: rows( row(bool(false)), ), - compare: compareExactUnordered, + Compare: CompareExactUnordered, }, { - sqls: sqls( + SQLs: sqls( "select ids1 between [100, 102] and [456, 789] from between_all_types", ), - expErr: "type 'IDSET' cannot be used a range subscript", + ExpErr: "type 'IDSET' cannot be used a range subscript", }, { - sqls: sqls( + SQLs: sqls( "select s1 between 'foo' and 'bar' from between_all_types", ), - expErr: "type 'STRING' cannot be used a range subscript", + ExpErr: "type 'STRING' cannot be used a range subscript", }, { - sqls: sqls( + SQLs: sqls( "select ss1 between ['a', 'b'] and ['c', 'd'] from between_all_types", ), - expErr: "type 'STRINGSET' cannot be used a range subscript", + ExpErr: "type 'STRINGSET' cannot be used a range subscript", }, { - sqls: sqls( + SQLs: sqls( "select t1 between '2010-11-01T22:08:41+00:00' and '2013-11-01T22:08:41+00:00' from between_all_types", ), - expHdrs: hdrs( + ExpHdrs: hdrs( hdr("", fldTypeBool), ), - expRows: rows( + ExpRows: rows( row(bool(true)), ), - compare: compareExactUnordered, + Compare: CompareExactUnordered, }, }, } // NOT BETWEEN tests -var notBetweenTests = tableTest{ - table: tbl( +var notBetweenTests = TableTest{ + Table: tbl( "not_between_all_types", srcHdrs( srcHdr("_id", fldTypeID), @@ -120,84 +120,84 @@ var notBetweenTests = tableTest{ srcRow(int64(1), int64(1000), bool(true), float64(12.34), int64(20), []int64{101, 102}, string("foo"), []string{"101", "102"}, knownTimestamp()), ), ), - sqlTests: []sqlTest{ + SQLTests: []SQLTest{ { - sqls: sqls( + SQLs: sqls( "select _id not between 1 and 10 from not_between_all_types", ), - expHdrs: hdrs( + ExpHdrs: hdrs( hdr("", fldTypeBool), ), - expRows: rows( + ExpRows: rows( row(bool(false)), ), - compare: compareExactUnordered, + Compare: CompareExactUnordered, }, { - sqls: sqls( + SQLs: sqls( "select i1 not between 1 and 10 from not_between_all_types", ), - expHdrs: hdrs( + ExpHdrs: hdrs( hdr("", fldTypeBool), ), - expRows: rows( + ExpRows: rows( row(bool(true)), ), - compare: compareExactUnordered, + Compare: CompareExactUnordered, }, { - sqls: sqls( + SQLs: sqls( "select b1 not between true and false from not_between_all_types", ), - expErr: "type 'BOOL' cannot be used a range subscript", + ExpErr: "type 'BOOL' cannot be used a range subscript", }, { - sqls: sqls( + SQLs: sqls( "select d1 not between 1.23 and 4.56 from not_between_all_types", ), - expErr: "type 'DECIMAL(2)' cannot be used a range subscript", + ExpErr: "type 'DECIMAL(2)' cannot be used a range subscript", }, { - sqls: sqls( + SQLs: sqls( "select id1 between 3 and 7 from not_between_all_types", ), - expHdrs: hdrs( + ExpHdrs: hdrs( hdr("", fldTypeBool), ), - expRows: rows( + ExpRows: rows( row(bool(false)), ), - compare: compareExactUnordered, + Compare: CompareExactUnordered, }, { - sqls: sqls( + SQLs: sqls( "select ids1 not between [100, 102] and [456, 789] from not_between_all_types", ), - expErr: "type 'IDSET' cannot be used a range subscript", + ExpErr: "type 'IDSET' cannot be used a range subscript", }, { - sqls: sqls( + SQLs: sqls( "select s1 not between 'foo' and 'bar' from not_between_all_types", ), - expErr: "type 'STRING' cannot be used a range subscript", + ExpErr: "type 'STRING' cannot be used a range subscript", }, { - sqls: sqls( + SQLs: sqls( "select ss1 not between ['a', 'b'] and ['c', 'd'] from not_between_all_types", ), - expErr: "type 'STRINGSET' cannot be used a range subscript", + ExpErr: "type 'STRINGSET' cannot be used a range subscript", }, { - sqls: sqls( + SQLs: sqls( "select t1 not between '2010-11-01T22:08:41+00:00' and '2013-11-01T22:08:41+00:00' from not_between_all_types", ), - expHdrs: hdrs( + ExpHdrs: hdrs( hdr("", fldTypeBool), ), - expRows: rows( + ExpRows: rows( row(bool(false)), ), - compare: compareExactUnordered, + Compare: CompareExactUnordered, }, }, } diff --git a/sql3/test/defs/defs_binops.go b/sql3/test/defs/defs_binops.go new file mode 100644 index 000000000..91eb1f84c --- /dev/null +++ b/sql3/test/defs/defs_binops.go @@ -0,0 +1,7923 @@ +package defs + +import ( + "time" + + "github.com/molecula/featurebase/v3/pql" +) + +// INT bin op tests +var binOpExprWithIntInt = TableTest{ + Table: tbl( + "binoptesti_i", + srcHdrs( + srcHdr("_id", fldTypeID), + srcHdr("a", fldTypeInt, "min 0", "max 1000"), + srcHdr("b", fldTypeInt, "min 0", "max 1000"), + ), + srcRows( + srcRow(int64(1), int64(10), int64(20)), + ), + ), + SQLTests: []SQLTest{ + { + SQLs: sqls( + "select a != b from binoptesti_i;", + ), + ExpHdrs: hdrs( + hdr("", fldTypeBool), + ), + ExpRows: rows( + row(bool(true)), + ), + Compare: CompareExactUnordered, + }, + { + SQLs: sqls( + "select a = b from binoptesti_i;", + ), + ExpHdrs: hdrs( + hdr("", fldTypeBool), + ), + ExpRows: rows( + row(bool(false)), + ), + Compare: CompareExactUnordered, + }, + { + SQLs: sqls( + "select a <= b from binoptesti_i;", + ), + ExpHdrs: hdrs( + hdr("", fldTypeBool), + ), + ExpRows: rows( + row(bool(true)), + ), + Compare: CompareExactUnordered, + }, + { + SQLs: sqls( + "select a >= b from binoptesti_i;", + ), + ExpHdrs: hdrs( + hdr("", fldTypeBool), + ), + ExpRows: rows( + row(bool(false)), + ), + Compare: CompareExactUnordered, + }, + { + SQLs: sqls( + "select a < b from binoptesti_i;", + ), + ExpHdrs: hdrs( + hdr("", fldTypeBool), + ), + ExpRows: rows( + row(bool(true)), + ), + Compare: CompareExactUnordered, + }, + { + SQLs: sqls( + "select a > b from binoptesti_i;", + ), + ExpHdrs: hdrs( + hdr("", fldTypeBool), + ), + ExpRows: rows( + row(bool(false)), + ), + Compare: CompareExactUnordered, + }, + { + SQLs: sqls( + "select a & b from binoptesti_i;", + ), + ExpHdrs: hdrs( + hdr("", fldTypeInt), + ), + ExpRows: rows( + row(int64(0)), + ), + Compare: CompareExactUnordered, + }, + { + SQLs: sqls( + "select a | b from binoptesti_i;", + ), + ExpHdrs: hdrs( + hdr("", fldTypeInt), + ), + ExpRows: rows( + row(int64(30)), + ), + Compare: CompareExactUnordered, + }, + { + SQLs: sqls( + "select a << b from binoptesti_i;", + ), + ExpHdrs: hdrs( + hdr("", fldTypeInt), + ), + ExpRows: rows( + row(int64(10485760)), + ), + Compare: CompareExactUnordered, + }, + { + SQLs: sqls( + "select a >> b from binoptesti_i;", + ), + ExpHdrs: hdrs( + hdr("", fldTypeInt), + ), + ExpRows: rows( + row(int64(0)), + ), + Compare: CompareExactUnordered, + }, + { + SQLs: sqls( + "select a + b from binoptesti_i;", + ), + ExpHdrs: hdrs( + hdr("", fldTypeInt), + ), + ExpRows: rows( + row(int64(30)), + ), + Compare: CompareExactUnordered, + }, + { + SQLs: sqls( + "select a - b from binoptesti_i;", + ), + ExpHdrs: hdrs( + hdr("", fldTypeInt), + ), + ExpRows: rows( + row(int64(-10)), + ), + Compare: CompareExactUnordered, + }, + { + SQLs: sqls( + "select a * b from binoptesti_i;", + ), + ExpHdrs: hdrs( + hdr("", fldTypeInt), + ), + ExpRows: rows( + row(int64(200)), + ), + Compare: CompareExactUnordered, + }, + { + SQLs: sqls( + "select a / b from binoptesti_i;", + ), + ExpHdrs: hdrs( + hdr("", fldTypeInt), + ), + ExpRows: rows( + row(int64(0)), + ), + Compare: CompareExactUnordered, + }, + { + SQLs: sqls( + "select a % b from binoptesti_i;", + ), + ExpHdrs: hdrs( + hdr("", fldTypeInt), + ), + ExpRows: rows( + row(int64(10)), + ), + Compare: CompareExactUnordered, + }, + { + SQLs: sqls( + "select a || b from binoptesti_i;", + ), + ExpErr: "operator '||' incompatible with type 'INT'", + }, + }, +} + +var binOpExprWithIntBool = TableTest{ + Table: tbl( + "binoptesti_b", + srcHdrs( + srcHdr("_id", fldTypeID), + srcHdr("a", fldTypeInt, "min 0", "max 1000"), + srcHdr("b", fldTypeBool), + ), + srcRows( + srcRow(int64(1), int64(10), bool(true)), + ), + ), + SQLTests: []SQLTest{ + { + SQLs: sqls( + "select a != b from binoptesti_b;", + ), + ExpErr: "types 'INT' and 'BOOL' are not equatable", + }, + { + SQLs: sqls( + "select a = b from binoptesti_b;", + ), + ExpErr: "types 'INT' and 'BOOL' are not equatable", + }, + { + SQLs: sqls( + "select a <= b from binoptesti_b;", + ), + ExpErr: "operator '<=' incompatible with type 'BOOL'", + }, + { + SQLs: sqls( + "select a >= b from binoptesti_b;", + ), + ExpErr: "operator '>=' incompatible with type 'BOOL'", + }, + { + SQLs: sqls( + "select a < b from binoptesti_b;", + ), + ExpErr: "operator '<' incompatible with type 'BOOL'", + }, + { + SQLs: sqls( + "select a > b from binoptesti_b;", + ), + ExpErr: "operator '>' incompatible with type 'BOOL'", + }, + { + SQLs: sqls( + "select a & b from binoptesti_b;", + ), + ExpErr: "operator '&' incompatible with type 'BOOL'", + }, + { + SQLs: sqls( + "select a | b from binoptesti_b;", + ), + ExpErr: "operator '|' incompatible with type 'BOOL'", + }, + { + SQLs: sqls( + "select a << b from binoptesti_b;", + ), + ExpErr: "operator '<<' incompatible with type 'BOOL'", + }, + { + SQLs: sqls( + "select a >> b from binoptesti_b;", + ), + ExpErr: "operator '>>' incompatible with type 'BOOL'", + }, + { + SQLs: sqls( + "select a + b from binoptesti_b;", + ), + ExpErr: "operator '+' incompatible with type 'BOOL'", + }, + { + SQLs: sqls( + "select a - b from binoptesti_b;", + ), + ExpErr: "operator '-' incompatible with type 'BOOL'", + }, + { + SQLs: sqls( + "select a * b from binoptesti_b;", + ), + ExpErr: "operator '*' incompatible with type 'BOOL'", + }, + { + SQLs: sqls( + "select a / b from binoptesti_b;", + ), + ExpErr: "operator '/' incompatible with type 'BOOL'", + }, + { + SQLs: sqls( + "select a % b from binoptesti_b;", + ), + ExpErr: "operator '%' incompatible with type 'BOOL'", + }, + { + SQLs: sqls( + "select a || b from binoptesti_b;", + ), + ExpErr: "operator '||' incompatible with type 'INT'", + }, + }, +} + +var binOpExprWithIntID = TableTest{ + Table: tbl( + "binoptesti_id", + srcHdrs( + srcHdr("_id", fldTypeID), + srcHdr("b", fldTypeInt, "min 0", "max 1000"), + ), + srcRows( + srcRow(int64(10), int64(20)), + ), + ), + SQLTests: []SQLTest{ + { + SQLs: sqls( + "select b != _id from binoptesti_id;", + ), + ExpHdrs: hdrs( + hdr("", fldTypeBool), + ), + ExpRows: rows( + row(bool(true)), + ), + Compare: CompareExactUnordered, + }, + { + SQLs: sqls( + "select b = _id from binoptesti_id;", + ), + ExpHdrs: hdrs( + hdr("", fldTypeBool), + ), + ExpRows: rows( + row(bool(false)), + ), + Compare: CompareExactUnordered, + }, + { + SQLs: sqls( + "select b <= _id from binoptesti_id;", + ), + ExpHdrs: hdrs( + hdr("", fldTypeBool), + ), + ExpRows: rows( + row(bool(false)), + ), + Compare: CompareExactUnordered, + }, + { + SQLs: sqls( + "select b >= _id from binoptesti_id;", + ), + ExpHdrs: hdrs( + hdr("", fldTypeBool), + ), + ExpRows: rows( + row(bool(true)), + ), + Compare: CompareExactUnordered, + }, + { + SQLs: sqls( + "select b < _id from binoptesti_id;", + ), + ExpHdrs: hdrs( + hdr("", fldTypeBool), + ), + ExpRows: rows( + row(bool(false)), + ), + Compare: CompareExactUnordered, + }, + { + SQLs: sqls( + "select b > _id from binoptesti_id;", + ), + ExpHdrs: hdrs( + hdr("", fldTypeBool), + ), + ExpRows: rows( + row(bool(true)), + ), + Compare: CompareExactUnordered, + }, + { + SQLs: sqls( + "select b & _id from binoptesti_id;", + ), + ExpHdrs: hdrs( + hdr("", fldTypeInt), + ), + ExpRows: rows( + row(int64(0)), + ), + Compare: CompareExactUnordered, + }, + { + SQLs: sqls( + "select b | _id from binoptesti_id;", + ), + ExpHdrs: hdrs( + hdr("", fldTypeInt), + ), + ExpRows: rows( + row(int64(30)), + ), + Compare: CompareExactUnordered, + }, + { + SQLs: sqls( + "select b << _id from binoptesti_id;", + ), + ExpHdrs: hdrs( + hdr("", fldTypeInt), + ), + ExpRows: rows( + row(int64(20480)), + ), + Compare: CompareExactUnordered, + }, + { + SQLs: sqls( + "select b >> _id from binoptesti_id;", + ), + ExpHdrs: hdrs( + hdr("", fldTypeInt), + ), + ExpRows: rows( + row(int64(0)), + ), + Compare: CompareExactUnordered, + }, + { + SQLs: sqls( + "select b + _id from binoptesti_id;", + ), + ExpHdrs: hdrs( + hdr("", fldTypeInt), + ), + ExpRows: rows( + row(int64(30)), + ), + Compare: CompareExactUnordered, + }, + { + SQLs: sqls( + "select b - _id from binoptesti_id;", + ), + ExpHdrs: hdrs( + hdr("", fldTypeInt), + ), + ExpRows: rows( + row(int64(10)), + ), + Compare: CompareExactUnordered, + }, + { + SQLs: sqls( + "select b * _id from binoptesti_id;", + ), + ExpHdrs: hdrs( + hdr("", fldTypeInt), + ), + ExpRows: rows( + row(int64(200)), + ), + Compare: CompareExactUnordered, + }, + { + SQLs: sqls( + "select b / _id from binoptesti_id;", + ), + ExpHdrs: hdrs( + hdr("", fldTypeInt), + ), + ExpRows: rows( + row(int64(2)), + ), + Compare: CompareExactUnordered, + }, + { + SQLs: sqls( + "select b % _id from binoptesti_id;", + ), + ExpHdrs: hdrs( + hdr("", fldTypeInt), + ), + ExpRows: rows( + row(int64(0)), + ), + Compare: CompareExactUnordered, + }, + { + SQLs: sqls( + "select b || _id from binoptesti_id;", + ), + ExpErr: "operator '||' incompatible with type 'INT'", + }, + }, +} + +var binOpExprWithIntDecimal = TableTest{ + Table: tbl( + "binoptesti_d", + srcHdrs( + srcHdr("_id", fldTypeID), + srcHdr("a", fldTypeInt, "min 0", "max 1000"), + srcHdr("d", fldTypeDecimal2), + ), + srcRows( + srcRow(int64(1), int64(20), float64(12.34)), + ), + ), + SQLTests: []SQLTest{ + { + SQLs: sqls( + "select a != d from binoptesti_d;", + ), + ExpHdrs: hdrs( + hdr("", fldTypeBool), + ), + ExpRows: rows( + row(bool(true)), + ), + Compare: CompareExactUnordered, + }, + { + SQLs: sqls( + "select a = d from binoptesti_d;", + ), + ExpHdrs: hdrs( + hdr("", fldTypeBool), + ), + ExpRows: rows( + row(bool(false)), + ), + Compare: CompareExactUnordered, + }, + { + SQLs: sqls( + "select a <= d from binoptesti_d;", + ), + ExpHdrs: hdrs( + hdr("", fldTypeBool), + ), + ExpRows: rows( + row(bool(false)), + ), + Compare: CompareExactUnordered, + }, + { + SQLs: sqls( + "select a >= d from binoptesti_d;", + ), + ExpHdrs: hdrs( + hdr("", fldTypeBool), + ), + ExpRows: rows( + row(bool(true)), + ), + Compare: CompareExactUnordered, + }, + { + SQLs: sqls( + "select a < d from binoptesti_d;", + ), + ExpHdrs: hdrs( + hdr("", fldTypeBool), + ), + ExpRows: rows( + row(bool(false)), + ), + Compare: CompareExactUnordered, + }, + { + SQLs: sqls( + "select a > d from binoptesti_d;", + ), + ExpHdrs: hdrs( + hdr("", fldTypeBool), + ), + ExpRows: rows( + row(bool(true)), + ), + Compare: CompareExactUnordered, + }, + { + SQLs: sqls( + "select a & d from binoptesti_d;", + ), + ExpErr: "operator '&' incompatible with type 'DECIMAL(2)'", + }, + { + SQLs: sqls( + "select a | d from binoptesti_d;", + ), + ExpErr: "operator '|' incompatible with type 'DECIMAL(2)'", + }, + { + SQLs: sqls( + "select a << d from binoptesti_d;", + ), + ExpErr: "operator '<<' incompatible with type 'DECIMAL(2)'", + }, + { + SQLs: sqls( + "select a >> d from binoptesti_d;", + ), + ExpErr: "operator '>>' incompatible with type 'DECIMAL(2)'", + }, + { + SQLs: sqls( + "select a + d from binoptesti_d;", + ), + ExpHdrs: hdrs( + hdr("", fldTypeDecimal2), + ), + ExpRows: rows( + row(pql.NewDecimal(3234, 2)), + ), + Compare: CompareExactUnordered, + }, + { + SQLs: sqls( + "select a - d from binoptesti_d;", + ), + ExpHdrs: hdrs( + hdr("", fldTypeDecimal2), + ), + ExpRows: rows( + row(pql.NewDecimal(766, 2)), + ), + Compare: CompareExactUnordered, + }, + { + SQLs: sqls( + "select a * d from binoptesti_d;", + ), + ExpHdrs: hdrs( + hdr("", fldTypeDecimal2), + ), + ExpRows: rows( + row(pql.NewDecimal(24680, 2)), + ), + Compare: CompareExactUnordered, + }, + { + SQLs: sqls( + "select a / d from binoptesti_d;", + ), + ExpHdrs: hdrs( + hdr("", fldTypeDecimal2), + ), + ExpRows: rows( + row(pql.NewDecimal(162, 2)), + ), + Compare: CompareExactUnordered, + }, + { + SQLs: sqls( + "select a % d from binoptesti_d;", + ), + ExpErr: "operator '%' incompatible with type 'DECIMAL(2)'", + }, + { + SQLs: sqls( + "select a || d from binoptesti_d;", + ), + ExpErr: "operator '||' incompatible with type 'INT'", + }, + }, +} + +var binOpExprWithIntTimestamp = TableTest{ + Table: tbl( + "binoptesti_ts", + srcHdrs( + srcHdr("_id", fldTypeID), + srcHdr("a", fldTypeInt, "min 0", "max 1000"), + srcHdr("ts", fldTypeTimestamp), + ), + srcRows( + srcRow(int64(1), int64(20), time.Time(knownTimestamp())), + ), + ), + SQLTests: []SQLTest{ + { + SQLs: sqls( + "select a != ts from binoptesti_ts;", + ), + ExpErr: "types 'INT' and 'TIMESTAMP' are not equatable", + }, + { + SQLs: sqls( + "select a = ts from binoptesti_ts;", + ), + ExpErr: "types 'INT' and 'TIMESTAMP' are not equatable", + }, + { + SQLs: sqls( + "select a <= ts from binoptesti_ts;", + ), + ExpErr: "types 'INT' and 'TIMESTAMP' are not equatable", + }, + { + SQLs: sqls( + "select a >= ts from binoptesti_ts;", + ), + ExpErr: "types 'INT' and 'TIMESTAMP' are not equatable", + }, + { + SQLs: sqls( + "select a < ts from binoptesti_ts;", + ), + ExpErr: "types 'INT' and 'TIMESTAMP' are not equatable", + }, + { + SQLs: sqls( + "select a > ts from binoptesti_ts;", + ), + ExpErr: "types 'INT' and 'TIMESTAMP' are not equatable", + }, + { + SQLs: sqls( + "select a & ts from binoptesti_ts;", + ), + ExpErr: "operator '&' incompatible with type 'TIMESTAMP'", + }, + { + SQLs: sqls( + "select a | ts from binoptesti_ts;", + ), + ExpErr: "operator '|' incompatible with type 'TIMESTAMP'", + }, + { + SQLs: sqls( + "select a << ts from binoptesti_ts;", + ), + ExpErr: "operator '<<' incompatible with type 'TIMESTAMP'", + }, + { + SQLs: sqls( + "select a >> ts from binoptesti_ts;", + ), + ExpErr: "operator '>>' incompatible with type 'TIMESTAMP'", + }, + { + SQLs: sqls( + "select a + ts from binoptesti_ts;", + ), + ExpErr: "operator '+' incompatible with type 'TIMESTAMP'", + }, + { + SQLs: sqls( + "select a - ts from binoptesti_ts;", + ), + ExpErr: "operator '-' incompatible with type 'TIMESTAMP'", + }, + { + SQLs: sqls( + "select a * ts from binoptesti_ts;", + ), + ExpErr: "operator '*' incompatible with type 'TIMESTAMP'", + }, + { + SQLs: sqls( + "select a / ts from binoptesti_ts;", + ), + ExpErr: "operator '/' incompatible with type 'TIMESTAMP'", + }, + { + SQLs: sqls( + "select a % ts from binoptesti_ts;", + ), + ExpErr: "operator '%' incompatible with type 'TIMESTAMP'", + }, + { + SQLs: sqls( + "select a || ts from binoptesti_ts;", + ), + ExpErr: "operator '||' incompatible with type 'INT'", + }, + }, +} + +var binOpExprWithIntIDSet = TableTest{ + Table: tbl( + "binoptesti_ids", + srcHdrs( + srcHdr("_id", fldTypeID), + srcHdr("a", fldTypeInt, "min 0", "max 1000"), + srcHdr("b", fldTypeIDSet), + ), + srcRows( + srcRow(int64(1), int64(20), []int64{101, 102}), + ), + ), + SQLTests: []SQLTest{ + { + SQLs: sqls( + "select a != b from binoptesti_ids;", + ), + ExpErr: "types 'INT' and 'IDSET' are not equatable", + }, + { + SQLs: sqls( + "select a = b from binoptesti_ids;", + ), + ExpErr: "types 'INT' and 'IDSET' are not equatable", + }, + { + SQLs: sqls( + "select a <= b from binoptesti_ids;", + ), + ExpErr: " operator '<=' incompatible with type 'IDSET'", + }, + { + SQLs: sqls( + "select a >= b from binoptesti_ids;", + ), + ExpErr: " operator '>=' incompatible with type 'IDSET'", + }, + { + SQLs: sqls( + "select a < b from binoptesti_ids;", + ), + ExpErr: " operator '<' incompatible with type 'IDSET'", + }, + { + SQLs: sqls( + "select a > b from binoptesti_ids;", + ), + ExpErr: " operator '>' incompatible with type 'IDSET'", + }, + { + SQLs: sqls( + "select a & b from binoptesti_ids;", + ), + ExpErr: " operator '&' incompatible with type 'IDSET'", + }, + { + SQLs: sqls( + "select a | b from binoptesti_ids;", + ), + ExpErr: " operator '|' incompatible with type 'IDSET'", + }, + { + SQLs: sqls( + "select a << b from binoptesti_ids;", + ), + ExpErr: " operator '<<' incompatible with type 'IDSET'", + }, + { + SQLs: sqls( + "select a >> b from binoptesti_ids;", + ), + ExpErr: " operator '>>' incompatible with type 'IDSET'", + }, + { + SQLs: sqls( + "select a + b from binoptesti_ids;", + ), + ExpErr: " operator '+' incompatible with type 'IDSET'", + }, + { + SQLs: sqls( + "select a - b from binoptesti_ids;", + ), + ExpErr: " operator '-' incompatible with type 'IDSET'", + }, + { + SQLs: sqls( + "select a * b from binoptesti_ids;", + ), + ExpErr: " operator '*' incompatible with type 'IDSET'", + }, + { + SQLs: sqls( + "select a / b from binoptesti_ids;", + ), + ExpErr: " operator '/' incompatible with type 'IDSET'", + }, + { + SQLs: sqls( + "select a % b from binoptesti_ids;", + ), + ExpErr: " operator '%' incompatible with type 'IDSET'", + }, + { + SQLs: sqls( + "select a || b from binoptesti_ids;", + ), + ExpErr: "operator '||' incompatible with type 'INT'", + }, + }, +} + +var binOpExprWithIntString = TableTest{ + Table: tbl( + "binoptesti_s", + srcHdrs( + srcHdr("_id", fldTypeID), + srcHdr("a", fldTypeInt, "min 0", "max 1000"), + srcHdr("b", fldTypeString), + ), + srcRows( + srcRow(int64(1), int64(20), string("101")), + ), + ), + SQLTests: []SQLTest{ + { + SQLs: sqls( + "select a != b from binoptesti_s;", + ), + ExpErr: "types 'INT' and 'STRING' are not equatable", + }, + { + SQLs: sqls( + "select a = b from binoptesti_s;", + ), + ExpErr: "types 'INT' and 'STRING' are not equatable", + }, + { + SQLs: sqls( + "select a <= b from binoptesti_s;", + ), + ExpErr: " operator '<=' incompatible with type 'STRING'", + }, + { + SQLs: sqls( + "select a >= b from binoptesti_s;", + ), + ExpErr: " operator '>=' incompatible with type 'STRING'", + }, + { + SQLs: sqls( + "select a < b from binoptesti_s;", + ), + ExpErr: " operator '<' incompatible with type 'STRING'", + }, + { + SQLs: sqls( + "select a > b from binoptesti_s;", + ), + ExpErr: " operator '>' incompatible with type 'STRING'", + }, + { + SQLs: sqls( + "select a & b from binoptesti_s;", + ), + ExpErr: " operator '&' incompatible with type 'STRING'", + }, + { + SQLs: sqls( + "select a | b from binoptesti_s;", + ), + ExpErr: " operator '|' incompatible with type 'STRING'", + }, + { + SQLs: sqls( + "select a << b from binoptesti_s;", + ), + ExpErr: " operator '<<' incompatible with type 'STRING'", + }, + { + SQLs: sqls( + "select a >> b from binoptesti_s;", + ), + ExpErr: " operator '>>' incompatible with type 'STRING'", + }, + { + SQLs: sqls( + "select a + b from binoptesti_s;", + ), + ExpErr: " operator '+' incompatible with type 'STRING'", + }, + { + SQLs: sqls( + "select a - b from binoptesti_s;", + ), + ExpErr: " operator '-' incompatible with type 'STRING'", + }, + { + SQLs: sqls( + "select a * b from binoptesti_s;", + ), + ExpErr: " operator '*' incompatible with type 'STRING'", + }, + { + SQLs: sqls( + "select a / b from binoptesti_s;", + ), + ExpErr: " operator '/' incompatible with type 'STRING'", + }, + { + SQLs: sqls( + "select a % b from binoptesti_s;", + ), + ExpErr: " operator '%' incompatible with type 'STRING'", + }, + { + SQLs: sqls( + "select a || b from binoptesti_s;", + ), + ExpErr: "operator '||' incompatible with type 'INT'", + }, + }, +} + +var binOpExprWithIntStringSet = TableTest{ + Table: tbl( + "binoptesti_ss", + srcHdrs( + srcHdr("_id", fldTypeID), + srcHdr("a", fldTypeInt, "min 0", "max 1000"), + srcHdr("b", fldTypeStringSet), + ), + srcRows( + srcRow(int64(1), int64(20), []string{"101", "102"}), + ), + ), + SQLTests: []SQLTest{ + { + SQLs: sqls( + "select a != b from binoptesti_ss;", + ), + ExpErr: "types 'INT' and 'STRINGSET' are not equatable", + }, + { + SQLs: sqls( + "select a = b from binoptesti_ss;", + ), + ExpErr: "types 'INT' and 'STRINGSET' are not equatable", + }, + { + SQLs: sqls( + "select a <= b from binoptesti_ss;", + ), + ExpErr: " operator '<=' incompatible with type 'STRINGSET'", + }, + { + SQLs: sqls( + "select a >= b from binoptesti_ss;", + ), + ExpErr: " operator '>=' incompatible with type 'STRINGSET'", + }, + { + SQLs: sqls( + "select a < b from binoptesti_ss;", + ), + ExpErr: " operator '<' incompatible with type 'STRINGSET'", + }, + { + SQLs: sqls( + "select a > b from binoptesti_ss;", + ), + ExpErr: " operator '>' incompatible with type 'STRINGSET'", + }, + { + SQLs: sqls( + "select a & b from binoptesti_ss;", + ), + ExpErr: " operator '&' incompatible with type 'STRINGSET'", + }, + { + SQLs: sqls( + "select a | b from binoptesti_ss;", + ), + ExpErr: " operator '|' incompatible with type 'STRINGSET'", + }, + { + SQLs: sqls( + "select a << b from binoptesti_ss;", + ), + ExpErr: " operator '<<' incompatible with type 'STRINGSET'", + }, + { + SQLs: sqls( + "select a >> b from binoptesti_ss;", + ), + ExpErr: " operator '>>' incompatible with type 'STRINGSET'", + }, + { + SQLs: sqls( + "select a + b from binoptesti_ss;", + ), + ExpErr: " operator '+' incompatible with type 'STRINGSET'", + }, + { + SQLs: sqls( + "select a - b from binoptesti_ss;", + ), + ExpErr: " operator '-' incompatible with type 'STRINGSET'", + }, + { + SQLs: sqls( + "select a * b from binoptesti_ss;", + ), + ExpErr: " operator '*' incompatible with type 'STRINGSET'", + }, + { + SQLs: sqls( + "select a / b from binoptesti_ss;", + ), + ExpErr: " operator '/' incompatible with type 'STRINGSET'", + }, + { + SQLs: sqls( + "select a % b from binoptesti_ss;", + ), + ExpErr: " operator '%' incompatible with type 'STRINGSET'", + }, + { + SQLs: sqls( + "select a || b from binoptesti_ss;", + ), + ExpErr: "operator '||' incompatible with type 'INT'", + }, + }, +} + +// BOOL bin op tests +var binOpExprWithBoolInt = TableTest{ + Table: tbl( + "binoptestb_i", + srcHdrs( + srcHdr("_id", fldTypeID), + srcHdr("a", fldTypeBool), + srcHdr("b", fldTypeInt, "min 0", "max 1000"), + ), + srcRows( + srcRow(int64(1), bool(true), int64(20)), + ), + ), + SQLTests: []SQLTest{ + { + SQLs: sqls( + "select a != b from binoptestb_i;", + ), + ExpErr: "types 'BOOL' and 'INT' are not equatable", + }, + { + SQLs: sqls( + "select a = b from binoptestb_i;", + ), + ExpErr: "types 'BOOL' and 'INT' are not equatable", + }, + { + SQLs: sqls( + "select a <= b from binoptestb_i;", + ), + ExpErr: "operator '<=' incompatible with type 'BOOL'", + }, + { + SQLs: sqls( + "select a >= b from binoptestb_i;", + ), + ExpErr: "operator '>=' incompatible with type 'BOOL'", + }, + { + SQLs: sqls( + "select a < b from binoptestb_i;", + ), + ExpErr: "operator '<' incompatible with type 'BOOL'", + }, + { + SQLs: sqls( + "select a > b from binoptestb_i;", + ), + ExpErr: "operator '>' incompatible with type 'BOOL'", + }, + { + SQLs: sqls( + "select a & b from binoptestb_i;", + ), + ExpErr: "operator '&' incompatible with type 'BOOL'", + }, + { + SQLs: sqls( + "select a | b from binoptestb_i;", + ), + ExpErr: "operator '|' incompatible with type 'BOOL'", + }, + { + SQLs: sqls( + "select a << b from binoptestb_i;", + ), + ExpErr: "operator '<<' incompatible with type 'BOOL'", + }, + { + SQLs: sqls( + "select a >> b from binoptestb_i;", + ), + ExpErr: "operator '>>' incompatible with type 'BOOL'", + }, + { + SQLs: sqls( + "select a + b from binoptestb_i;", + ), + ExpErr: "operator '+' incompatible with type 'BOOL'", + }, + { + SQLs: sqls( + "select a - b from binoptestb_i;", + ), + ExpErr: "operator '-' incompatible with type 'BOOL'", + }, + { + SQLs: sqls( + "select a * b from binoptestb_i;", + ), + ExpErr: "operator '*' incompatible with type 'BOOL'", + }, + { + SQLs: sqls( + "select a / b from binoptestb_i;", + ), + ExpErr: "operator '/' incompatible with type 'BOOL'", + }, + { + SQLs: sqls( + "select a % b from binoptestb_i;", + ), + ExpErr: "operator '%' incompatible with type 'BOOL'", + }, + { + SQLs: sqls( + "select a || b from binoptestb_i;", + ), + ExpErr: "operator '||' incompatible with type 'BOOL'", + }, + }, +} + +var binOpExprWithBoolBool = TableTest{ + Table: tbl( + "binoptestb_b", + srcHdrs( + srcHdr("_id", fldTypeID), + srcHdr("a", fldTypeBool), + srcHdr("b", fldTypeBool), + ), + srcRows( + srcRow(int64(1), bool(true), bool(true)), + ), + ), + SQLTests: []SQLTest{ + { + SQLs: sqls( + "select a != b from binoptestb_b;", + ), + ExpHdrs: hdrs( + hdr("", fldTypeBool), + ), + ExpRows: rows( + row(bool(false)), + ), + Compare: CompareExactUnordered, + }, + { + SQLs: sqls( + "select a = b from binoptestb_b;", + ), + ExpHdrs: hdrs( + hdr("", fldTypeBool), + ), + ExpRows: rows( + row(bool(true)), + ), + Compare: CompareExactUnordered, + }, + { + SQLs: sqls( + "select a <= b from binoptestb_b;", + ), + ExpErr: "operator '<=' incompatible with type 'BOOL'", + }, + { + SQLs: sqls( + "select a >= b from binoptestb_b;", + ), + ExpErr: "operator '>=' incompatible with type 'BOOL'", + }, + { + SQLs: sqls( + "select a < b from binoptestb_b;", + ), + ExpErr: "operator '<' incompatible with type 'BOOL'", + }, + { + SQLs: sqls( + "select a > b from binoptestb_b;", + ), + ExpErr: "operator '>' incompatible with type 'BOOL'", + }, + { + SQLs: sqls( + "select a & b from binoptestb_b;", + ), + ExpErr: "operator '&' incompatible with type 'BOOL'", + }, + { + SQLs: sqls( + "select a | b from binoptestb_b;", + ), + ExpErr: "operator '|' incompatible with type 'BOOL'", + }, + { + SQLs: sqls( + "select a << b from binoptestb_b;", + ), + ExpErr: "operator '<<' incompatible with type 'BOOL'", + }, + { + SQLs: sqls( + "select a >> b from binoptestb_b;", + ), + ExpErr: "operator '>>' incompatible with type 'BOOL'", + }, + { + SQLs: sqls( + "select a + b from binoptestb_b;", + ), + ExpErr: "operator '+' incompatible with type 'BOOL'", + }, + { + SQLs: sqls( + "select a - b from binoptestb_b;", + ), + ExpErr: "operator '-' incompatible with type 'BOOL'", + }, + { + SQLs: sqls( + "select a * b from binoptestb_b;", + ), + ExpErr: "operator '*' incompatible with type 'BOOL'", + }, + { + SQLs: sqls( + "select a / b from binoptestb_b;", + ), + ExpErr: "operator '/' incompatible with type 'BOOL'", + }, + { + SQLs: sqls( + "select a % b from binoptestb_b;", + ), + ExpErr: "operator '%' incompatible with type 'BOOL'", + }, + { + SQLs: sqls( + "select a || b from binoptestb_b;", + ), + ExpErr: "operator '||' incompatible with type 'BOOL'", + }, + }, +} + +var binOpExprWithBoolID = TableTest{ + Table: tbl( + "binoptestb_id", + srcHdrs( + srcHdr("_id", fldTypeID), + srcHdr("b", fldTypeBool), + ), + srcRows( + srcRow(int64(10), bool(true)), + ), + ), + SQLTests: []SQLTest{ + { + SQLs: sqls( + "select b != _id from binoptestb_id;", + ), + ExpErr: "types 'BOOL' and 'ID' are not equatable", + }, + { + SQLs: sqls( + "select b = _id from binoptestb_id;", + ), + ExpErr: "types 'BOOL' and 'ID' are not equatable", + }, + { + SQLs: sqls( + "select b <= _id from binoptestb_id;", + ), + ExpErr: "operator '<=' incompatible with type 'BOOL'", + }, + { + SQLs: sqls( + "select b >= _id from binoptestb_id;", + ), + ExpErr: "operator '>=' incompatible with type 'BOOL'", + }, + { + SQLs: sqls( + "select b < _id from binoptestb_id;", + ), + ExpErr: "operator '<' incompatible with type 'BOOL'", + }, + { + SQLs: sqls( + "select b > _id from binoptestb_id;", + ), + ExpErr: "operator '>' incompatible with type 'BOOL'", + }, + { + SQLs: sqls( + "select b & _id from binoptestb_id;", + ), + ExpErr: "operator '&' incompatible with type 'BOOL'", + }, + { + SQLs: sqls( + "select b | _id from binoptestb_id;", + ), + ExpErr: "operator '|' incompatible with type 'BOOL'", + }, + { + SQLs: sqls( + "select b << _id from binoptestb_id;", + ), + ExpErr: "operator '<<' incompatible with type 'BOOL'", + }, + { + SQLs: sqls( + "select b >> _id from binoptestb_id;", + ), + ExpErr: "operator '>>' incompatible with type 'BOOL'", + }, + { + SQLs: sqls( + "select b + _id from binoptestb_id;", + ), + ExpErr: "operator '+' incompatible with type 'BOOL'", + }, + { + SQLs: sqls( + "select b - _id from binoptestb_id;", + ), + ExpErr: "operator '-' incompatible with type 'BOOL'", + }, + { + SQLs: sqls( + "select b * _id from binoptestb_id;", + ), + ExpErr: "operator '*' incompatible with type 'BOOL'", + }, + { + SQLs: sqls( + "select b / _id from binoptestb_id;", + ), + ExpErr: "operator '/' incompatible with type 'BOOL'", + }, + { + SQLs: sqls( + "select b % _id from binoptestb_id;", + ), + ExpErr: "operator '%' incompatible with type 'BOOL'", + }, + { + SQLs: sqls( + "select b || _id from binoptestb_id;", + ), + ExpErr: "operator '||' incompatible with type 'BOOL'", + }, + }, +} + +var binOpExprWithBoolDecimal = TableTest{ + Table: tbl( + "binoptestb_d", + srcHdrs( + srcHdr("_id", fldTypeID), + srcHdr("a", fldTypeBool), + srcHdr("d", fldTypeDecimal2), + ), + srcRows( + srcRow(int64(1), bool(true), float64(12.34)), + ), + ), + SQLTests: []SQLTest{ + { + SQLs: sqls( + "select a != d from binoptestb_d;", + ), + ExpErr: "types 'BOOL' and 'DECIMAL(2)' are not equatable", + }, + { + SQLs: sqls( + "select a = d from binoptestb_d;", + ), + ExpErr: "types 'BOOL' and 'DECIMAL(2)' are not equatable", + }, + { + SQLs: sqls( + "select a <= d from binoptestb_d;", + ), + ExpErr: "operator '<=' incompatible with type 'BOOL'", + }, + { + SQLs: sqls( + "select a >= d from binoptestb_d;", + ), + ExpErr: "operator '>=' incompatible with type 'BOOL'", + }, + { + SQLs: sqls( + "select a < d from binoptestb_d;", + ), + ExpErr: "operator '<' incompatible with type 'BOOL'", + }, + { + SQLs: sqls( + "select a > d from binoptestb_d;", + ), + ExpErr: "operator '>' incompatible with type 'BOOL'", + }, + { + SQLs: sqls( + "select a & d from binoptestb_d;", + ), + ExpErr: "operator '&' incompatible with type 'BOOL'", + }, + { + SQLs: sqls( + "select a | d from binoptestb_d;", + ), + ExpErr: "operator '|' incompatible with type 'BOOL'", + }, + { + SQLs: sqls( + "select a << d from binoptestb_d;", + ), + ExpErr: "operator '<<' incompatible with type 'BOOL'", + }, + { + SQLs: sqls( + "select a >> d from binoptestb_d;", + ), + ExpErr: "operator '>>' incompatible with type 'BOOL'", + }, + { + SQLs: sqls( + "select a + d from binoptestb_d;", + ), + ExpErr: "operator '+' incompatible with type 'BOOL'", + }, + { + SQLs: sqls( + "select a - d from binoptestb_d;", + ), + ExpErr: "operator '-' incompatible with type 'BOOL'", + }, + { + SQLs: sqls( + "select a * d from binoptestb_d;", + ), + ExpErr: "operator '*' incompatible with type 'BOOL'", + }, + { + SQLs: sqls( + "select a / d from binoptestb_d;", + ), + ExpErr: "operator '/' incompatible with type 'BOOL'", + }, + { + SQLs: sqls( + "select a % d from binoptestb_d;", + ), + ExpErr: "operator '%' incompatible with type 'BOOL'", + }, + { + SQLs: sqls( + "select a || d from binoptestb_d;", + ), + ExpErr: "operator '||' incompatible with type 'BOOL'", + }, + }, +} + +var binOpExprWithBoolTimestamp = TableTest{ + Table: tbl( + "binoptestb_ts", + srcHdrs( + srcHdr("_id", fldTypeID), + srcHdr("a", fldTypeBool), + srcHdr("ts", fldTypeTimestamp), + ), + srcRows( + srcRow(int64(1), bool(true), time.Time(knownTimestamp())), + ), + ), + SQLTests: []SQLTest{ + { + SQLs: sqls( + "select a != ts from binoptestb_ts;", + ), + ExpErr: "types 'BOOL' and 'TIMESTAMP' are not equatable", + }, + { + SQLs: sqls( + "select a = ts from binoptestb_ts;", + ), + ExpErr: "types 'BOOL' and 'TIMESTAMP' are not equatable", + }, + { + SQLs: sqls( + "select a <= ts from binoptestb_ts;", + ), + ExpErr: "operator '<=' incompatible with type 'BOOL'", + }, + { + SQLs: sqls( + "select a >= ts from binoptestb_ts;", + ), + ExpErr: "operator '>=' incompatible with type 'BOOL'", + }, + { + SQLs: sqls( + "select a < ts from binoptestb_ts;", + ), + ExpErr: "operator '<' incompatible with type 'BOOL'", + }, + { + SQLs: sqls( + "select a > ts from binoptestb_ts;", + ), + ExpErr: "operator '>' incompatible with type 'BOOL'", + }, + { + SQLs: sqls( + "select a & ts from binoptestb_ts;", + ), + ExpErr: "operator '&' incompatible with type 'BOOL'", + }, + { + SQLs: sqls( + "select a | ts from binoptestb_ts;", + ), + ExpErr: "operator '|' incompatible with type 'BOOL'", + }, + { + SQLs: sqls( + "select a << ts from binoptestb_ts;", + ), + ExpErr: "operator '<<' incompatible with type 'BOOL'", + }, + { + SQLs: sqls( + "select a >> ts from binoptestb_ts;", + ), + ExpErr: "operator '>>' incompatible with type 'BOOL'", + }, + { + SQLs: sqls( + "select a + ts from binoptestb_ts;", + ), + ExpErr: "operator '+' incompatible with type 'BOOL'", + }, + { + SQLs: sqls( + "select a - ts from binoptestb_ts;", + ), + ExpErr: "operator '-' incompatible with type 'BOOL'", + }, + { + SQLs: sqls( + "select a * ts from binoptestb_ts;", + ), + ExpErr: "operator '*' incompatible with type 'BOOL'", + }, + { + SQLs: sqls( + "select a / ts from binoptestb_ts;", + ), + ExpErr: "operator '/' incompatible with type 'BOOL'", + }, + { + SQLs: sqls( + "select a % ts from binoptestb_ts;", + ), + ExpErr: "operator '%' incompatible with type 'BOOL'", + }, + { + SQLs: sqls( + "select a || ts from binoptestb_ts;", + ), + ExpErr: "operator '||' incompatible with type 'BOOL'", + }, + }, +} + +var binOpExprWithBoolIDSet = TableTest{ + Table: tbl( + "binoptestb_ids", + srcHdrs( + srcHdr("_id", fldTypeID), + srcHdr("a", fldTypeBool), + srcHdr("b", fldTypeIDSet), + ), + srcRows( + srcRow(int64(1), bool(true), []int64{101, 102}), + ), + ), + SQLTests: []SQLTest{ + { + SQLs: sqls( + "select a != b from binoptestb_ids;", + ), + ExpErr: "types 'BOOL' and 'IDSET' are not equatable", + }, + { + SQLs: sqls( + "select a = b from binoptestb_ids;", + ), + ExpErr: "types 'BOOL' and 'IDSET' are not equatable", + }, + { + SQLs: sqls( + "select a <= b from binoptestb_ids;", + ), + ExpErr: " operator '<=' incompatible with type 'BOOL'", + }, + { + SQLs: sqls( + "select a >= b from binoptestb_ids;", + ), + ExpErr: " operator '>=' incompatible with type 'BOOL'", + }, + { + SQLs: sqls( + "select a < b from binoptestb_ids;", + ), + ExpErr: " operator '<' incompatible with type 'BOOL'", + }, + { + SQLs: sqls( + "select a > b from binoptestb_ids;", + ), + ExpErr: " operator '>' incompatible with type 'BOOL'", + }, + { + SQLs: sqls( + "select a & b from binoptestb_ids;", + ), + ExpErr: " operator '&' incompatible with type 'BOOL'", + }, + { + SQLs: sqls( + "select a | b from binoptestb_ids;", + ), + ExpErr: " operator '|' incompatible with type 'BOOL'", + }, + { + SQLs: sqls( + "select a << b from binoptestb_ids;", + ), + ExpErr: " operator '<<' incompatible with type 'BOOL'", + }, + { + SQLs: sqls( + "select a >> b from binoptestb_ids;", + ), + ExpErr: " operator '>>' incompatible with type 'BOOL'", + }, + { + SQLs: sqls( + "select a + b from binoptestb_ids;", + ), + ExpErr: " operator '+' incompatible with type 'BOOL'", + }, + { + SQLs: sqls( + "select a - b from binoptestb_ids;", + ), + ExpErr: " operator '-' incompatible with type 'BOOL'", + }, + { + SQLs: sqls( + "select a * b from binoptestb_ids;", + ), + ExpErr: " operator '*' incompatible with type 'BOOL'", + }, + { + SQLs: sqls( + "select a / b from binoptestb_ids;", + ), + ExpErr: " operator '/' incompatible with type 'BOOL'", + }, + { + SQLs: sqls( + "select a % b from binoptestb_ids;", + ), + ExpErr: " operator '%' incompatible with type 'BOOL'", + }, + { + SQLs: sqls( + "select a || b from binoptestb_ids;", + ), + ExpErr: "operator '||' incompatible with type 'BOOL'", + }, + }, +} + +var binOpExprWithBoolString = TableTest{ + Table: tbl( + "binoptestb_s", + srcHdrs( + srcHdr("_id", fldTypeID), + srcHdr("a", fldTypeBool), + srcHdr("b", fldTypeString), + ), + srcRows( + srcRow(int64(1), bool(true), string("101")), + ), + ), + SQLTests: []SQLTest{ + { + SQLs: sqls( + "select a != b from binoptestb_s;", + ), + ExpErr: "types 'BOOL' and 'STRING' are not equatable", + }, + { + SQLs: sqls( + "select a = b from binoptestb_s;", + ), + ExpErr: "types 'BOOL' and 'STRING' are not equatable", + }, + { + SQLs: sqls( + "select a <= b from binoptestb_s;", + ), + ExpErr: " operator '<=' incompatible with type 'BOOL'", + }, + { + SQLs: sqls( + "select a >= b from binoptestb_s;", + ), + ExpErr: " operator '>=' incompatible with type 'BOOL'", + }, + { + SQLs: sqls( + "select a < b from binoptestb_s;", + ), + ExpErr: " operator '<' incompatible with type 'BOOL'", + }, + { + SQLs: sqls( + "select a > b from binoptestb_s;", + ), + ExpErr: " operator '>' incompatible with type 'BOOL'", + }, + { + SQLs: sqls( + "select a & b from binoptestb_s;", + ), + ExpErr: " operator '&' incompatible with type 'BOOL'", + }, + { + SQLs: sqls( + "select a | b from binoptestb_s;", + ), + ExpErr: " operator '|' incompatible with type 'BOOL'", + }, + { + SQLs: sqls( + "select a << b from binoptestb_s;", + ), + ExpErr: " operator '<<' incompatible with type 'BOOL'", + }, + { + SQLs: sqls( + "select a >> b from binoptestb_s;", + ), + ExpErr: " operator '>>' incompatible with type 'BOOL'", + }, + { + SQLs: sqls( + "select a + b from binoptestb_s;", + ), + ExpErr: " operator '+' incompatible with type 'BOOL'", + }, + { + SQLs: sqls( + "select a - b from binoptestb_s;", + ), + ExpErr: " operator '-' incompatible with type 'BOOL'", + }, + { + SQLs: sqls( + "select a * b from binoptestb_s;", + ), + ExpErr: " operator '*' incompatible with type 'BOOL'", + }, + { + SQLs: sqls( + "select a / b from binoptestb_s;", + ), + ExpErr: " operator '/' incompatible with type 'BOOL'", + }, + { + SQLs: sqls( + "select a % b from binoptestb_s;", + ), + ExpErr: " operator '%' incompatible with type 'BOOL'", + }, + { + SQLs: sqls( + "select a || b from binoptestb_s;", + ), + ExpErr: "operator '||' incompatible with type 'BOOL'", + }, + }, +} + +var binOpExprWithBoolStringSet = TableTest{ + Table: tbl( + "binoptestb_ss", + srcHdrs( + srcHdr("_id", fldTypeID), + srcHdr("a", fldTypeBool), + srcHdr("b", fldTypeStringSet), + ), + srcRows( + srcRow(int64(1), bool(true), []string{"101", "102"}), + ), + ), + SQLTests: []SQLTest{ + { + SQLs: sqls( + "select a != b from binoptestb_ss;", + ), + ExpErr: "types 'BOOL' and 'STRINGSET' are not equatable", + }, + { + SQLs: sqls( + "select a = b from binoptestb_ss;", + ), + ExpErr: "types 'BOOL' and 'STRINGSET' are not equatable", + }, + { + SQLs: sqls( + "select a <= b from binoptestb_ss;", + ), + ExpErr: " operator '<=' incompatible with type 'BOOL'", + }, + { + SQLs: sqls( + "select a >= b from binoptestb_ss;", + ), + ExpErr: " operator '>=' incompatible with type 'BOOL'", + }, + { + SQLs: sqls( + "select a < b from binoptestb_ss;", + ), + ExpErr: " operator '<' incompatible with type 'BOOL'", + }, + { + SQLs: sqls( + "select a > b from binoptestb_ss;", + ), + ExpErr: " operator '>' incompatible with type 'BOOL'", + }, + { + SQLs: sqls( + "select a & b from binoptestb_ss;", + ), + ExpErr: " operator '&' incompatible with type 'BOOL'", + }, + { + SQLs: sqls( + "select a | b from binoptestb_ss;", + ), + ExpErr: " operator '|' incompatible with type 'BOOL'", + }, + { + SQLs: sqls( + "select a << b from binoptestb_ss;", + ), + ExpErr: " operator '<<' incompatible with type 'BOOL'", + }, + { + SQLs: sqls( + "select a >> b from binoptestb_ss;", + ), + ExpErr: " operator '>>' incompatible with type 'BOOL'", + }, + { + SQLs: sqls( + "select a + b from binoptestb_ss;", + ), + ExpErr: " operator '+' incompatible with type 'BOOL'", + }, + { + SQLs: sqls( + "select a - b from binoptestb_ss;", + ), + ExpErr: " operator '-' incompatible with type 'BOOL'", + }, + { + SQLs: sqls( + "select a * b from binoptestb_ss;", + ), + ExpErr: " operator '*' incompatible with type 'BOOL'", + }, + { + SQLs: sqls( + "select a / b from binoptestb_ss;", + ), + ExpErr: " operator '/' incompatible with type 'BOOL'", + }, + { + SQLs: sqls( + "select a % b from binoptestb_ss;", + ), + ExpErr: " operator '%' incompatible with type 'BOOL'", + }, + { + SQLs: sqls( + "select a || b from binoptestb_ss;", + ), + ExpErr: "operator '||' incompatible with type 'BOOL'", + }, + }, +} + +// ID bin op tests +var binOpExprWithIDInt = TableTest{ + Table: tbl( + "binoptestid_i", + srcHdrs( + srcHdr("_id", fldTypeID), + srcHdr("b", fldTypeInt, "min 0", "max 1000"), + ), + srcRows( + srcRow(int64(10), int64(20)), + ), + ), + SQLTests: []SQLTest{ + { + SQLs: sqls( + "select _id != b from binoptestid_i;", + ), + ExpHdrs: hdrs( + hdr("", fldTypeBool), + ), + ExpRows: rows( + row(bool(true)), + ), + Compare: CompareExactUnordered, + }, + { + SQLs: sqls( + "select _id = b from binoptestid_i;", + ), + ExpHdrs: hdrs( + hdr("", fldTypeBool), + ), + ExpRows: rows( + row(bool(false)), + ), + Compare: CompareExactUnordered, + }, + { + SQLs: sqls( + "select _id <= b from binoptestid_i;", + ), + ExpHdrs: hdrs( + hdr("", fldTypeBool), + ), + ExpRows: rows( + row(bool(true)), + ), + Compare: CompareExactUnordered, + }, + { + SQLs: sqls( + "select _id >= b from binoptestid_i;", + ), + ExpHdrs: hdrs( + hdr("", fldTypeBool), + ), + ExpRows: rows( + row(bool(false)), + ), + Compare: CompareExactUnordered, + }, + { + SQLs: sqls( + "select _id < b from binoptestid_i;", + ), + ExpHdrs: hdrs( + hdr("", fldTypeBool), + ), + ExpRows: rows( + row(bool(true)), + ), + Compare: CompareExactUnordered, + }, + { + SQLs: sqls( + "select _id > b from binoptestid_i;", + ), + ExpHdrs: hdrs( + hdr("", fldTypeBool), + ), + ExpRows: rows( + row(bool(false)), + ), + Compare: CompareExactUnordered, + }, + { + SQLs: sqls( + "select _id & b from binoptestid_i;", + ), + ExpHdrs: hdrs( + hdr("", fldTypeInt), + ), + ExpRows: rows( + row(int64(0)), + ), + Compare: CompareExactUnordered, + }, + { + SQLs: sqls( + "select _id | b from binoptestid_i;", + ), + ExpHdrs: hdrs( + hdr("", fldTypeInt), + ), + ExpRows: rows( + row(int64(30)), + ), + Compare: CompareExactUnordered, + }, + { + SQLs: sqls( + "select _id << b from binoptestid_i;", + ), + ExpHdrs: hdrs( + hdr("", fldTypeInt), + ), + ExpRows: rows( + row(int64(10485760)), + ), + Compare: CompareExactUnordered, + }, + { + SQLs: sqls( + "select _id >> b from binoptestid_i;", + ), + ExpHdrs: hdrs( + hdr("", fldTypeInt), + ), + ExpRows: rows( + row(int64(0)), + ), + Compare: CompareExactUnordered, + }, + { + SQLs: sqls( + "select _id + b from binoptestid_i;", + ), + ExpHdrs: hdrs( + hdr("", fldTypeInt), + ), + ExpRows: rows( + row(int64(30)), + ), + Compare: CompareExactUnordered, + }, + { + SQLs: sqls( + "select _id - b from binoptestid_i;", + ), + ExpHdrs: hdrs( + hdr("", fldTypeInt), + ), + ExpRows: rows( + row(int64(-10)), + ), + Compare: CompareExactUnordered, + }, + { + SQLs: sqls( + "select _id * b from binoptestid_i;", + ), + ExpHdrs: hdrs( + hdr("", fldTypeInt), + ), + ExpRows: rows( + row(int64(200)), + ), + Compare: CompareExactUnordered, + }, + { + SQLs: sqls( + "select _id / b from binoptestid_i;", + ), + ExpHdrs: hdrs( + hdr("", fldTypeInt), + ), + ExpRows: rows( + row(int64(0)), + ), + Compare: CompareExactUnordered, + }, + { + SQLs: sqls( + "select _id % b from binoptestid_i;", + ), + ExpHdrs: hdrs( + hdr("", fldTypeInt), + ), + ExpRows: rows( + row(int64(10)), + ), + Compare: CompareExactUnordered, + }, + { + SQLs: sqls( + "select _id || b from binoptestid_i;", + ), + ExpErr: "operator '||' incompatible with type 'ID'", + }, + }, +} + +var binOpExprWithIDBool = TableTest{ + Table: tbl( + "binoptestid_b", + srcHdrs( + srcHdr("_id", fldTypeID), + srcHdr("b", fldTypeBool), + ), + srcRows( + srcRow(int64(10), bool(true)), + ), + ), + SQLTests: []SQLTest{ + { + SQLs: sqls( + "select _id != b from binoptestid_b;", + ), + ExpErr: "types 'ID' and 'BOOL' are not equatable", + }, + { + SQLs: sqls( + "select _id = b from binoptestid_b;", + ), + ExpErr: "types 'ID' and 'BOOL' are not equatable", + }, + { + SQLs: sqls( + "select _id <= b from binoptestid_b;", + ), + ExpErr: "operator '<=' incompatible with type 'BOOL'", + }, + { + SQLs: sqls( + "select _id >= b from binoptestid_b;", + ), + ExpErr: "operator '>=' incompatible with type 'BOOL'", + }, + { + SQLs: sqls( + "select _id < b from binoptestid_b;", + ), + ExpErr: "operator '<' incompatible with type 'BOOL'", + }, + { + SQLs: sqls( + "select _id > b from binoptestid_b;", + ), + ExpErr: "operator '>' incompatible with type 'BOOL'", + }, + { + SQLs: sqls( + "select _id & b from binoptestid_b;", + ), + ExpErr: "operator '&' incompatible with type 'BOOL'", + }, + { + SQLs: sqls( + "select _id | b from binoptestid_b;", + ), + ExpErr: "operator '|' incompatible with type 'BOOL'", + }, + { + SQLs: sqls( + "select _id << b from binoptestid_b;", + ), + ExpErr: "operator '<<' incompatible with type 'BOOL'", + }, + { + SQLs: sqls( + "select _id >> b from binoptestid_b;", + ), + ExpErr: "operator '>>' incompatible with type 'BOOL'", + }, + { + SQLs: sqls( + "select _id + b from binoptestid_b;", + ), + ExpErr: "operator '+' incompatible with type 'BOOL'", + }, + { + SQLs: sqls( + "select _id - b from binoptestid_b;", + ), + ExpErr: "operator '-' incompatible with type 'BOOL'", + }, + { + SQLs: sqls( + "select _id * b from binoptestid_b;", + ), + ExpErr: "operator '*' incompatible with type 'BOOL'", + }, + { + SQLs: sqls( + "select _id / b from binoptestid_b;", + ), + ExpErr: "operator '/' incompatible with type 'BOOL'", + }, + { + SQLs: sqls( + "select _id % b from binoptestid_b;", + ), + ExpErr: "operator '%' incompatible with type 'BOOL'", + }, + { + SQLs: sqls( + "select _id || b from binoptestid_b;", + ), + ExpErr: "operator '||' incompatible with type 'ID'", + }, + }, +} + +var binOpExprWithIDID = TableTest{ + Table: tbl( + "binoptestid_id", + srcHdrs( + srcHdr("_id", fldTypeID), + srcHdr("b", fldTypeID), + ), + srcRows( + srcRow(int64(10), int64(20)), + ), + ), + SQLTests: []SQLTest{ + { + SQLs: sqls( + "select _id != b from binoptestid_id;", + ), + ExpHdrs: hdrs( + hdr("", fldTypeBool), + ), + ExpRows: rows( + row(bool(true)), + ), + Compare: CompareExactUnordered, + }, + { + SQLs: sqls( + "select _id = b from binoptestid_id;", + ), + ExpHdrs: hdrs( + hdr("", fldTypeBool), + ), + ExpRows: rows( + row(bool(false)), + ), + Compare: CompareExactUnordered, + }, + { + SQLs: sqls( + "select _id <= b from binoptestid_id;", + ), + ExpHdrs: hdrs( + hdr("", fldTypeBool), + ), + ExpRows: rows( + row(bool(true)), + ), + Compare: CompareExactUnordered, + }, + { + SQLs: sqls( + "select _id >= b from binoptestid_id;", + ), + ExpHdrs: hdrs( + hdr("", fldTypeBool), + ), + ExpRows: rows( + row(bool(false)), + ), + Compare: CompareExactUnordered, + }, + { + SQLs: sqls( + "select _id < b from binoptestid_id;", + ), + ExpHdrs: hdrs( + hdr("", fldTypeBool), + ), + ExpRows: rows( + row(bool(true)), + ), + Compare: CompareExactUnordered, + }, + { + SQLs: sqls( + "select _id > b from binoptestid_id;", + ), + ExpHdrs: hdrs( + hdr("", fldTypeBool), + ), + ExpRows: rows( + row(bool(false)), + ), + Compare: CompareExactUnordered, + }, + { + SQLs: sqls( + "select _id & b from binoptestid_id;", + ), + ExpHdrs: hdrs( + hdr("", fldTypeID), + ), + ExpRows: rows( + row(int64(0)), + ), + Compare: CompareExactUnordered, + }, + { + SQLs: sqls( + "select _id | b from binoptestid_id;", + ), + ExpHdrs: hdrs( + hdr("", fldTypeID), + ), + ExpRows: rows( + row(int64(30)), + ), + Compare: CompareExactUnordered, + }, + { + SQLs: sqls( + "select _id << b from binoptestid_id;", + ), + ExpHdrs: hdrs( + hdr("", fldTypeID), + ), + ExpRows: rows( + row(int64(10485760)), + ), + Compare: CompareExactUnordered, + }, + { + SQLs: sqls( + "select _id >> b from binoptestid_id;", + ), + ExpHdrs: hdrs( + hdr("", fldTypeID), + ), + ExpRows: rows( + row(int64(0)), + ), + Compare: CompareExactUnordered, + }, + { + SQLs: sqls( + "select _id + b from binoptestid_id;", + ), + ExpHdrs: hdrs( + hdr("", fldTypeID), + ), + ExpRows: rows( + row(int64(30)), + ), + Compare: CompareExactUnordered, + }, + { + SQLs: sqls( + "select _id - b from binoptestid_id;", + ), + ExpHdrs: hdrs( + hdr("", fldTypeID), + ), + ExpRows: rows( + row(int64(-10)), + ), + Compare: CompareExactUnordered, + }, + { + SQLs: sqls( + "select _id * b from binoptestid_id;", + ), + ExpHdrs: hdrs( + hdr("", fldTypeID), + ), + ExpRows: rows( + row(int64(200)), + ), + Compare: CompareExactUnordered, + }, + { + SQLs: sqls( + "select _id / b from binoptestid_id;", + ), + ExpHdrs: hdrs( + hdr("", fldTypeID), + ), + ExpRows: rows( + row(int64(0)), + ), + Compare: CompareExactUnordered, + }, + { + SQLs: sqls( + "select _id % b from binoptestid_id;", + ), + ExpHdrs: hdrs( + hdr("", fldTypeID), + ), + ExpRows: rows( + row(int64(10)), + ), + Compare: CompareExactUnordered, + }, + { + SQLs: sqls( + "select _id || b from binoptestid_id;", + ), + ExpErr: "operator '||' incompatible with type 'ID'", + }, + }, +} + +var binOpExprWithIDDecimal = TableTest{ + Table: tbl( + "binoptestid_d", + srcHdrs( + srcHdr("_id", fldTypeID), + srcHdr("a", fldTypeID), + srcHdr("d", fldTypeDecimal2), + ), + srcRows( + srcRow(int64(1), int64(20), float64(12.34)), + ), + ), + SQLTests: []SQLTest{ + { + SQLs: sqls( + "select a != d from binoptesti_d;", + ), + ExpHdrs: hdrs( + hdr("", fldTypeBool), + ), + ExpRows: rows( + row(bool(true)), + ), + Compare: CompareExactUnordered, + }, + { + SQLs: sqls( + "select a = d from binoptesti_d;", + ), + ExpHdrs: hdrs( + hdr("", fldTypeBool), + ), + ExpRows: rows( + row(bool(false)), + ), + Compare: CompareExactUnordered, + }, + { + SQLs: sqls( + "select a <= d from binoptesti_d;", + ), + ExpHdrs: hdrs( + hdr("", fldTypeBool), + ), + ExpRows: rows( + row(bool(false)), + ), + Compare: CompareExactUnordered, + }, + { + SQLs: sqls( + "select a >= d from binoptesti_d;", + ), + ExpHdrs: hdrs( + hdr("", fldTypeBool), + ), + ExpRows: rows( + row(bool(true)), + ), + Compare: CompareExactUnordered, + }, + { + SQLs: sqls( + "select a < d from binoptesti_d;", + ), + ExpHdrs: hdrs( + hdr("", fldTypeBool), + ), + ExpRows: rows( + row(bool(false)), + ), + Compare: CompareExactUnordered, + }, + { + SQLs: sqls( + "select a > d from binoptesti_d;", + ), + ExpHdrs: hdrs( + hdr("", fldTypeBool), + ), + ExpRows: rows( + row(bool(true)), + ), + Compare: CompareExactUnordered, + }, + { + SQLs: sqls( + "select a & d from binoptesti_d;", + ), + ExpErr: "operator '&' incompatible with type 'DECIMAL(2)'", + }, + { + SQLs: sqls( + "select a | d from binoptesti_d;", + ), + ExpErr: "operator '|' incompatible with type 'DECIMAL(2)'", + }, + { + SQLs: sqls( + "select a << d from binoptesti_d;", + ), + ExpErr: "operator '<<' incompatible with type 'DECIMAL(2)'", + }, + { + SQLs: sqls( + "select a >> d from binoptesti_d;", + ), + ExpErr: "operator '>>' incompatible with type 'DECIMAL(2)'", + }, + { + SQLs: sqls( + "select a + d from binoptesti_d;", + ), + ExpHdrs: hdrs( + hdr("", fldTypeDecimal2), + ), + ExpRows: rows( + row(pql.NewDecimal(3234, 2)), + ), + Compare: CompareExactUnordered, + }, + { + SQLs: sqls( + "select a - d from binoptesti_d;", + ), + ExpHdrs: hdrs( + hdr("", fldTypeDecimal2), + ), + ExpRows: rows( + row(pql.NewDecimal(766, 2)), + ), + Compare: CompareExactUnordered, + }, + { + SQLs: sqls( + "select a * d from binoptesti_d;", + ), + ExpHdrs: hdrs( + hdr("", fldTypeDecimal2), + ), + ExpRows: rows( + row(pql.NewDecimal(24680, 2)), + ), + Compare: CompareExactUnordered, + }, + { + SQLs: sqls( + "select a / d from binoptesti_d;", + ), + ExpHdrs: hdrs( + hdr("", fldTypeDecimal2), + ), + ExpRows: rows( + row(pql.NewDecimal(162, 2)), + ), + Compare: CompareExactUnordered, + }, + { + SQLs: sqls( + "select a % d from binoptesti_d;", + ), + ExpErr: "operator '%' incompatible with type 'DECIMAL(2)'", + }, + { + SQLs: sqls( + "select a || d from binoptesti_d;", + ), + ExpErr: "operator '||' incompatible with type 'INT'", + }, + }, +} + +var binOpExprWithIDTimestamp = TableTest{ + Table: tbl( + "binoptestid_ts", + srcHdrs( + srcHdr("_id", fldTypeID), + srcHdr("a", fldTypeID), + srcHdr("ts", fldTypeTimestamp), + ), + srcRows( + srcRow(int64(1), int64(20), time.Time(knownTimestamp())), + ), + ), + SQLTests: []SQLTest{ + { + SQLs: sqls( + "select a != ts from binoptesti_ts;", + ), + ExpErr: "types 'INT' and 'TIMESTAMP' are not equatable", + }, + { + SQLs: sqls( + "select a = ts from binoptesti_ts;", + ), + ExpErr: "types 'INT' and 'TIMESTAMP' are not equatable", + }, + { + SQLs: sqls( + "select a <= ts from binoptesti_ts;", + ), + ExpErr: "types 'INT' and 'TIMESTAMP' are not equatable", + }, + { + SQLs: sqls( + "select a >= ts from binoptesti_ts;", + ), + ExpErr: "types 'INT' and 'TIMESTAMP' are not equatable", + }, + { + SQLs: sqls( + "select a < ts from binoptesti_ts;", + ), + ExpErr: "types 'INT' and 'TIMESTAMP' are not equatable", + }, + { + SQLs: sqls( + "select a > ts from binoptesti_ts;", + ), + ExpErr: "types 'INT' and 'TIMESTAMP' are not equatable", + }, + { + SQLs: sqls( + "select a & ts from binoptesti_ts;", + ), + ExpErr: "operator '&' incompatible with type 'TIMESTAMP'", + }, + { + SQLs: sqls( + "select a | ts from binoptesti_ts;", + ), + ExpErr: "operator '|' incompatible with type 'TIMESTAMP'", + }, + { + SQLs: sqls( + "select a << ts from binoptesti_ts;", + ), + ExpErr: "operator '<<' incompatible with type 'TIMESTAMP'", + }, + { + SQLs: sqls( + "select a >> ts from binoptesti_ts;", + ), + ExpErr: "operator '>>' incompatible with type 'TIMESTAMP'", + }, + { + SQLs: sqls( + "select a + ts from binoptesti_ts;", + ), + ExpErr: "operator '+' incompatible with type 'TIMESTAMP'", + }, + { + SQLs: sqls( + "select a - ts from binoptesti_ts;", + ), + ExpErr: "operator '-' incompatible with type 'TIMESTAMP'", + }, + { + SQLs: sqls( + "select a * ts from binoptesti_ts;", + ), + ExpErr: "operator '*' incompatible with type 'TIMESTAMP'", + }, + { + SQLs: sqls( + "select a / ts from binoptesti_ts;", + ), + ExpErr: "operator '/' incompatible with type 'TIMESTAMP'", + }, + { + SQLs: sqls( + "select a % ts from binoptesti_ts;", + ), + ExpErr: "operator '%' incompatible with type 'TIMESTAMP'", + }, + { + SQLs: sqls( + "select a || ts from binoptesti_ts;", + ), + ExpErr: "operator '||' incompatible with type 'INT'", + }, + }, +} + +var binOpExprWithIDIDSet = TableTest{ + Table: tbl( + "binoptestid_ids", + srcHdrs( + srcHdr("_id", fldTypeID), + srcHdr("a", fldTypeID), + srcHdr("b", fldTypeIDSet), + ), + srcRows( + srcRow(int64(1), int64(20), []int64{101, 102}), + ), + ), + SQLTests: []SQLTest{ + { + SQLs: sqls( + "select a != b from binoptesti_ids;", + ), + ExpErr: "types 'INT' and 'IDSET' are not equatable", + }, + { + SQLs: sqls( + "select a = b from binoptesti_ids;", + ), + ExpErr: "types 'INT' and 'IDSET' are not equatable", + }, + { + SQLs: sqls( + "select a <= b from binoptesti_ids;", + ), + ExpErr: " operator '<=' incompatible with type 'IDSET'", + }, + { + SQLs: sqls( + "select a >= b from binoptesti_ids;", + ), + ExpErr: " operator '>=' incompatible with type 'IDSET'", + }, + { + SQLs: sqls( + "select a < b from binoptesti_ids;", + ), + ExpErr: " operator '<' incompatible with type 'IDSET'", + }, + { + SQLs: sqls( + "select a > b from binoptesti_ids;", + ), + ExpErr: " operator '>' incompatible with type 'IDSET'", + }, + { + SQLs: sqls( + "select a & b from binoptesti_ids;", + ), + ExpErr: " operator '&' incompatible with type 'IDSET'", + }, + { + SQLs: sqls( + "select a | b from binoptesti_ids;", + ), + ExpErr: " operator '|' incompatible with type 'IDSET'", + }, + { + SQLs: sqls( + "select a << b from binoptesti_ids;", + ), + ExpErr: " operator '<<' incompatible with type 'IDSET'", + }, + { + SQLs: sqls( + "select a >> b from binoptesti_ids;", + ), + ExpErr: " operator '>>' incompatible with type 'IDSET'", + }, + { + SQLs: sqls( + "select a + b from binoptesti_ids;", + ), + ExpErr: " operator '+' incompatible with type 'IDSET'", + }, + { + SQLs: sqls( + "select a - b from binoptesti_ids;", + ), + ExpErr: " operator '-' incompatible with type 'IDSET'", + }, + { + SQLs: sqls( + "select a * b from binoptesti_ids;", + ), + ExpErr: " operator '*' incompatible with type 'IDSET'", + }, + { + SQLs: sqls( + "select a / b from binoptesti_ids;", + ), + ExpErr: " operator '/' incompatible with type 'IDSET'", + }, + { + SQLs: sqls( + "select a % b from binoptesti_ids;", + ), + ExpErr: " operator '%' incompatible with type 'IDSET'", + }, + { + SQLs: sqls( + "select a || b from binoptesti_ids;", + ), + ExpErr: "operator '||' incompatible with type 'INT'", + }, + }, +} + +var binOpExprWithIDString = TableTest{ + Table: tbl( + "binoptestid_s", + srcHdrs( + srcHdr("_id", fldTypeID), + srcHdr("a", fldTypeID), + srcHdr("b", fldTypeString), + ), + srcRows( + srcRow(int64(1), int64(20), string("101")), + ), + ), + SQLTests: []SQLTest{ + { + SQLs: sqls( + "select a != b from binoptesti_s;", + ), + ExpErr: "types 'INT' and 'STRING' are not equatable", + }, + { + SQLs: sqls( + "select a = b from binoptesti_s;", + ), + ExpErr: "types 'INT' and 'STRING' are not equatable", + }, + { + SQLs: sqls( + "select a <= b from binoptesti_s;", + ), + ExpErr: " operator '<=' incompatible with type 'STRING'", + }, + { + SQLs: sqls( + "select a >= b from binoptesti_s;", + ), + ExpErr: " operator '>=' incompatible with type 'STRING'", + }, + { + SQLs: sqls( + "select a < b from binoptesti_s;", + ), + ExpErr: " operator '<' incompatible with type 'STRING'", + }, + { + SQLs: sqls( + "select a > b from binoptesti_s;", + ), + ExpErr: " operator '>' incompatible with type 'STRING'", + }, + { + SQLs: sqls( + "select a & b from binoptesti_s;", + ), + ExpErr: " operator '&' incompatible with type 'STRING'", + }, + { + SQLs: sqls( + "select a | b from binoptesti_s;", + ), + ExpErr: " operator '|' incompatible with type 'STRING'", + }, + { + SQLs: sqls( + "select a << b from binoptesti_s;", + ), + ExpErr: " operator '<<' incompatible with type 'STRING'", + }, + { + SQLs: sqls( + "select a >> b from binoptesti_s;", + ), + ExpErr: " operator '>>' incompatible with type 'STRING'", + }, + { + SQLs: sqls( + "select a + b from binoptesti_s;", + ), + ExpErr: " operator '+' incompatible with type 'STRING'", + }, + { + SQLs: sqls( + "select a - b from binoptesti_s;", + ), + ExpErr: " operator '-' incompatible with type 'STRING'", + }, + { + SQLs: sqls( + "select a * b from binoptesti_s;", + ), + ExpErr: " operator '*' incompatible with type 'STRING'", + }, + { + SQLs: sqls( + "select a / b from binoptesti_s;", + ), + ExpErr: " operator '/' incompatible with type 'STRING'", + }, + { + SQLs: sqls( + "select a % b from binoptesti_s;", + ), + ExpErr: " operator '%' incompatible with type 'STRING'", + }, + { + SQLs: sqls( + "select a || b from binoptesti_s;", + ), + ExpErr: "operator '||' incompatible with type 'INT'", + }, + }, +} + +var binOpExprWithIDStringSet = TableTest{ + Table: tbl( + "binoptestid_ss", + srcHdrs( + srcHdr("_id", fldTypeID), + srcHdr("a", fldTypeID), + srcHdr("b", fldTypeStringSet), + ), + srcRows( + srcRow(int64(1), int64(20), []string{"101", "102"}), + ), + ), + SQLTests: []SQLTest{ + { + SQLs: sqls( + "select a != b from binoptesti_ss;", + ), + ExpErr: "types 'INT' and 'STRINGSET' are not equatable", + }, + { + SQLs: sqls( + "select a = b from binoptesti_ss;", + ), + ExpErr: "types 'INT' and 'STRINGSET' are not equatable", + }, + { + SQLs: sqls( + "select a <= b from binoptesti_ss;", + ), + ExpErr: " operator '<=' incompatible with type 'STRINGSET'", + }, + { + SQLs: sqls( + "select a >= b from binoptesti_ss;", + ), + ExpErr: " operator '>=' incompatible with type 'STRINGSET'", + }, + { + SQLs: sqls( + "select a < b from binoptesti_ss;", + ), + ExpErr: " operator '<' incompatible with type 'STRINGSET'", + }, + { + SQLs: sqls( + "select a > b from binoptesti_ss;", + ), + ExpErr: " operator '>' incompatible with type 'STRINGSET'", + }, + { + SQLs: sqls( + "select a & b from binoptesti_ss;", + ), + ExpErr: " operator '&' incompatible with type 'STRINGSET'", + }, + { + SQLs: sqls( + "select a | b from binoptesti_ss;", + ), + ExpErr: " operator '|' incompatible with type 'STRINGSET'", + }, + { + SQLs: sqls( + "select a << b from binoptesti_ss;", + ), + ExpErr: " operator '<<' incompatible with type 'STRINGSET'", + }, + { + SQLs: sqls( + "select a >> b from binoptesti_ss;", + ), + ExpErr: " operator '>>' incompatible with type 'STRINGSET'", + }, + { + SQLs: sqls( + "select a + b from binoptesti_ss;", + ), + ExpErr: " operator '+' incompatible with type 'STRINGSET'", + }, + { + SQLs: sqls( + "select a - b from binoptesti_ss;", + ), + ExpErr: " operator '-' incompatible with type 'STRINGSET'", + }, + { + SQLs: sqls( + "select a * b from binoptesti_ss;", + ), + ExpErr: " operator '*' incompatible with type 'STRINGSET'", + }, + { + SQLs: sqls( + "select a / b from binoptesti_ss;", + ), + ExpErr: " operator '/' incompatible with type 'STRINGSET'", + }, + { + SQLs: sqls( + "select a % b from binoptesti_ss;", + ), + ExpErr: " operator '%' incompatible with type 'STRINGSET'", + }, + { + SQLs: sqls( + "select a || b from binoptesti_ss;", + ), + ExpErr: "operator '||' incompatible with type 'INT'", + }, + }, +} + +// DECIMAL bin op tests +var binOpExprWithDecInt = TableTest{ + Table: tbl( + "binoptestdec_i", + srcHdrs( + srcHdr("_id", fldTypeID), + srcHdr("b", fldTypeInt, "min 0", "max 1000"), + srcHdr("d", fldTypeDecimal2), + ), + srcRows( + srcRow(int64(10), int64(20), float64(12.34)), + ), + ), + SQLTests: []SQLTest{ + { + SQLs: sqls( + "select d != b from binoptestdec_i;", + ), + ExpHdrs: hdrs( + hdr("", fldTypeBool), + ), + ExpRows: rows( + row(bool(true)), + ), + Compare: CompareExactUnordered, + }, + { + SQLs: sqls( + "select d = b from binoptestdec_i;", + ), + ExpHdrs: hdrs( + hdr("", fldTypeBool), + ), + ExpRows: rows( + row(bool(false)), + ), + Compare: CompareExactUnordered, + }, + { + SQLs: sqls( + "select d <= b from binoptestdec_i;", + ), + ExpHdrs: hdrs( + hdr("", fldTypeBool), + ), + ExpRows: rows( + row(bool(true)), + ), + Compare: CompareExactUnordered, + }, + { + SQLs: sqls( + "select d >= b from binoptestdec_i;", + ), + ExpHdrs: hdrs( + hdr("", fldTypeBool), + ), + ExpRows: rows( + row(bool(false)), + ), + Compare: CompareExactUnordered, + }, + { + SQLs: sqls( + "select d < b from binoptestdec_i;", + ), + ExpHdrs: hdrs( + hdr("", fldTypeBool), + ), + ExpRows: rows( + row(bool(true)), + ), + Compare: CompareExactUnordered, + }, + { + SQLs: sqls( + "select d > b from binoptestdec_i;", + ), + ExpHdrs: hdrs( + hdr("", fldTypeBool), + ), + ExpRows: rows( + row(bool(false)), + ), + Compare: CompareExactUnordered, + }, + { + SQLs: sqls( + "select d & b from binoptestdec_i;", + ), + ExpErr: "operator '&' incompatible with type 'DECIMAL(2)'", + }, + { + SQLs: sqls( + "select d | b from binoptestdec_i;", + ), + ExpErr: "operator '|' incompatible with type 'DECIMAL(2)'", + }, + { + SQLs: sqls( + "select d << b from binoptestdec_i;", + ), + ExpErr: "operator '<<' incompatible with type 'DECIMAL(2)'", + }, + { + SQLs: sqls( + "select d >> b from binoptestdec_i;", + ), + ExpErr: "operator '>>' incompatible with type 'DECIMAL(2)'", + }, + { + SQLs: sqls( + "select d + b from binoptestdec_i;", + ), + ExpHdrs: hdrs( + hdr("", fldTypeDecimal2), + ), + ExpRows: rows( + row(pql.NewDecimal(3234, 2)), + ), + Compare: CompareExactUnordered, + }, + { + SQLs: sqls( + "select d - b from binoptestdec_i;", + ), + ExpHdrs: hdrs( + hdr("", fldTypeDecimal2), + ), + ExpRows: rows( + row(pql.NewDecimal(-766, 2)), + ), + Compare: CompareExactUnordered, + }, + { + SQLs: sqls( + "select d * b from binoptestdec_i;", + ), + ExpHdrs: hdrs( + hdr("", fldTypeDecimal2), + ), + ExpRows: rows( + row(pql.NewDecimal(24680, 2)), + ), + Compare: CompareExactUnordered, + }, + { + SQLs: sqls( + "select d / b from binoptestdec_i;", + ), + ExpHdrs: hdrs( + hdr("", fldTypeDecimal2), + ), + ExpRows: rows( + row(pql.NewDecimal(61, 2)), + ), + Compare: CompareExactUnordered, + }, + { + SQLs: sqls( + "select d % b from binoptestdec_i;", + ), + ExpErr: "operator '%' incompatible with type 'DECIMAL(2)'", + }, + { + SQLs: sqls( + "select d || b from binoptestdec_i;", + ), + ExpErr: "operator '||' incompatible with type 'DECIMAL(2)'", + }, + }, +} + +var binOpExprWithDecBool = TableTest{ + Table: tbl( + "binoptestdec_b", + srcHdrs( + srcHdr("_id", fldTypeID), + srcHdr("b", fldTypeBool), + srcHdr("d", fldTypeDecimal2), + ), + srcRows( + srcRow(int64(10), bool(true), float64(12.34)), + ), + ), + SQLTests: []SQLTest{ + { + SQLs: sqls( + "select d != b from binoptestdec_b;", + ), + ExpErr: "types 'DECIMAL(2)' and 'BOOL' are not equatable", + }, + { + SQLs: sqls( + "select d = b from binoptestdec_b;", + ), + ExpErr: "types 'DECIMAL(2)' and 'BOOL' are not equatable", + }, + { + SQLs: sqls( + "select d <= b from binoptestdec_b;", + ), + ExpErr: "operator '<=' incompatible with type 'BOOL'", + }, + { + SQLs: sqls( + "select d >= b from binoptestdec_b;", + ), + ExpErr: "operator '>=' incompatible with type 'BOOL'", + }, + { + SQLs: sqls( + "select d < b from binoptestdec_b;", + ), + ExpErr: "operator '<' incompatible with type 'BOOL'", + }, + { + SQLs: sqls( + "select d > b from binoptestdec_b;", + ), + ExpErr: "operator '>' incompatible with type 'BOOL'", + }, + { + SQLs: sqls( + "select d & b from binoptestdec_b;", + ), + ExpErr: "operator '&' incompatible with type 'DECIMAL(2)'", + }, + { + SQLs: sqls( + "select d | b from binoptestdec_b;", + ), + ExpErr: "operator '|' incompatible with type 'DECIMAL(2)'", + }, + { + SQLs: sqls( + "select d << b from binoptestdec_b;", + ), + ExpErr: "operator '<<' incompatible with type 'DECIMAL(2)'", + }, + { + SQLs: sqls( + "select d >> b from binoptestdec_b;", + ), + ExpErr: "operator '>>' incompatible with type 'DECIMAL(2)'", + }, + { + SQLs: sqls( + "select d + b from binoptestdec_b;", + ), + ExpErr: "operator '+' incompatible with type 'BOOL'", + }, + { + SQLs: sqls( + "select d - b from binoptestdec_b;", + ), + ExpErr: "operator '-' incompatible with type 'BOOL'", + }, + { + SQLs: sqls( + "select d * b from binoptestdec_b;", + ), + ExpErr: "operator '*' incompatible with type 'BOOL'", + }, + { + SQLs: sqls( + "select d / b from binoptestdec_b;", + ), + ExpErr: "operator '/' incompatible with type 'BOOL'", + }, + { + SQLs: sqls( + "select d % b from binoptestdec_b;", + ), + ExpErr: "operator '%' incompatible with type 'DECIMAL(2)'", + }, + { + SQLs: sqls( + "select d || b from binoptestdec_b;", + ), + ExpErr: "operator '||' incompatible with type 'DECIMAL(2)'", + }, + }, +} + +var binOpExprWithDecID = TableTest{ + Table: tbl( + "binoptestdec_id", + srcHdrs( + srcHdr("_id", fldTypeID), + srcHdr("b", fldTypeID), + srcHdr("d", fldTypeDecimal2), + ), + srcRows( + srcRow(int64(10), int64(20), float64(12.34)), + ), + ), + SQLTests: []SQLTest{ + { + SQLs: sqls( + "select d != b from binoptestdec_id;", + ), + ExpHdrs: hdrs( + hdr("", fldTypeBool), + ), + ExpRows: rows( + row(bool(true)), + ), + Compare: CompareExactUnordered, + }, + { + SQLs: sqls( + "select d = b from binoptestdec_id;", + ), + ExpHdrs: hdrs( + hdr("", fldTypeBool), + ), + ExpRows: rows( + row(bool(false)), + ), + Compare: CompareExactUnordered, + }, + { + SQLs: sqls( + "select d <= b from binoptestdec_id;", + ), + ExpHdrs: hdrs( + hdr("", fldTypeBool), + ), + ExpRows: rows( + row(bool(true)), + ), + Compare: CompareExactUnordered, + }, + { + SQLs: sqls( + "select d >= b from binoptestdec_id;", + ), + ExpHdrs: hdrs( + hdr("", fldTypeBool), + ), + ExpRows: rows( + row(bool(false)), + ), + Compare: CompareExactUnordered, + }, + { + SQLs: sqls( + "select d < b from binoptestdec_id;", + ), + ExpHdrs: hdrs( + hdr("", fldTypeBool), + ), + ExpRows: rows( + row(bool(true)), + ), + Compare: CompareExactUnordered, + }, + { + SQLs: sqls( + "select d > b from binoptestdec_id;", + ), + ExpHdrs: hdrs( + hdr("", fldTypeBool), + ), + ExpRows: rows( + row(bool(false)), + ), + Compare: CompareExactUnordered, + }, + { + SQLs: sqls( + "select d & b from binoptestdec_id;", + ), + ExpErr: "operator '&' incompatible with type 'DECIMAL(2)'", + }, + { + SQLs: sqls( + "select d | b from binoptestdec_id;", + ), + ExpErr: "operator '|' incompatible with type 'DECIMAL(2)'", + }, + { + SQLs: sqls( + "select d << b from binoptestdec_id;", + ), + ExpErr: "operator '<<' incompatible with type 'DECIMAL(2)'", + }, + { + SQLs: sqls( + "select d >> b from binoptestdec_id;", + ), + ExpErr: "operator '>>' incompatible with type 'DECIMAL(2)'", + }, + { + SQLs: sqls( + "select d + b from binoptestdec_id;", + ), + ExpHdrs: hdrs( + hdr("", fldTypeDecimal2), + ), + ExpRows: rows( + row(pql.NewDecimal(3234, 2)), + ), + Compare: CompareExactUnordered, + }, + { + SQLs: sqls( + "select d - b from binoptestdec_id;", + ), + ExpHdrs: hdrs( + hdr("", fldTypeDecimal2), + ), + ExpRows: rows( + row(pql.NewDecimal(-766, 2)), + ), + Compare: CompareExactUnordered, + }, + { + SQLs: sqls( + "select d * b from binoptestdec_id;", + ), + ExpHdrs: hdrs( + hdr("", fldTypeDecimal2), + ), + ExpRows: rows( + row(pql.NewDecimal(24680, 2)), + ), + Compare: CompareExactUnordered, + }, + { + SQLs: sqls( + "select d / b from binoptestdec_id;", + ), + ExpHdrs: hdrs( + hdr("", fldTypeDecimal2), + ), + ExpRows: rows( + row(pql.NewDecimal(61, 2)), + ), + Compare: CompareExactUnordered, + }, + { + SQLs: sqls( + "select d % b from binoptestdec_id;", + ), + ExpErr: "operator '%' incompatible with type 'DECIMAL(2)'", + }, + { + SQLs: sqls( + "select d || b from binoptestdec_id;", + ), + ExpErr: "operator '||' incompatible with type 'DECIMAL(2)'", + }, + }, +} + +var binOpExprWithDecDecimal = TableTest{ + Table: tbl( + "binoptestdec_d", + srcHdrs( + srcHdr("_id", fldTypeID), + srcHdr("a", fldTypeDecimal2), + srcHdr("d", fldTypeDecimal2), + ), + srcRows( + srcRow(int64(1), float64(20.00), float64(12.34)), + ), + ), + SQLTests: []SQLTest{ + { + SQLs: sqls( + "select a != d from binoptestdec_d;", + ), + ExpHdrs: hdrs( + hdr("", fldTypeBool), + ), + ExpRows: rows( + row(bool(true)), + ), + Compare: CompareExactUnordered, + }, + { + SQLs: sqls( + "select a = d from binoptestdec_d;", + ), + ExpHdrs: hdrs( + hdr("", fldTypeBool), + ), + ExpRows: rows( + row(bool(false)), + ), + Compare: CompareExactUnordered, + }, + { + SQLs: sqls( + "select a <= d from binoptestdec_d;", + ), + ExpHdrs: hdrs( + hdr("", fldTypeBool), + ), + ExpRows: rows( + row(bool(false)), + ), + Compare: CompareExactUnordered, + }, + { + SQLs: sqls( + "select a >= d from binoptestdec_d;", + ), + ExpHdrs: hdrs( + hdr("", fldTypeBool), + ), + ExpRows: rows( + row(bool(true)), + ), + Compare: CompareExactUnordered, + }, + { + SQLs: sqls( + "select a < d from binoptestdec_d;", + ), + ExpHdrs: hdrs( + hdr("", fldTypeBool), + ), + ExpRows: rows( + row(bool(false)), + ), + Compare: CompareExactUnordered, + }, + { + SQLs: sqls( + "select a > d from binoptestdec_d;", + ), + ExpHdrs: hdrs( + hdr("", fldTypeBool), + ), + ExpRows: rows( + row(bool(true)), + ), + Compare: CompareExactUnordered, + }, + { + SQLs: sqls( + "select a & d from binoptestdec_d;", + ), + ExpErr: "operator '&' incompatible with type 'DECIMAL(2)'", + }, + { + SQLs: sqls( + "select a | d from binoptestdec_d;", + ), + ExpErr: "operator '|' incompatible with type 'DECIMAL(2)'", + }, + { + SQLs: sqls( + "select a << d from binoptestdec_d;", + ), + ExpErr: "operator '<<' incompatible with type 'DECIMAL(2)'", + }, + { + SQLs: sqls( + "select a >> d from binoptestdec_d;", + ), + ExpErr: "operator '>>' incompatible with type 'DECIMAL(2)'", + }, + { + SQLs: sqls( + "select a + d from binoptestdec_d;", + ), + ExpHdrs: hdrs( + hdr("", fldTypeDecimal2), + ), + ExpRows: rows( + row(pql.NewDecimal(3234, 2)), + ), + Compare: CompareExactUnordered, + }, + { + SQLs: sqls( + "select a - d from binoptestdec_d;", + ), + ExpHdrs: hdrs( + hdr("", fldTypeDecimal2), + ), + ExpRows: rows( + row(pql.NewDecimal(766, 2)), + ), + Compare: CompareExactUnordered, + }, + { + SQLs: sqls( + "select a * d from binoptestdec_d;", + ), + ExpHdrs: hdrs( + hdr("", fldTypeDecimal2), + ), + ExpRows: rows( + row(pql.NewDecimal(24680, 2)), + ), + Compare: CompareExactUnordered, + }, + { + SQLs: sqls( + "select a / d from binoptestdec_d;", + ), + ExpHdrs: hdrs( + hdr("", fldTypeDecimal2), + ), + ExpRows: rows( + row(pql.NewDecimal(162, 2)), + ), + Compare: CompareExactUnordered, + }, + { + SQLs: sqls( + "select a % d from binoptestdec_d;", + ), + ExpErr: "operator '%' incompatible with type 'DECIMAL(2)'", + }, + { + SQLs: sqls( + "select a || d from binoptestdec_d;", + ), + ExpErr: "operator '||' incompatible with type 'DECIMAL(2)'", + }, + }, +} + +var binOpExprWithDecTimestamp = TableTest{ + Table: tbl( + "binoptestdec_ts", + srcHdrs( + srcHdr("_id", fldTypeID), + srcHdr("a", fldTypeDecimal2), + srcHdr("ts", fldTypeTimestamp), + ), + srcRows( + srcRow(int64(1), float64(20.00), time.Time(knownTimestamp())), + ), + ), + SQLTests: []SQLTest{ + { + SQLs: sqls( + "select a != ts from binoptestdec_ts;", + ), + ExpErr: "types 'DECIMAL(2)' and 'TIMESTAMP' are not equatable", + }, + { + SQLs: sqls( + "select a = ts from binoptestdec_ts;", + ), + ExpErr: "types 'DECIMAL(2)' and 'TIMESTAMP' are not equatable", + }, + { + SQLs: sqls( + "select a <= ts from binoptestdec_ts;", + ), + ExpErr: "types 'DECIMAL(2)' and 'TIMESTAMP' are not equatable", + }, + { + SQLs: sqls( + "select a >= ts from binoptestdec_ts;", + ), + ExpErr: "types 'DECIMAL(2)' and 'TIMESTAMP' are not equatable", + }, + { + SQLs: sqls( + "select a < ts from binoptestdec_ts;", + ), + ExpErr: "types 'DECIMAL(2)' and 'TIMESTAMP' are not equatable", + }, + { + SQLs: sqls( + "select a > ts from binoptestdec_ts;", + ), + ExpErr: "types 'DECIMAL(2)' and 'TIMESTAMP' are not equatable", + }, + { + SQLs: sqls( + "select a & ts from binoptestdec_ts;", + ), + ExpErr: "operator '&' incompatible with type 'DECIMAL(2)'", + }, + { + SQLs: sqls( + "select a | ts from binoptestdec_ts;", + ), + ExpErr: "operator '|' incompatible with type 'DECIMAL(2)'", + }, + { + SQLs: sqls( + "select a << ts from binoptestdec_ts;", + ), + ExpErr: "operator '<<' incompatible with type 'DECIMAL(2)'", + }, + { + SQLs: sqls( + "select a >> ts from binoptestdec_ts;", + ), + ExpErr: "operator '>>' incompatible with type 'DECIMAL(2)'", + }, + { + SQLs: sqls( + "select a + ts from binoptestdec_ts;", + ), + ExpErr: "operator '+' incompatible with type 'TIMESTAMP'", + }, + { + SQLs: sqls( + "select a - ts from binoptestdec_ts;", + ), + ExpErr: "operator '-' incompatible with type 'TIMESTAMP'", + }, + { + SQLs: sqls( + "select a * ts from binoptestdec_ts;", + ), + ExpErr: "operator '*' incompatible with type 'TIMESTAMP'", + }, + { + SQLs: sqls( + "select a / ts from binoptestdec_ts;", + ), + ExpErr: "operator '/' incompatible with type 'TIMESTAMP'", + }, + { + SQLs: sqls( + "select a % ts from binoptestdec_ts;", + ), + ExpErr: "operator '%' incompatible with type 'DECIMAL(2)'", + }, + { + SQLs: sqls( + "select a || ts from binoptestdec_ts;", + ), + ExpErr: "operator '||' incompatible with type 'DECIMAL(2)'", + }, + }, +} + +var binOpExprWithDecIDSet = TableTest{ + Table: tbl( + "binoptestdec_ids", + srcHdrs( + srcHdr("_id", fldTypeID), + srcHdr("a", fldTypeDecimal2), + srcHdr("b", fldTypeIDSet), + ), + srcRows( + srcRow(int64(1), float64(20.00), []int64{101, 102}), + ), + ), + SQLTests: []SQLTest{ + { + SQLs: sqls( + "select a != b from binoptestdec_ids;", + ), + ExpErr: "types 'DECIMAL(2)' and 'IDSET' are not equatable", + }, + { + SQLs: sqls( + "select a = b from binoptestdec_ids;", + ), + ExpErr: "types 'DECIMAL(2)' and 'IDSET' are not equatable", + }, + { + SQLs: sqls( + "select a <= b from binoptestdec_ids;", + ), + ExpErr: " operator '<=' incompatible with type 'IDSET'", + }, + { + SQLs: sqls( + "select a >= b from binoptestdec_ids;", + ), + ExpErr: " operator '>=' incompatible with type 'IDSET'", + }, + { + SQLs: sqls( + "select a < b from binoptestdec_ids;", + ), + ExpErr: " operator '<' incompatible with type 'IDSET'", + }, + { + SQLs: sqls( + "select a > b from binoptestdec_ids;", + ), + ExpErr: " operator '>' incompatible with type 'IDSET'", + }, + { + SQLs: sqls( + "select a & b from binoptestdec_ids;", + ), + ExpErr: " operator '&' incompatible with type 'DECIMAL(2)'", + }, + { + SQLs: sqls( + "select a | b from binoptestdec_ids;", + ), + ExpErr: " operator '|' incompatible with type 'DECIMAL(2)'", + }, + { + SQLs: sqls( + "select a << b from binoptestdec_ids;", + ), + ExpErr: " operator '<<' incompatible with type 'DECIMAL(2)'", + }, + { + SQLs: sqls( + "select a >> b from binoptestdec_ids;", + ), + ExpErr: " operator '>>' incompatible with type 'DECIMAL(2)'", + }, + { + SQLs: sqls( + "select a + b from binoptestdec_ids;", + ), + ExpErr: " operator '+' incompatible with type 'IDSET'", + }, + { + SQLs: sqls( + "select a - b from binoptestdec_ids;", + ), + ExpErr: " operator '-' incompatible with type 'IDSET'", + }, + { + SQLs: sqls( + "select a * b from binoptestdec_ids;", + ), + ExpErr: " operator '*' incompatible with type 'IDSET'", + }, + { + SQLs: sqls( + "select a / b from binoptestdec_ids;", + ), + ExpErr: " operator '/' incompatible with type 'IDSET'", + }, + { + SQLs: sqls( + "select a % b from binoptestdec_ids;", + ), + ExpErr: " operator '%' incompatible with type 'DECIMAL(2)'", + }, + { + SQLs: sqls( + "select a || b from binoptestdec_ids;", + ), + ExpErr: "operator '||' incompatible with type 'DECIMAL(2)'", + }, + }, +} + +var binOpExprWithDecString = TableTest{ + Table: tbl( + "binoptestdec_s", + srcHdrs( + srcHdr("_id", fldTypeID), + srcHdr("a", fldTypeDecimal2), + srcHdr("b", fldTypeString), + ), + srcRows( + srcRow(int64(1), float64(20.00), string("101")), + ), + ), + SQLTests: []SQLTest{ + { + SQLs: sqls( + "select a != b from binoptestdec_s;", + ), + ExpErr: "types 'DECIMAL(2)' and 'STRING' are not equatable", + }, + { + SQLs: sqls( + "select a = b from binoptestdec_s;", + ), + ExpErr: "types 'DECIMAL(2)' and 'STRING' are not equatable", + }, + { + SQLs: sqls( + "select a <= b from binoptestdec_s;", + ), + ExpErr: " operator '<=' incompatible with type 'STRING'", + }, + { + SQLs: sqls( + "select a >= b from binoptestdec_s;", + ), + ExpErr: " operator '>=' incompatible with type 'STRING'", + }, + { + SQLs: sqls( + "select a < b from binoptestdec_s;", + ), + ExpErr: " operator '<' incompatible with type 'STRING'", + }, + { + SQLs: sqls( + "select a > b from binoptestdec_s;", + ), + ExpErr: " operator '>' incompatible with type 'STRING'", + }, + { + SQLs: sqls( + "select a & b from binoptestdec_s;", + ), + ExpErr: " operator '&' incompatible with type 'DECIMAL(2)'", + }, + { + SQLs: sqls( + "select a | b from binoptestdec_s;", + ), + ExpErr: " operator '|' incompatible with type 'DECIMAL(2)'", + }, + { + SQLs: sqls( + "select a << b from binoptestdec_s;", + ), + ExpErr: " operator '<<' incompatible with type 'DECIMAL(2)'", + }, + { + SQLs: sqls( + "select a >> b from binoptestdec_s;", + ), + ExpErr: " operator '>>' incompatible with type 'DECIMAL(2)'", + }, + { + SQLs: sqls( + "select a + b from binoptestdec_s;", + ), + ExpErr: " operator '+' incompatible with type 'STRING'", + }, + { + SQLs: sqls( + "select a - b from binoptestdec_s;", + ), + ExpErr: " operator '-' incompatible with type 'STRING'", + }, + { + SQLs: sqls( + "select a * b from binoptestdec_s;", + ), + ExpErr: " operator '*' incompatible with type 'STRING'", + }, + { + SQLs: sqls( + "select a / b from binoptestdec_s;", + ), + ExpErr: " operator '/' incompatible with type 'STRING'", + }, + { + SQLs: sqls( + "select a % b from binoptestdec_s;", + ), + ExpErr: " operator '%' incompatible with type 'DECIMAL(2)'", + }, + { + SQLs: sqls( + "select a || b from binoptestdec_s;", + ), + ExpErr: "operator '||' incompatible with type 'DECIMAL(2)'", + }, + }, +} + +var binOpExprWithDecStringSet = TableTest{ + Table: tbl( + "binoptestdec_ss", + srcHdrs( + srcHdr("_id", fldTypeID), + srcHdr("a", fldTypeDecimal2), + srcHdr("b", fldTypeStringSet), + ), + srcRows( + srcRow(int64(1), float64(20.00), []string{"101", "102"}), + ), + ), + SQLTests: []SQLTest{ + { + SQLs: sqls( + "select a != b from binoptestdec_ss;", + ), + ExpErr: "types 'DECIMAL(2)' and 'STRINGSET' are not equatable", + }, + { + SQLs: sqls( + "select a = b from binoptestdec_ss;", + ), + ExpErr: "types 'DECIMAL(2)' and 'STRINGSET' are not equatable", + }, + { + SQLs: sqls( + "select a <= b from binoptestdec_ss;", + ), + ExpErr: " operator '<=' incompatible with type 'STRINGSET'", + }, + { + SQLs: sqls( + "select a >= b from binoptestdec_ss;", + ), + ExpErr: " operator '>=' incompatible with type 'STRINGSET'", + }, + { + SQLs: sqls( + "select a < b from binoptestdec_ss;", + ), + ExpErr: " operator '<' incompatible with type 'STRINGSET'", + }, + { + SQLs: sqls( + "select a > b from binoptestdec_ss;", + ), + ExpErr: " operator '>' incompatible with type 'STRINGSET'", + }, + { + SQLs: sqls( + "select a & b from binoptestdec_ss;", + ), + ExpErr: " operator '&' incompatible with type 'DECIMAL(2)'", + }, + { + SQLs: sqls( + "select a | b from binoptestdec_ss;", + ), + ExpErr: " operator '|' incompatible with type 'DECIMAL(2)'", + }, + { + SQLs: sqls( + "select a << b from binoptestdec_ss;", + ), + ExpErr: " operator '<<' incompatible with type 'DECIMAL(2)'", + }, + { + SQLs: sqls( + "select a >> b from binoptestdec_ss;", + ), + ExpErr: " operator '>>' incompatible with type 'DECIMAL(2)'", + }, + { + SQLs: sqls( + "select a + b from binoptestdec_ss;", + ), + ExpErr: " operator '+' incompatible with type 'STRINGSET'", + }, + { + SQLs: sqls( + "select a - b from binoptestdec_ss;", + ), + ExpErr: " operator '-' incompatible with type 'STRINGSET'", + }, + { + SQLs: sqls( + "select a * b from binoptestdec_ss;", + ), + ExpErr: " operator '*' incompatible with type 'STRINGSET'", + }, + { + SQLs: sqls( + "select a / b from binoptestdec_ss;", + ), + ExpErr: " operator '/' incompatible with type 'STRINGSET'", + }, + { + SQLs: sqls( + "select a % b from binoptestdec_ss;", + ), + ExpErr: " operator '%' incompatible with type 'DECIMAL(2)'", + }, + { + SQLs: sqls( + "select a || b from binoptestdec_ss;", + ), + ExpErr: "operator '||' incompatible with type 'DECIMAL(2)'", + }, + }, +} + +// TIMESTAMP bin op tests +var binOpExprWithTSInt = TableTest{ + Table: tbl( + "binoptestts_i", + srcHdrs( + srcHdr("_id", fldTypeID), + srcHdr("b", fldTypeInt, "min 0", "max 1000"), + srcHdr("d", fldTypeTimestamp), + ), + srcRows( + srcRow(int64(10), int64(20), time.Time(knownTimestamp())), + ), + ), + SQLTests: []SQLTest{ + { + SQLs: sqls( + "select d != b from binoptestts_i;", + ), + ExpErr: "types 'TIMESTAMP' and 'INT' are not equatable", + }, + { + SQLs: sqls( + "select d = b from binoptestts_i;", + ), + ExpErr: "types 'TIMESTAMP' and 'INT' are not equatable", + }, + { + SQLs: sqls( + "select d <= b from binoptestts_i;", + ), + ExpErr: "types 'TIMESTAMP' and 'INT' are not equatable", + }, + { + SQLs: sqls( + "select d >= b from binoptestts_i;", + ), + ExpErr: "types 'TIMESTAMP' and 'INT' are not equatable", + }, + { + SQLs: sqls( + "select d < b from binoptestts_i;", + ), + ExpErr: "types 'TIMESTAMP' and 'INT' are not equatable", + }, + { + SQLs: sqls( + "select d > b from binoptestts_i;", + ), + ExpErr: "types 'TIMESTAMP' and 'INT' are not equatable", + }, + { + SQLs: sqls( + "select d & b from binoptestts_i;", + ), + ExpErr: "operator '&' incompatible with type 'TIMESTAMP'", + }, + { + SQLs: sqls( + "select d | b from binoptestts_i;", + ), + ExpErr: "operator '|' incompatible with type 'TIMESTAMP'", + }, + { + SQLs: sqls( + "select d << b from binoptestts_i;", + ), + ExpErr: "operator '<<' incompatible with type 'TIMESTAMP'", + }, + { + SQLs: sqls( + "select d >> b from binoptestts_i;", + ), + ExpErr: "operator '>>' incompatible with type 'TIMESTAMP'", + }, + { + SQLs: sqls( + "select d + b from binoptestts_i;", + ), + ExpErr: "operator '+' incompatible with type 'TIMESTAMP'", + }, + { + SQLs: sqls( + "select d - b from binoptestts_i;", + ), + ExpErr: "operator '-' incompatible with type 'TIMESTAMP'", + }, + { + SQLs: sqls( + "select d * b from binoptestts_i;", + ), + ExpErr: "operator '*' incompatible with type 'TIMESTAMP'", + }, + { + SQLs: sqls( + "select d / b from binoptestts_i;", + ), + ExpErr: "operator '/' incompatible with type 'TIMESTAMP'", + }, + { + SQLs: sqls( + "select d % b from binoptestts_i;", + ), + ExpErr: "operator '%' incompatible with type 'TIMESTAMP'", + }, + { + SQLs: sqls( + "select d || b from binoptestts_i;", + ), + ExpErr: "operator '||' incompatible with type 'TIMESTAMP'", + }, + }, +} + +var binOpExprWithTSBool = TableTest{ + Table: tbl( + "binoptestts_b", + srcHdrs( + srcHdr("_id", fldTypeID), + srcHdr("b", fldTypeBool), + srcHdr("d", fldTypeTimestamp), + ), + srcRows( + srcRow(int64(10), bool(true), time.Time(knownTimestamp())), + ), + ), + SQLTests: []SQLTest{ + { + SQLs: sqls( + "select d != b from binoptestts_b;", + ), + ExpErr: "types 'TIMESTAMP' and 'BOOL' are not equatable", + }, + { + SQLs: sqls( + "select d = b from binoptestts_b;", + ), + ExpErr: "types 'TIMESTAMP' and 'BOOL' are not equatable", + }, + { + SQLs: sqls( + "select d <= b from binoptestts_b;", + ), + ExpErr: "operator '<=' incompatible with type 'BOOL'", + }, + { + SQLs: sqls( + "select d >= b from binoptestts_b;", + ), + ExpErr: "operator '>=' incompatible with type 'BOOL'", + }, + { + SQLs: sqls( + "select d < b from binoptestts_b;", + ), + ExpErr: "operator '<' incompatible with type 'BOOL'", + }, + { + SQLs: sqls( + "select d > b from binoptestts_b;", + ), + ExpErr: "operator '>' incompatible with type 'BOOL'", + }, + { + SQLs: sqls( + "select d & b from binoptestts_b;", + ), + ExpErr: "operator '&' incompatible with type 'TIMESTAMP'", + }, + { + SQLs: sqls( + "select d | b from binoptestts_b;", + ), + ExpErr: "operator '|' incompatible with type 'TIMESTAMP'", + }, + { + SQLs: sqls( + "select d << b from binoptestts_b;", + ), + ExpErr: "operator '<<' incompatible with type 'TIMESTAMP'", + }, + { + SQLs: sqls( + "select d >> b from binoptestts_b;", + ), + ExpErr: "operator '>>' incompatible with type 'TIMESTAMP'", + }, + { + SQLs: sqls( + "select d + b from binoptestts_b;", + ), + ExpErr: "operator '+' incompatible with type 'TIMESTAMP'", + }, + { + SQLs: sqls( + "select d - b from binoptestts_b;", + ), + ExpErr: "operator '-' incompatible with type 'TIMESTAMP'", + }, + { + SQLs: sqls( + "select d * b from binoptestts_b;", + ), + ExpErr: "operator '*' incompatible with type 'TIMESTAMP'", + }, + { + SQLs: sqls( + "select d / b from binoptestts_b;", + ), + ExpErr: "operator '/' incompatible with type 'TIMESTAMP'", + }, + { + SQLs: sqls( + "select d % b from binoptestts_b;", + ), + ExpErr: "operator '%' incompatible with type 'TIMESTAMP'", + }, + { + SQLs: sqls( + "select d || b from binoptestts_b;", + ), + ExpErr: "operator '||' incompatible with type 'TIMESTAMP'", + }, + }, +} + +var binOpExprWithTSID = TableTest{ + Table: tbl( + "binoptestts_id", + srcHdrs( + srcHdr("_id", fldTypeID), + srcHdr("b", fldTypeID), + srcHdr("d", fldTypeTimestamp), + ), + srcRows( + srcRow(int64(10), int64(20), time.Time(knownTimestamp())), + ), + ), + SQLTests: []SQLTest{ + { + SQLs: sqls( + "select d != b from binoptestts_id;", + ), + ExpErr: "types 'TIMESTAMP' and 'ID' are not equatable", + }, + { + SQLs: sqls( + "select d = b from binoptestts_id;", + ), + ExpErr: "types 'TIMESTAMP' and 'ID' are not equatable", + }, + { + SQLs: sqls( + "select d <= b from binoptestts_id;", + ), + ExpErr: "types 'TIMESTAMP' and 'ID' are not equatable", + }, + { + SQLs: sqls( + "select d >= b from binoptestts_id;", + ), + ExpErr: "types 'TIMESTAMP' and 'ID' are not equatable", + }, + { + SQLs: sqls( + "select d < b from binoptestts_id;", + ), + ExpErr: "types 'TIMESTAMP' and 'ID' are not equatable", + }, + { + SQLs: sqls( + "select d > b from binoptestts_id;", + ), + ExpErr: "types 'TIMESTAMP' and 'ID' are not equatable", + }, + { + SQLs: sqls( + "select d & b from binoptestts_id;", + ), + ExpErr: "operator '&' incompatible with type 'TIMESTAMP'", + }, + { + SQLs: sqls( + "select d | b from binoptestts_id;", + ), + ExpErr: "operator '|' incompatible with type 'TIMESTAMP'", + }, + { + SQLs: sqls( + "select d << b from binoptestts_id;", + ), + ExpErr: "operator '<<' incompatible with type 'TIMESTAMP'", + }, + { + SQLs: sqls( + "select d >> b from binoptestts_id;", + ), + ExpErr: "operator '>>' incompatible with type 'TIMESTAMP'", + }, + { + SQLs: sqls( + "select d + b from binoptestts_id;", + ), + ExpErr: "operator '+' incompatible with type 'TIMESTAMP'", + }, + { + SQLs: sqls( + "select d - b from binoptestts_id;", + ), + ExpErr: "operator '-' incompatible with type 'TIMESTAMP'", + }, + { + SQLs: sqls( + "select d * b from binoptestts_id;", + ), + ExpErr: "operator '*' incompatible with type 'TIMESTAMP'", + }, + { + SQLs: sqls( + "select d / b from binoptestts_id;", + ), + ExpErr: "operator '/' incompatible with type 'TIMESTAMP'", + }, + { + SQLs: sqls( + "select d % b from binoptestts_id;", + ), + ExpErr: "operator '%' incompatible with type 'TIMESTAMP'", + }, + { + SQLs: sqls( + "select d || b from binoptestts_id;", + ), + ExpErr: "operator '||' incompatible with type 'TIMESTAMP'", + }, + }, +} + +var binOpExprWithTSDecimal = TableTest{ + Table: tbl( + "binoptestts_d", + srcHdrs( + srcHdr("_id", fldTypeID), + srcHdr("a", fldTypeTimestamp), + srcHdr("d", fldTypeDecimal2), + ), + srcRows( + srcRow(int64(1), time.Time(knownTimestamp()), float64(12.34)), + ), + ), + SQLTests: []SQLTest{ + { + SQLs: sqls( + "select a != d from binoptestts_d;", + ), + ExpErr: "types 'TIMESTAMP' and 'DECIMAL(2)' are not equatable", + }, + { + SQLs: sqls( + "select a = d from binoptestts_d;", + ), + ExpErr: "types 'TIMESTAMP' and 'DECIMAL(2)' are not equatable", + }, + { + SQLs: sqls( + "select a <= d from binoptestts_d;", + ), + ExpErr: "types 'TIMESTAMP' and 'DECIMAL(2)' are not equatable", + }, + { + SQLs: sqls( + "select a >= d from binoptestts_d;", + ), + ExpErr: "types 'TIMESTAMP' and 'DECIMAL(2)' are not equatable", + }, + { + SQLs: sqls( + "select a < d from binoptestts_d;", + ), + ExpErr: "types 'TIMESTAMP' and 'DECIMAL(2)' are not equatable", + }, + { + SQLs: sqls( + "select a > d from binoptestts_d;", + ), + ExpErr: "types 'TIMESTAMP' and 'DECIMAL(2)' are not equatable", + }, + { + SQLs: sqls( + "select a & d from binoptestts_d;", + ), + ExpErr: "operator '&' incompatible with type 'TIMESTAMP'", + }, + { + SQLs: sqls( + "select a | d from binoptestts_d;", + ), + ExpErr: "operator '|' incompatible with type 'TIMESTAMP'", + }, + { + SQLs: sqls( + "select a << d from binoptestts_d;", + ), + ExpErr: "operator '<<' incompatible with type 'TIMESTAMP'", + }, + { + SQLs: sqls( + "select a >> d from binoptestts_d;", + ), + ExpErr: "operator '>>' incompatible with type 'TIMESTAMP'", + }, + { + SQLs: sqls( + "select a + d from binoptestts_d;", + ), + ExpErr: "operator '+' incompatible with type 'TIMESTAMP'", + }, + { + SQLs: sqls( + "select a - d from binoptestts_d;", + ), + ExpErr: "operator '-' incompatible with type 'TIMESTAMP'", + }, + { + SQLs: sqls( + "select a * d from binoptestts_d;", + ), + ExpErr: "operator '*' incompatible with type 'TIMESTAMP'", + }, + { + SQLs: sqls( + "select a / d from binoptestts_d;", + ), + ExpErr: "operator '/' incompatible with type 'TIMESTAMP'", + }, + { + SQLs: sqls( + "select a % d from binoptestts_d;", + ), + ExpErr: "operator '%' incompatible with type 'TIMESTAMP'", + }, + { + SQLs: sqls( + "select a || d from binoptestts_d;", + ), + ExpErr: "operator '||' incompatible with type 'TIMESTAMP'", + }, + }, +} + +var binOpExprWithTSTimestamp = TableTest{ + Table: tbl( + "binoptestts_ts", + srcHdrs( + srcHdr("_id", fldTypeID), + srcHdr("a", fldTypeTimestamp), + srcHdr("ts", fldTypeTimestamp), + ), + srcRows( + srcRow(int64(1), time.Time(knownTimestamp()), time.Time(knownTimestamp())), + ), + ), + SQLTests: []SQLTest{ + { + SQLs: sqls( + "select a != ts from binoptestts_ts;", + ), + ExpHdrs: hdrs( + hdr("", fldTypeBool), + ), + ExpRows: rows( + row(bool(false)), + ), + Compare: CompareExactUnordered}, + { + SQLs: sqls( + "select a = ts from binoptestts_ts;", + ), + ExpHdrs: hdrs( + hdr("", fldTypeBool), + ), + ExpRows: rows( + row(bool(true)), + ), + Compare: CompareExactUnordered}, + { + SQLs: sqls( + "select a <= ts from binoptestts_ts;", + ), + ExpHdrs: hdrs( + hdr("", fldTypeBool), + ), + ExpRows: rows( + row(bool(true)), + ), + Compare: CompareExactUnordered, + }, + { + SQLs: sqls( + "select a >= ts from binoptestts_ts;", + ), + ExpHdrs: hdrs( + hdr("", fldTypeBool), + ), + ExpRows: rows( + row(bool(true)), + ), + Compare: CompareExactUnordered}, + { + SQLs: sqls( + "select a < ts from binoptestts_ts;", + ), + ExpHdrs: hdrs( + hdr("", fldTypeBool), + ), + ExpRows: rows( + row(bool(false)), + ), + Compare: CompareExactUnordered}, + { + SQLs: sqls( + "select a > ts from binoptestts_ts;", + ), + ExpHdrs: hdrs( + hdr("", fldTypeBool), + ), + ExpRows: rows( + row(bool(false)), + ), + Compare: CompareExactUnordered}, + { + SQLs: sqls( + "select a & ts from binoptestts_ts;", + ), + ExpErr: "operator '&' incompatible with type 'TIMESTAMP'", + }, + { + SQLs: sqls( + "select a | ts from binoptestts_ts;", + ), + ExpErr: "operator '|' incompatible with type 'TIMESTAMP'", + }, + { + SQLs: sqls( + "select a << ts from binoptestts_ts;", + ), + ExpErr: "operator '<<' incompatible with type 'TIMESTAMP'", + }, + { + SQLs: sqls( + "select a >> ts from binoptestts_ts;", + ), + ExpErr: "operator '>>' incompatible with type 'TIMESTAMP'", + }, + { + SQLs: sqls( + "select a + ts from binoptestts_ts;", + ), + ExpErr: "operator '+' incompatible with type 'TIMESTAMP'", + }, + { + SQLs: sqls( + "select a - ts from binoptestts_ts;", + ), + ExpErr: "operator '-' incompatible with type 'TIMESTAMP'", + }, + { + SQLs: sqls( + "select a * ts from binoptestts_ts;", + ), + ExpErr: "operator '*' incompatible with type 'TIMESTAMP'", + }, + { + SQLs: sqls( + "select a / ts from binoptestts_ts;", + ), + ExpErr: "operator '/' incompatible with type 'TIMESTAMP'", + }, + { + SQLs: sqls( + "select a % ts from binoptestts_ts;", + ), + ExpErr: "operator '%' incompatible with type 'TIMESTAMP'", + }, + { + SQLs: sqls( + "select a || ts from binoptestts_ts;", + ), + ExpErr: "operator '||' incompatible with type 'TIMESTAMP'", + }, + }, +} + +var binOpExprWithTSIDSet = TableTest{ + Table: tbl( + "binoptestts_ids", + srcHdrs( + srcHdr("_id", fldTypeID), + srcHdr("a", fldTypeTimestamp), + srcHdr("b", fldTypeIDSet), + ), + srcRows( + srcRow(int64(1), time.Time(knownTimestamp()), []int64{101, 102}), + ), + ), + SQLTests: []SQLTest{ + { + SQLs: sqls( + "select a != b from binoptestts_ids;", + ), + ExpErr: "types 'TIMESTAMP' and 'IDSET' are not equatable", + }, + { + SQLs: sqls( + "select a = b from binoptestts_ids;", + ), + ExpErr: "types 'TIMESTAMP' and 'IDSET' are not equatable", + }, + { + SQLs: sqls( + "select a <= b from binoptestts_ids;", + ), + ExpErr: " operator '<=' incompatible with type 'IDSET'", + }, + { + SQLs: sqls( + "select a >= b from binoptestts_ids;", + ), + ExpErr: " operator '>=' incompatible with type 'IDSET'", + }, + { + SQLs: sqls( + "select a < b from binoptestts_ids;", + ), + ExpErr: " operator '<' incompatible with type 'IDSET'", + }, + { + SQLs: sqls( + "select a > b from binoptestts_ids;", + ), + ExpErr: " operator '>' incompatible with type 'IDSET'", + }, + { + SQLs: sqls( + "select a & b from binoptestts_ids;", + ), + ExpErr: " operator '&' incompatible with type 'TIMESTAMP'", + }, + { + SQLs: sqls( + "select a | b from binoptestts_ids;", + ), + ExpErr: " operator '|' incompatible with type 'TIMESTAMP'", + }, + { + SQLs: sqls( + "select a << b from binoptestts_ids;", + ), + ExpErr: " operator '<<' incompatible with type 'TIMESTAMP'", + }, + { + SQLs: sqls( + "select a >> b from binoptestts_ids;", + ), + ExpErr: " operator '>>' incompatible with type 'TIMESTAMP'", + }, + { + SQLs: sqls( + "select a + b from binoptestts_ids;", + ), + ExpErr: " operator '+' incompatible with type 'TIMESTAMP'", + }, + { + SQLs: sqls( + "select a - b from binoptestts_ids;", + ), + ExpErr: " operator '-' incompatible with type 'TIMESTAMP'", + }, + { + SQLs: sqls( + "select a * b from binoptestts_ids;", + ), + ExpErr: " operator '*' incompatible with type 'TIMESTAMP'", + }, + { + SQLs: sqls( + "select a / b from binoptestts_ids;", + ), + ExpErr: " operator '/' incompatible with type 'TIMESTAMP'", + }, + { + SQLs: sqls( + "select a % b from binoptestts_ids;", + ), + ExpErr: " operator '%' incompatible with type 'TIMESTAMP'", + }, + { + SQLs: sqls( + "select a || b from binoptestts_ids;", + ), + ExpErr: "operator '||' incompatible with type 'TIMESTAMP'", + }, + }, +} + +var binOpExprWithTSString = TableTest{ + Table: tbl( + "binoptestts_s", + srcHdrs( + srcHdr("_id", fldTypeID), + srcHdr("a", fldTypeTimestamp), + srcHdr("b", fldTypeString), + ), + srcRows( + srcRow(int64(1), time.Time(knownTimestamp()), string("101")), + ), + ), + SQLTests: []SQLTest{ + { + SQLs: sqls( + "select a != b from binoptestts_s;", + ), + ExpErr: "types 'TIMESTAMP' and 'STRING' are not equatable", + }, + { + SQLs: sqls( + "select a = b from binoptestts_s;", + ), + ExpErr: "types 'TIMESTAMP' and 'STRING' are not equatable", + }, + { + SQLs: sqls( + "select a <= b from binoptestts_s;", + ), + ExpErr: " operator '<=' incompatible with type 'STRING'", + }, + { + SQLs: sqls( + "select a >= b from binoptestts_s;", + ), + ExpErr: " operator '>=' incompatible with type 'STRING'", + }, + { + SQLs: sqls( + "select a < b from binoptestts_s;", + ), + ExpErr: " operator '<' incompatible with type 'STRING'", + }, + { + SQLs: sqls( + "select a > b from binoptestts_s;", + ), + ExpErr: " operator '>' incompatible with type 'STRING'", + }, + { + SQLs: sqls( + "select a & b from binoptestts_s;", + ), + ExpErr: " operator '&' incompatible with type 'TIMESTAMP'", + }, + { + SQLs: sqls( + "select a | b from binoptestts_s;", + ), + ExpErr: " operator '|' incompatible with type 'TIMESTAMP'", + }, + { + SQLs: sqls( + "select a << b from binoptestts_s;", + ), + ExpErr: " operator '<<' incompatible with type 'TIMESTAMP'", + }, + { + SQLs: sqls( + "select a >> b from binoptestts_s;", + ), + ExpErr: " operator '>>' incompatible with type 'TIMESTAMP'", + }, + { + SQLs: sqls( + "select a + b from binoptestts_s;", + ), + ExpErr: " operator '+' incompatible with type 'TIMESTAMP'", + }, + { + SQLs: sqls( + "select a - b from binoptestts_s;", + ), + ExpErr: " operator '-' incompatible with type 'TIMESTAMP'", + }, + { + SQLs: sqls( + "select a * b from binoptestts_s;", + ), + ExpErr: " operator '*' incompatible with type 'TIMESTAMP'", + }, + { + SQLs: sqls( + "select a / b from binoptestts_s;", + ), + ExpErr: " operator '/' incompatible with type 'TIMESTAMP'", + }, + { + SQLs: sqls( + "select a % b from binoptestts_s;", + ), + ExpErr: " operator '%' incompatible with type 'TIMESTAMP'", + }, + { + SQLs: sqls( + "select a || b from binoptestts_s;", + ), + ExpErr: "operator '||' incompatible with type 'TIMESTAMP'", + }, + }, +} + +var binOpExprWithTSStringSet = TableTest{ + Table: tbl( + "binoptestts_ss", + srcHdrs( + srcHdr("_id", fldTypeID), + srcHdr("a", fldTypeTimestamp), + srcHdr("b", fldTypeStringSet), + ), + srcRows( + srcRow(int64(1), time.Time(knownTimestamp()), []string{"101", "102"}), + ), + ), + SQLTests: []SQLTest{ + { + SQLs: sqls( + "select a != b from binoptestts_ss;", + ), + ExpErr: "types 'TIMESTAMP' and 'STRINGSET' are not equatable", + }, + { + SQLs: sqls( + "select a = b from binoptestts_ss;", + ), + ExpErr: "types 'TIMESTAMP' and 'STRINGSET' are not equatable", + }, + { + SQLs: sqls( + "select a <= b from binoptestts_ss;", + ), + ExpErr: " operator '<=' incompatible with type 'STRINGSET'", + }, + { + SQLs: sqls( + "select a >= b from binoptestts_ss;", + ), + ExpErr: " operator '>=' incompatible with type 'STRINGSET'", + }, + { + SQLs: sqls( + "select a < b from binoptestts_ss;", + ), + ExpErr: " operator '<' incompatible with type 'STRINGSET'", + }, + { + SQLs: sqls( + "select a > b from binoptestts_ss;", + ), + ExpErr: " operator '>' incompatible with type 'STRINGSET'", + }, + { + SQLs: sqls( + "select a & b from binoptestts_ss;", + ), + ExpErr: " operator '&' incompatible with type 'TIMESTAMP'", + }, + { + SQLs: sqls( + "select a | b from binoptestts_ss;", + ), + ExpErr: " operator '|' incompatible with type 'TIMESTAMP'", + }, + { + SQLs: sqls( + "select a << b from binoptestts_ss;", + ), + ExpErr: " operator '<<' incompatible with type 'TIMESTAMP'", + }, + { + SQLs: sqls( + "select a >> b from binoptestts_ss;", + ), + ExpErr: " operator '>>' incompatible with type 'TIMESTAMP'", + }, + { + SQLs: sqls( + "select a + b from binoptestts_ss;", + ), + ExpErr: " operator '+' incompatible with type 'TIMESTAMP'", + }, + { + SQLs: sqls( + "select a - b from binoptestts_ss;", + ), + ExpErr: " operator '-' incompatible with type 'TIMESTAMP'", + }, + { + SQLs: sqls( + "select a * b from binoptestts_ss;", + ), + ExpErr: " operator '*' incompatible with type 'TIMESTAMP'", + }, + { + SQLs: sqls( + "select a / b from binoptestts_ss;", + ), + ExpErr: " operator '/' incompatible with type 'TIMESTAMP'", + }, + { + SQLs: sqls( + "select a % b from binoptestts_ss;", + ), + ExpErr: " operator '%' incompatible with type 'TIMESTAMP'", + }, + { + SQLs: sqls( + "select a || b from binoptestts_ss;", + ), + ExpErr: "operator '||' incompatible with type 'TIMESTAMP'", + }, + }, +} + +// IDSET bin op tests +var binOpExprWithIDSetInt = TableTest{ + Table: tbl( + "binoptestids_i", + srcHdrs( + srcHdr("_id", fldTypeID), + srcHdr("b", fldTypeInt), + srcHdr("d", fldTypeIDSet), + ), + srcRows( + srcRow(int64(10), int64(20), []int64{20, 21}), + ), + ), + SQLTests: []SQLTest{ + { + SQLs: sqls( + "select d != b from binoptestids_i;", + ), + ExpErr: "types 'IDSET' and 'INT' are not equatable", + }, + { + SQLs: sqls( + "select d = b from binoptestids_i;", + ), + ExpErr: "types 'IDSET' and 'INT' are not equatable", + }, + { + SQLs: sqls( + "select d <= b from binoptestids_i;", + ), + ExpErr: "operator '<=' incompatible with type 'IDSET'", + }, + { + SQLs: sqls( + "select d >= b from binoptestids_i;", + ), + ExpErr: "operator '>=' incompatible with type 'IDSET'", + }, + { + SQLs: sqls( + "select d < b from binoptestids_i;", + ), + ExpErr: "operator '<' incompatible with type 'IDSET'", + }, + { + SQLs: sqls( + "select d > b from binoptestids_i;", + ), + ExpErr: "operator '>' incompatible with type 'IDSET'", + }, + { + SQLs: sqls( + "select d & b from binoptestids_i;", + ), + ExpErr: "operator '&' incompatible with type 'IDSET'", + }, + { + SQLs: sqls( + "select d | b from binoptestids_i;", + ), + ExpErr: "operator '|' incompatible with type 'IDSET'", + }, + { + SQLs: sqls( + "select d << b from binoptestids_i;", + ), + ExpErr: "operator '<<' incompatible with type 'IDSET'", + }, + { + SQLs: sqls( + "select d >> b from binoptestids_i;", + ), + ExpErr: "operator '>>' incompatible with type 'IDSET'", + }, + { + SQLs: sqls( + "select d + b from binoptestids_i;", + ), + ExpErr: "operator '+' incompatible with type 'IDSET'", + }, + { + SQLs: sqls( + "select d - b from binoptestids_i;", + ), + ExpErr: "operator '-' incompatible with type 'IDSET'", + }, + { + SQLs: sqls( + "select d * b from binoptestids_i;", + ), + ExpErr: "operator '*' incompatible with type 'IDSET'", + }, + { + SQLs: sqls( + "select d / b from binoptestids_i;", + ), + ExpErr: "operator '/' incompatible with type 'IDSET'", + }, + { + SQLs: sqls( + "select d % b from binoptestids_i;", + ), + ExpErr: "operator '%' incompatible with type 'IDSET'", + }, + { + SQLs: sqls( + "select d || b from binoptestids_i;", + ), + ExpErr: "operator '||' incompatible with type 'IDSET'", + }, + }, +} + +var binOpExprWithIDSetBool = TableTest{ + Table: tbl( + "binoptestids_b", + srcHdrs( + srcHdr("_id", fldTypeID), + srcHdr("b", fldTypeBool), + srcHdr("d", fldTypeIDSet), + ), + srcRows( + srcRow(int64(10), bool(true), []int64{20, 21}), + ), + ), + SQLTests: []SQLTest{ + { + SQLs: sqls( + "select d != b from binoptestids_b;", + ), + ExpErr: "types 'IDSET' and 'BOOL' are not equatable", + }, + { + SQLs: sqls( + "select d = b from binoptestids_b;", + ), + ExpErr: "types 'IDSET' and 'BOOL' are not equatable", + }, + { + SQLs: sqls( + "select d <= b from binoptestids_b;", + ), + ExpErr: "operator '<=' incompatible with type 'IDSET'", + }, + { + SQLs: sqls( + "select d >= b from binoptestids_b;", + ), + ExpErr: "operator '>=' incompatible with type 'IDSET'", + }, + { + SQLs: sqls( + "select d < b from binoptestids_b;", + ), + ExpErr: "operator '<' incompatible with type 'IDSET'", + }, + { + SQLs: sqls( + "select d > b from binoptestids_b;", + ), + ExpErr: "operator '>' incompatible with type 'IDSET'", + }, + { + SQLs: sqls( + "select d & b from binoptestids_b;", + ), + ExpErr: "operator '&' incompatible with type 'IDSET'", + }, + { + SQLs: sqls( + "select d | b from binoptestids_b;", + ), + ExpErr: "operator '|' incompatible with type 'IDSET'", + }, + { + SQLs: sqls( + "select d << b from binoptestids_b;", + ), + ExpErr: "operator '<<' incompatible with type 'IDSET'", + }, + { + SQLs: sqls( + "select d >> b from binoptestids_b;", + ), + ExpErr: "operator '>>' incompatible with type 'IDSET'", + }, + { + SQLs: sqls( + "select d + b from binoptestids_b;", + ), + ExpErr: "operator '+' incompatible with type 'IDSET'", + }, + { + SQLs: sqls( + "select d - b from binoptestids_b;", + ), + ExpErr: "operator '-' incompatible with type 'IDSET'", + }, + { + SQLs: sqls( + "select d * b from binoptestids_b;", + ), + ExpErr: "operator '*' incompatible with type 'IDSET'", + }, + { + SQLs: sqls( + "select d / b from binoptestids_b;", + ), + ExpErr: "operator '/' incompatible with type 'IDSET'", + }, + { + SQLs: sqls( + "select d % b from binoptestids_b;", + ), + ExpErr: "operator '%' incompatible with type 'IDSET'", + }, + { + SQLs: sqls( + "select d || b from binoptestids_b;", + ), + ExpErr: "operator '||' incompatible with type 'IDSET'", + }, + }, +} + +var binOpExprWithIDSetID = TableTest{ + Table: tbl( + "binoptestids_id", + srcHdrs( + srcHdr("_id", fldTypeID), + srcHdr("b", fldTypeID), + srcHdr("d", fldTypeIDSet), + ), + srcRows( + srcRow(int64(10), int64(20), []int64{20, 21}), + ), + ), + SQLTests: []SQLTest{ + { + SQLs: sqls( + "select d != b from binoptestids_id;", + ), + ExpErr: "types 'IDSET' and 'ID' are not equatable", + }, + { + SQLs: sqls( + "select d = b from binoptestids_id;", + ), + ExpErr: "types 'IDSET' and 'ID' are not equatable", + }, + { + SQLs: sqls( + "select d <= b from binoptestids_id;", + ), + ExpErr: "operator '<=' incompatible with type 'IDSET'", + }, + { + SQLs: sqls( + "select d >= b from binoptestids_id;", + ), + ExpErr: "operator '>=' incompatible with type 'IDSET'", + }, + { + SQLs: sqls( + "select d < b from binoptestids_id;", + ), + ExpErr: "operator '<' incompatible with type 'IDSET'", + }, + { + SQLs: sqls( + "select d > b from binoptestids_id;", + ), + ExpErr: "operator '>' incompatible with type 'IDSET'", + }, + { + SQLs: sqls( + "select d & b from binoptestids_id;", + ), + ExpErr: "operator '&' incompatible with type 'IDSET'", + }, + { + SQLs: sqls( + "select d | b from binoptestids_id;", + ), + ExpErr: "operator '|' incompatible with type 'IDSET'", + }, + { + SQLs: sqls( + "select d << b from binoptestids_id;", + ), + ExpErr: "operator '<<' incompatible with type 'IDSET'", + }, + { + SQLs: sqls( + "select d >> b from binoptestids_id;", + ), + ExpErr: "operator '>>' incompatible with type 'IDSET'", + }, + { + SQLs: sqls( + "select d + b from binoptestids_id;", + ), + ExpErr: "operator '+' incompatible with type 'IDSET'", + }, + { + SQLs: sqls( + "select d - b from binoptestids_id;", + ), + ExpErr: "operator '-' incompatible with type 'IDSET'", + }, + { + SQLs: sqls( + "select d * b from binoptestids_id;", + ), + ExpErr: "operator '*' incompatible with type 'IDSET'", + }, + { + SQLs: sqls( + "select d / b from binoptestids_id;", + ), + ExpErr: "operator '/' incompatible with type 'IDSET'", + }, + { + SQLs: sqls( + "select d % b from binoptestids_id;", + ), + ExpErr: "operator '%' incompatible with type 'IDSET'", + }, + { + SQLs: sqls( + "select d || b from binoptestids_id;", + ), + ExpErr: "operator '||' incompatible with type 'IDSET'", + }, + }, +} + +var binOpExprWithIDSetDecimal = TableTest{ + Table: tbl( + "binoptestids_d", + srcHdrs( + srcHdr("_id", fldTypeID), + srcHdr("a", fldTypeIDSet), + srcHdr("d", fldTypeDecimal2), + ), + srcRows( + srcRow(int64(1), []int64{20, 21}, float64(12.34)), + ), + ), + SQLTests: []SQLTest{ + { + SQLs: sqls( + "select a != d from binoptestids_d;", + ), + ExpErr: "types 'IDSET' and 'DECIMAL(2)' are not equatable", + }, + { + SQLs: sqls( + "select a = d from binoptestids_d;", + ), + ExpErr: "types 'IDSET' and 'DECIMAL(2)' are not equatable", + }, + { + SQLs: sqls( + "select a <= d from binoptestids_d;", + ), + ExpErr: "operator '<=' incompatible with type 'IDSET'", + }, + { + SQLs: sqls( + "select a >= d from binoptestids_d;", + ), + ExpErr: "operator '>=' incompatible with type 'IDSET'", + }, + { + SQLs: sqls( + "select a < d from binoptestids_d;", + ), + ExpErr: "operator '<' incompatible with type 'IDSET'", + }, + { + SQLs: sqls( + "select a > d from binoptestids_d;", + ), + ExpErr: "operator '>' incompatible with type 'IDSET'", + }, + { + SQLs: sqls( + "select a & d from binoptestids_d;", + ), + ExpErr: "operator '&' incompatible with type 'IDSET'", + }, + { + SQLs: sqls( + "select a | d from binoptestids_d;", + ), + ExpErr: "operator '|' incompatible with type 'IDSET'", + }, + { + SQLs: sqls( + "select a << d from binoptestids_d;", + ), + ExpErr: "operator '<<' incompatible with type 'IDSET'", + }, + { + SQLs: sqls( + "select a >> d from binoptestids_d;", + ), + ExpErr: "operator '>>' incompatible with type 'IDSET'", + }, + { + SQLs: sqls( + "select a + d from binoptestids_d;", + ), + ExpErr: "operator '+' incompatible with type 'IDSET'", + }, + { + SQLs: sqls( + "select a - d from binoptestids_d;", + ), + ExpErr: "operator '-' incompatible with type 'IDSET'", + }, + { + SQLs: sqls( + "select a * d from binoptestids_d;", + ), + ExpErr: "operator '*' incompatible with type 'IDSET'", + }, + { + SQLs: sqls( + "select a / d from binoptestids_d;", + ), + ExpErr: "operator '/' incompatible with type 'IDSET'", + }, + { + SQLs: sqls( + "select a % d from binoptestids_d;", + ), + ExpErr: "operator '%' incompatible with type 'IDSET'", + }, + { + SQLs: sqls( + "select a || d from binoptestids_d;", + ), + ExpErr: "operator '||' incompatible with type 'IDSET'", + }, + }, +} + +var binOpExprWithIDSetTimestamp = TableTest{ + Table: tbl( + "binoptestids_ts", + srcHdrs( + srcHdr("_id", fldTypeID), + srcHdr("a", fldTypeIDSet), + srcHdr("ts", fldTypeTimestamp), + ), + srcRows( + srcRow(int64(1), []int64{20, 21}, time.Time(knownTimestamp())), + ), + ), + SQLTests: []SQLTest{ + { + SQLs: sqls( + "select a != ts from binoptestids_ts;", + ), + ExpErr: "types 'IDSET' and 'TIMESTAMP' are not equatable", + }, + { + SQLs: sqls( + "select a = ts from binoptestids_ts;", + ), + ExpErr: "types 'IDSET' and 'TIMESTAMP' are not equatable", + }, + { + SQLs: sqls( + "select a <= ts from binoptestids_ts;", + ), + ExpErr: " operator '<=' incompatible with type 'IDSET'", + }, + { + SQLs: sqls( + "select a >= ts from binoptestids_ts;", + ), + ExpErr: " operator '>=' incompatible with type 'IDSET'", + }, + { + SQLs: sqls( + "select a < ts from binoptestids_ts;", + ), + ExpErr: " operator '<' incompatible with type 'IDSET'", + }, + { + SQLs: sqls( + "select a > ts from binoptestids_ts;", + ), + ExpErr: " operator '>' incompatible with type 'IDSET'", + }, + { + SQLs: sqls( + "select a & ts from binoptestids_ts;", + ), + ExpErr: "operator '&' incompatible with type 'IDSET'", + }, + { + SQLs: sqls( + "select a | ts from binoptestids_ts;", + ), + ExpErr: "operator '|' incompatible with type 'IDSET'", + }, + { + SQLs: sqls( + "select a << ts from binoptestids_ts;", + ), + ExpErr: "operator '<<' incompatible with type 'IDSET'", + }, + { + SQLs: sqls( + "select a >> ts from binoptestids_ts;", + ), + ExpErr: "operator '>>' incompatible with type 'IDSET'", + }, + { + SQLs: sqls( + "select a + ts from binoptestids_ts;", + ), + ExpErr: "operator '+' incompatible with type 'IDSET'", + }, + { + SQLs: sqls( + "select a - ts from binoptestids_ts;", + ), + ExpErr: "operator '-' incompatible with type 'IDSET'", + }, + { + SQLs: sqls( + "select a * ts from binoptestids_ts;", + ), + ExpErr: "operator '*' incompatible with type 'IDSET'", + }, + { + SQLs: sqls( + "select a / ts from binoptestids_ts;", + ), + ExpErr: "operator '/' incompatible with type 'IDSET'", + }, + { + SQLs: sqls( + "select a % ts from binoptestids_ts;", + ), + ExpErr: "operator '%' incompatible with type 'IDSET'", + }, + { + SQLs: sqls( + "select a || ts from binoptestids_ts;", + ), + ExpErr: "operator '||' incompatible with type 'IDSET'", + }, + }, +} + +var binOpExprWithIDSetIDSet = TableTest{ + Table: tbl( + "binoptestids_ids", + srcHdrs( + srcHdr("_id", fldTypeID), + srcHdr("a", fldTypeIDSet), + srcHdr("b", fldTypeIDSet), + ), + srcRows( + srcRow(int64(1), []int64{101, 103}, []int64{101, 102}), + ), + ), + SQLTests: []SQLTest{ + { + SQLs: sqls( + "select a != b from binoptestids_ids;", + ), + ExpHdrs: hdrs( + hdr("", fldTypeBool), + ), + ExpRows: rows( + row(bool(true)), + ), + Compare: CompareExactUnordered, + }, + { + SQLs: sqls( + "select a = b from binoptestids_ids;", + ), + ExpHdrs: hdrs( + hdr("", fldTypeBool), + ), + ExpRows: rows( + row(bool(false)), + ), + Compare: CompareExactUnordered, + }, + { + SQLs: sqls( + "select a <= b from binoptestids_ids;", + ), + ExpErr: " operator '<=' incompatible with type 'IDSET'", + }, + { + SQLs: sqls( + "select a >= b from binoptestids_ids;", + ), + ExpErr: " operator '>=' incompatible with type 'IDSET'", + }, + { + SQLs: sqls( + "select a < b from binoptestids_ids;", + ), + ExpErr: " operator '<' incompatible with type 'IDSET'", + }, + { + SQLs: sqls( + "select a > b from binoptestids_ids;", + ), + ExpErr: " operator '>' incompatible with type 'IDSET'", + }, + { + SQLs: sqls( + "select a & b from binoptestids_ids;", + ), + ExpErr: " operator '&' incompatible with type 'IDSET'", + }, + { + SQLs: sqls( + "select a | b from binoptestids_ids;", + ), + ExpErr: " operator '|' incompatible with type 'IDSET'", + }, + { + SQLs: sqls( + "select a << b from binoptestids_ids;", + ), + ExpErr: " operator '<<' incompatible with type 'IDSET'", + }, + { + SQLs: sqls( + "select a >> b from binoptestids_ids;", + ), + ExpErr: " operator '>>' incompatible with type 'IDSET'", + }, + { + SQLs: sqls( + "select a + b from binoptestids_ids;", + ), + ExpErr: " operator '+' incompatible with type 'IDSET'", + }, + { + SQLs: sqls( + "select a - b from binoptestids_ids;", + ), + ExpErr: " operator '-' incompatible with type 'IDSET'", + }, + { + SQLs: sqls( + "select a * b from binoptestids_ids;", + ), + ExpErr: " operator '*' incompatible with type 'IDSET'", + }, + { + SQLs: sqls( + "select a / b from binoptestids_ids;", + ), + ExpErr: " operator '/' incompatible with type 'IDSET'", + }, + { + SQLs: sqls( + "select a % b from binoptestids_ids;", + ), + ExpErr: " operator '%' incompatible with type 'IDSET'", + }, + { + SQLs: sqls( + "select a || b from binoptestids_ids;", + ), + ExpErr: "operator '||' incompatible with type 'IDSET'", + }, + }, +} + +var binOpExprWithIDSetString = TableTest{ + Table: tbl( + "binoptestids_s", + srcHdrs( + srcHdr("_id", fldTypeID), + srcHdr("a", fldTypeIDSet), + srcHdr("b", fldTypeString), + ), + srcRows( + srcRow(int64(1), []int64{101, 102}, string("101")), + ), + ), + SQLTests: []SQLTest{ + { + SQLs: sqls( + "select a != b from binoptestids_s;", + ), + ExpErr: "types 'IDSET' and 'STRING' are not equatable", + }, + { + SQLs: sqls( + "select a = b from binoptestids_s;", + ), + ExpErr: "types 'IDSET' and 'STRING' are not equatable", + }, + { + SQLs: sqls( + "select a <= b from binoptestids_s;", + ), + ExpErr: " operator '<=' incompatible with type 'IDSET'", + }, + { + SQLs: sqls( + "select a >= b from binoptestids_s;", + ), + ExpErr: " operator '>=' incompatible with type 'IDSET'", + }, + { + SQLs: sqls( + "select a < b from binoptestids_s;", + ), + ExpErr: " operator '<' incompatible with type 'IDSET'", + }, + { + SQLs: sqls( + "select a > b from binoptestids_s;", + ), + ExpErr: " operator '>' incompatible with type 'IDSET'", + }, + { + SQLs: sqls( + "select a & b from binoptestids_s;", + ), + ExpErr: " operator '&' incompatible with type 'IDSET'", + }, + { + SQLs: sqls( + "select a | b from binoptestids_s;", + ), + ExpErr: " operator '|' incompatible with type 'IDSET'", + }, + { + SQLs: sqls( + "select a << b from binoptestids_s;", + ), + ExpErr: " operator '<<' incompatible with type 'IDSET'", + }, + { + SQLs: sqls( + "select a >> b from binoptestids_s;", + ), + ExpErr: " operator '>>' incompatible with type 'IDSET'", + }, + { + SQLs: sqls( + "select a + b from binoptestids_s;", + ), + ExpErr: " operator '+' incompatible with type 'IDSET'", + }, + { + SQLs: sqls( + "select a - b from binoptestids_s;", + ), + ExpErr: " operator '-' incompatible with type 'IDSET'", + }, + { + SQLs: sqls( + "select a * b from binoptestids_s;", + ), + ExpErr: " operator '*' incompatible with type 'IDSET'", + }, + { + SQLs: sqls( + "select a / b from binoptestids_s;", + ), + ExpErr: " operator '/' incompatible with type 'IDSET'", + }, + { + SQLs: sqls( + "select a % b from binoptestids_s;", + ), + ExpErr: " operator '%' incompatible with type 'IDSET'", + }, + { + SQLs: sqls( + "select a || b from binoptestids_s;", + ), + ExpErr: "operator '||' incompatible with type 'IDSET'", + }, + }, +} + +var binOpExprWithIDSetStringSet = TableTest{ + Table: tbl( + "binoptestids_ss", + srcHdrs( + srcHdr("_id", fldTypeID), + srcHdr("a", fldTypeIDSet), + srcHdr("b", fldTypeStringSet), + ), + srcRows( + srcRow(int64(1), []int64{102, 103}, []string{"101", "102"}), + ), + ), + SQLTests: []SQLTest{ + { + SQLs: sqls( + "select a != b from binoptestids_ss;", + ), + ExpErr: "types 'IDSET' and 'STRINGSET' are not equatable", + }, + { + SQLs: sqls( + "select a = b from binoptestids_ss;", + ), + ExpErr: "types 'IDSET' and 'STRINGSET' are not equatable", + }, + { + SQLs: sqls( + "select a <= b from binoptestids_ss;", + ), + ExpErr: " operator '<=' incompatible with type 'IDSET'", + }, + { + SQLs: sqls( + "select a >= b from binoptestids_ss;", + ), + ExpErr: " operator '>=' incompatible with type 'IDSET'", + }, + { + SQLs: sqls( + "select a < b from binoptestids_ss;", + ), + ExpErr: " operator '<' incompatible with type 'IDSET'", + }, + { + SQLs: sqls( + "select a > b from binoptestids_ss;", + ), + ExpErr: " operator '>' incompatible with type 'IDSET'", + }, + { + SQLs: sqls( + "select a & b from binoptestids_ss;", + ), + ExpErr: " operator '&' incompatible with type 'IDSET'", + }, + { + SQLs: sqls( + "select a | b from binoptestids_ss;", + ), + ExpErr: " operator '|' incompatible with type 'IDSET'", + }, + { + SQLs: sqls( + "select a << b from binoptestids_ss;", + ), + ExpErr: " operator '<<' incompatible with type 'IDSET'", + }, + { + SQLs: sqls( + "select a >> b from binoptestids_ss;", + ), + ExpErr: " operator '>>' incompatible with type 'IDSET'", + }, + { + SQLs: sqls( + "select a + b from binoptestids_ss;", + ), + ExpErr: " operator '+' incompatible with type 'IDSET'", + }, + { + SQLs: sqls( + "select a - b from binoptestids_ss;", + ), + ExpErr: " operator '-' incompatible with type 'IDSET'", + }, + { + SQLs: sqls( + "select a * b from binoptestids_ss;", + ), + ExpErr: " operator '*' incompatible with type 'IDSET'", + }, + { + SQLs: sqls( + "select a / b from binoptestids_ss;", + ), + ExpErr: " operator '/' incompatible with type 'IDSET'", + }, + { + SQLs: sqls( + "select a % b from binoptestids_ss;", + ), + ExpErr: " operator '%' incompatible with type 'IDSET'", + }, + { + SQLs: sqls( + "select a || b from binoptestids_ss;", + ), + ExpErr: "operator '||' incompatible with type 'IDSET'", + }, + }, +} + +// STRING bin op tests +var binOpExprWithStringInt = TableTest{ + Table: tbl( + "binoptests_i", + srcHdrs( + srcHdr("_id", fldTypeID), + srcHdr("b", fldTypeInt), + srcHdr("d", fldTypeString), + ), + srcRows( + srcRow(int64(10), int64(20), string("foo")), + ), + ), + SQLTests: []SQLTest{ + { + SQLs: sqls( + "select d != b from binoptests_i;", + ), + ExpErr: "types 'STRING' and 'INT' are not equatable", + }, + { + SQLs: sqls( + "select d = b from binoptests_i;", + ), + ExpErr: "types 'STRING' and 'INT' are not equatable", + }, + { + SQLs: sqls( + "select d <= b from binoptests_i;", + ), + ExpErr: "operator '<=' incompatible with type 'STRING'", + }, + { + SQLs: sqls( + "select d >= b from binoptests_i;", + ), + ExpErr: "operator '>=' incompatible with type 'STRING'", + }, + { + SQLs: sqls( + "select d < b from binoptests_i;", + ), + ExpErr: "operator '<' incompatible with type 'STRING'", + }, + { + SQLs: sqls( + "select d > b from binoptests_i;", + ), + ExpErr: "operator '>' incompatible with type 'STRING'", + }, + { + SQLs: sqls( + "select d & b from binoptests_i;", + ), + ExpErr: "operator '&' incompatible with type 'STRING'", + }, + { + SQLs: sqls( + "select d | b from binoptests_i;", + ), + ExpErr: "operator '|' incompatible with type 'STRING'", + }, + { + SQLs: sqls( + "select d << b from binoptests_i;", + ), + ExpErr: "operator '<<' incompatible with type 'STRING'", + }, + { + SQLs: sqls( + "select d >> b from binoptests_i;", + ), + ExpErr: "operator '>>' incompatible with type 'STRING'", + }, + { + SQLs: sqls( + "select d + b from binoptests_i;", + ), + ExpErr: "operator '+' incompatible with type 'STRING'", + }, + { + SQLs: sqls( + "select d - b from binoptests_i;", + ), + ExpErr: "operator '-' incompatible with type 'STRING'", + }, + { + SQLs: sqls( + "select d * b from binoptests_i;", + ), + ExpErr: "operator '*' incompatible with type 'STRING'", + }, + { + SQLs: sqls( + "select d / b from binoptests_i;", + ), + ExpErr: "operator '/' incompatible with type 'STRING'", + }, + { + SQLs: sqls( + "select d % b from binoptests_i;", + ), + ExpErr: "operator '%' incompatible with type 'STRING'", + }, + { + SQLs: sqls( + "select d || b from binoptests_i;", + ), + ExpErr: "operator '||' incompatible with type 'INT'", + }, + }, +} + +var binOpExprWithStringBool = TableTest{ + Table: tbl( + "binoptests_b", + srcHdrs( + srcHdr("_id", fldTypeID), + srcHdr("b", fldTypeBool), + srcHdr("d", fldTypeString), + ), + srcRows( + srcRow(int64(10), bool(true), string("foo")), + ), + ), + SQLTests: []SQLTest{ + { + SQLs: sqls( + "select d != b from binoptests_b;", + ), + ExpErr: "types 'STRING' and 'BOOL' are not equatable", + }, + { + SQLs: sqls( + "select d = b from binoptests_b;", + ), + ExpErr: "types 'STRING' and 'BOOL' are not equatable", + }, + { + SQLs: sqls( + "select d <= b from binoptests_b;", + ), + ExpErr: "operator '<=' incompatible with type 'STRING'", + }, + { + SQLs: sqls( + "select d >= b from binoptests_b;", + ), + ExpErr: "operator '>=' incompatible with type 'STRING'", + }, + { + SQLs: sqls( + "select d < b from binoptests_b;", + ), + ExpErr: "operator '<' incompatible with type 'STRING'", + }, + { + SQLs: sqls( + "select d > b from binoptests_b;", + ), + ExpErr: "operator '>' incompatible with type 'STRING'", + }, + { + SQLs: sqls( + "select d & b from binoptests_b;", + ), + ExpErr: "operator '&' incompatible with type 'STRING'", + }, + { + SQLs: sqls( + "select d | b from binoptests_b;", + ), + ExpErr: "operator '|' incompatible with type 'STRING'", + }, + { + SQLs: sqls( + "select d << b from binoptests_b;", + ), + ExpErr: "operator '<<' incompatible with type 'STRING'", + }, + { + SQLs: sqls( + "select d >> b from binoptests_b;", + ), + ExpErr: "operator '>>' incompatible with type 'STRING'", + }, + { + SQLs: sqls( + "select d + b from binoptests_b;", + ), + ExpErr: "operator '+' incompatible with type 'STRING'", + }, + { + SQLs: sqls( + "select d - b from binoptests_b;", + ), + ExpErr: "operator '-' incompatible with type 'STRING'", + }, + { + SQLs: sqls( + "select d * b from binoptests_b;", + ), + ExpErr: "operator '*' incompatible with type 'STRING'", + }, + { + SQLs: sqls( + "select d / b from binoptests_b;", + ), + ExpErr: "operator '/' incompatible with type 'STRING'", + }, + { + SQLs: sqls( + "select d % b from binoptests_b;", + ), + ExpErr: "operator '%' incompatible with type 'STRING'", + }, + { + SQLs: sqls( + "select d || b from binoptests_b;", + ), + ExpErr: "operator '||' incompatible with type 'BOOL'", + }, + }, +} + +var binOpExprWithStringID = TableTest{ + Table: tbl( + "binoptests_id", + srcHdrs( + srcHdr("_id", fldTypeID), + srcHdr("b", fldTypeID), + srcHdr("d", fldTypeString), + ), + srcRows( + srcRow(int64(10), int64(20), string("foo")), + ), + ), + SQLTests: []SQLTest{ + { + SQLs: sqls( + "select d != b from binoptests_id;", + ), + ExpErr: "types 'STRING' and 'ID' are not equatable", + }, + { + SQLs: sqls( + "select d = b from binoptests_id;", + ), + ExpErr: "types 'STRING' and 'ID' are not equatable", + }, + { + SQLs: sqls( + "select d <= b from binoptests_id;", + ), + ExpErr: "operator '<=' incompatible with type 'STRING'", + }, + { + SQLs: sqls( + "select d >= b from binoptests_id;", + ), + ExpErr: "operator '>=' incompatible with type 'STRING'", + }, + { + SQLs: sqls( + "select d < b from binoptests_id;", + ), + ExpErr: "operator '<' incompatible with type 'STRING'", + }, + { + SQLs: sqls( + "select d > b from binoptests_id;", + ), + ExpErr: "operator '>' incompatible with type 'STRING'", + }, + { + SQLs: sqls( + "select d & b from binoptests_id;", + ), + ExpErr: "operator '&' incompatible with type 'STRING'", + }, + { + SQLs: sqls( + "select d | b from binoptests_id;", + ), + ExpErr: "operator '|' incompatible with type 'STRING'", + }, + { + SQLs: sqls( + "select d << b from binoptests_id;", + ), + ExpErr: "operator '<<' incompatible with type 'STRING'", + }, + { + SQLs: sqls( + "select d >> b from binoptests_id;", + ), + ExpErr: "operator '>>' incompatible with type 'STRING'", + }, + { + SQLs: sqls( + "select d + b from binoptests_id;", + ), + ExpErr: "operator '+' incompatible with type 'STRING'", + }, + { + SQLs: sqls( + "select d - b from binoptests_id;", + ), + ExpErr: "operator '-' incompatible with type 'STRING'", + }, + { + SQLs: sqls( + "select d * b from binoptests_id;", + ), + ExpErr: "operator '*' incompatible with type 'STRING'", + }, + { + SQLs: sqls( + "select d / b from binoptests_id;", + ), + ExpErr: "operator '/' incompatible with type 'STRING'", + }, + { + SQLs: sqls( + "select d % b from binoptests_id;", + ), + ExpErr: "operator '%' incompatible with type 'STRING'", + }, + { + SQLs: sqls( + "select d || b from binoptests_id;", + ), + ExpErr: "operator '||' incompatible with type 'ID'", + }, + }, +} + +var binOpExprWithStringDecimal = TableTest{ + Table: tbl( + "binoptests_d", + srcHdrs( + srcHdr("_id", fldTypeID), + srcHdr("a", fldTypeString), + srcHdr("d", fldTypeDecimal2), + ), + srcRows( + srcRow(int64(1), string("foo"), float64(12.34)), + ), + ), + SQLTests: []SQLTest{ + { + SQLs: sqls( + "select a != d from binoptests_d;", + ), + ExpErr: "types 'STRING' and 'DECIMAL(2)' are not equatable", + }, + { + SQLs: sqls( + "select a = d from binoptests_d;", + ), + ExpErr: "types 'STRING' and 'DECIMAL(2)' are not equatable", + }, + { + SQLs: sqls( + "select a <= d from binoptests_d;", + ), + ExpErr: "operator '<=' incompatible with type 'STRING'", + }, + { + SQLs: sqls( + "select a >= d from binoptests_d;", + ), + ExpErr: "operator '>=' incompatible with type 'STRING'", + }, + { + SQLs: sqls( + "select a < d from binoptests_d;", + ), + ExpErr: "operator '<' incompatible with type 'STRING'", + }, + { + SQLs: sqls( + "select a > d from binoptests_d;", + ), + ExpErr: "operator '>' incompatible with type 'STRING'", + }, + { + SQLs: sqls( + "select a & d from binoptests_d;", + ), + ExpErr: "operator '&' incompatible with type 'STRING'", + }, + { + SQLs: sqls( + "select a | d from binoptests_d;", + ), + ExpErr: "operator '|' incompatible with type 'STRING'", + }, + { + SQLs: sqls( + "select a << d from binoptests_d;", + ), + ExpErr: "operator '<<' incompatible with type 'STRING'", + }, + { + SQLs: sqls( + "select a >> d from binoptests_d;", + ), + ExpErr: "operator '>>' incompatible with type 'STRING'", + }, + { + SQLs: sqls( + "select a + d from binoptests_d;", + ), + ExpErr: "operator '+' incompatible with type 'STRING'", + }, + { + SQLs: sqls( + "select a - d from binoptests_d;", + ), + ExpErr: "operator '-' incompatible with type 'STRING'", + }, + { + SQLs: sqls( + "select a * d from binoptests_d;", + ), + ExpErr: "operator '*' incompatible with type 'STRING'", + }, + { + SQLs: sqls( + "select a / d from binoptests_d;", + ), + ExpErr: "operator '/' incompatible with type 'STRING'", + }, + { + SQLs: sqls( + "select a % d from binoptests_d;", + ), + ExpErr: "operator '%' incompatible with type 'STRING'", + }, + { + SQLs: sqls( + "select a || d from binoptests_d;", + ), + ExpErr: "operator '||' incompatible with type 'DECIMAL(2)'", + }, + }, +} + +var binOpExprWithStringTimestamp = TableTest{ + Table: tbl( + "binoptests_ts", + srcHdrs( + srcHdr("_id", fldTypeID), + srcHdr("a", fldTypeString), + srcHdr("ts", fldTypeTimestamp), + ), + srcRows( + srcRow(int64(1), string("foo"), time.Time(knownTimestamp())), + ), + ), + SQLTests: []SQLTest{ + { + SQLs: sqls( + "select a != ts from binoptests_ts;", + ), + ExpErr: "types 'STRING' and 'TIMESTAMP' are not equatable", + }, + { + SQLs: sqls( + "select a = ts from binoptests_ts;", + ), + ExpErr: "types 'STRING' and 'TIMESTAMP' are not equatable", + }, + { + SQLs: sqls( + "select a <= ts from binoptests_ts;", + ), + ExpErr: " operator '<=' incompatible with type 'STRING'", + }, + { + SQLs: sqls( + "select a >= ts from binoptests_ts;", + ), + ExpErr: " operator '>=' incompatible with type 'STRING'", + }, + { + SQLs: sqls( + "select a < ts from binoptests_ts;", + ), + ExpErr: " operator '<' incompatible with type 'STRING'", + }, + { + SQLs: sqls( + "select a > ts from binoptests_ts;", + ), + ExpErr: " operator '>' incompatible with type 'STRING'", + }, + { + SQLs: sqls( + "select a & ts from binoptests_ts;", + ), + ExpErr: "operator '&' incompatible with type 'STRING'", + }, + { + SQLs: sqls( + "select a | ts from binoptests_ts;", + ), + ExpErr: "operator '|' incompatible with type 'STRING'", + }, + { + SQLs: sqls( + "select a << ts from binoptests_ts;", + ), + ExpErr: "operator '<<' incompatible with type 'STRING'", + }, + { + SQLs: sqls( + "select a >> ts from binoptests_ts;", + ), + ExpErr: "operator '>>' incompatible with type 'STRING'", + }, + { + SQLs: sqls( + "select a + ts from binoptests_ts;", + ), + ExpErr: "operator '+' incompatible with type 'STRING'", + }, + { + SQLs: sqls( + "select a - ts from binoptests_ts;", + ), + ExpErr: "operator '-' incompatible with type 'STRING'", + }, + { + SQLs: sqls( + "select a * ts from binoptests_ts;", + ), + ExpErr: "operator '*' incompatible with type 'STRING'", + }, + { + SQLs: sqls( + "select a / ts from binoptests_ts;", + ), + ExpErr: "operator '/' incompatible with type 'STRING'", + }, + { + SQLs: sqls( + "select a % ts from binoptests_ts;", + ), + ExpErr: "operator '%' incompatible with type 'STRING'", + }, + { + SQLs: sqls( + "select a || ts from binoptests_ts;", + ), + ExpErr: "operator '||' incompatible with type 'TIMESTAMP'", + }, + }, +} + +var binOpExprWithStringIDSet = TableTest{ + Table: tbl( + "binoptests_ids", + srcHdrs( + srcHdr("_id", fldTypeID), + srcHdr("a", fldTypeString), + srcHdr("b", fldTypeIDSet), + ), + srcRows( + srcRow(int64(1), string("foo"), []int64{101, 102}), + ), + ), + SQLTests: []SQLTest{ + { + SQLs: sqls( + "select a != b from binoptests_ids;", + ), + ExpErr: "types 'STRING' and 'IDSET' are not equatable", + }, + { + SQLs: sqls( + "select a = b from binoptests_ids;", + ), + ExpErr: "types 'STRING' and 'IDSET' are not equatable", + }, + { + SQLs: sqls( + "select a <= b from binoptests_ids;", + ), + ExpErr: " operator '<=' incompatible with type 'STRING'", + }, + { + SQLs: sqls( + "select a >= b from binoptests_ids;", + ), + ExpErr: " operator '>=' incompatible with type 'STRING'", + }, + { + SQLs: sqls( + "select a < b from binoptests_ids;", + ), + ExpErr: " operator '<' incompatible with type 'STRING'", + }, + { + SQLs: sqls( + "select a > b from binoptests_ids;", + ), + ExpErr: " operator '>' incompatible with type 'STRING'", + }, + { + SQLs: sqls( + "select a & b from binoptests_ids;", + ), + ExpErr: " operator '&' incompatible with type 'STRING'", + }, + { + SQLs: sqls( + "select a | b from binoptests_ids;", + ), + ExpErr: " operator '|' incompatible with type 'STRING'", + }, + { + SQLs: sqls( + "select a << b from binoptests_ids;", + ), + ExpErr: " operator '<<' incompatible with type 'STRING'", + }, + { + SQLs: sqls( + "select a >> b from binoptests_ids;", + ), + ExpErr: " operator '>>' incompatible with type 'STRING'", + }, + { + SQLs: sqls( + "select a + b from binoptests_ids;", + ), + ExpErr: " operator '+' incompatible with type 'STRING'", + }, + { + SQLs: sqls( + "select a - b from binoptests_ids;", + ), + ExpErr: " operator '-' incompatible with type 'STRING'", + }, + { + SQLs: sqls( + "select a * b from binoptests_ids;", + ), + ExpErr: " operator '*' incompatible with type 'STRING'", + }, + { + SQLs: sqls( + "select a / b from binoptests_ids;", + ), + ExpErr: " operator '/' incompatible with type 'STRING'", + }, + { + SQLs: sqls( + "select a % b from binoptests_ids;", + ), + ExpErr: " operator '%' incompatible with type 'STRING'", + }, + { + SQLs: sqls( + "select a || b from binoptests_ids;", + ), + ExpErr: "operator '||' incompatible with type 'IDSET'", + }, + }, +} + +var binOpExprWithStringString = TableTest{ + Table: tbl( + "binoptests_s", + srcHdrs( + srcHdr("_id", fldTypeID), + srcHdr("a", fldTypeString), + srcHdr("b", fldTypeString), + ), + srcRows( + srcRow(int64(1), string("foo"), string("101")), + ), + ), + SQLTests: []SQLTest{ + { + SQLs: sqls( + "select a != b from binoptests_s;", + ), + ExpHdrs: hdrs( + hdr("", fldTypeBool), + ), + ExpRows: rows( + row(bool(true)), + ), + Compare: CompareExactUnordered, + }, + { + SQLs: sqls( + "select a = b from binoptests_s;", + ), + ExpHdrs: hdrs( + hdr("", fldTypeBool), + ), + ExpRows: rows( + row(bool(false)), + ), + Compare: CompareExactUnordered, + }, + { + SQLs: sqls( + "select a <= b from binoptests_s;", + ), + ExpErr: " operator '<=' incompatible with type 'STRING'", + }, + { + SQLs: sqls( + "select a >= b from binoptests_s;", + ), + ExpErr: " operator '>=' incompatible with type 'STRING'", + }, + { + SQLs: sqls( + "select a < b from binoptests_s;", + ), + ExpErr: " operator '<' incompatible with type 'STRING'", + }, + { + SQLs: sqls( + "select a > b from binoptests_s;", + ), + ExpErr: " operator '>' incompatible with type 'STRING'", + }, + { + SQLs: sqls( + "select a & b from binoptests_s;", + ), + ExpErr: " operator '&' incompatible with type 'STRING'", + }, + { + SQLs: sqls( + "select a | b from binoptests_s;", + ), + ExpErr: " operator '|' incompatible with type 'STRING'", + }, + { + SQLs: sqls( + "select a << b from binoptests_s;", + ), + ExpErr: " operator '<<' incompatible with type 'STRING'", + }, + { + SQLs: sqls( + "select a >> b from binoptests_s;", + ), + ExpErr: " operator '>>' incompatible with type 'STRING'", + }, + { + SQLs: sqls( + "select a + b from binoptests_s;", + ), + ExpErr: " operator '+' incompatible with type 'STRING'", + }, + { + SQLs: sqls( + "select a - b from binoptests_s;", + ), + ExpErr: " operator '-' incompatible with type 'STRING'", + }, + { + SQLs: sqls( + "select a * b from binoptests_s;", + ), + ExpErr: " operator '*' incompatible with type 'STRING'", + }, + { + SQLs: sqls( + "select a / b from binoptests_s;", + ), + ExpErr: " operator '/' incompatible with type 'STRING'", + }, + { + SQLs: sqls( + "select a % b from binoptests_s;", + ), + ExpErr: " operator '%' incompatible with type 'STRING'", + }, + { + SQLs: sqls( + "select a || b from binoptests_s;", + ), + ExpHdrs: hdrs( + hdr("", fldTypeString), + ), + ExpRows: rows( + row(string("foo101")), + ), + Compare: CompareExactUnordered, + }, + }, +} + +var binOpExprWithStringStringSet = TableTest{ + Table: tbl( + "binoptests_ss", + srcHdrs( + srcHdr("_id", fldTypeID), + srcHdr("a", fldTypeString), + srcHdr("b", fldTypeStringSet), + ), + srcRows( + srcRow(int64(1), string("foo"), []string{"101", "102"}), + ), + ), + SQLTests: []SQLTest{ + { + SQLs: sqls( + "select a != b from binoptests_ss;", + ), + ExpErr: "types 'STRING' and 'STRINGSET' are not equatable", + }, + { + SQLs: sqls( + "select a = b from binoptests_ss;", + ), + ExpErr: "types 'STRING' and 'STRINGSET' are not equatable", + }, + { + SQLs: sqls( + "select a <= b from binoptests_ss;", + ), + ExpErr: " operator '<=' incompatible with type 'STRING'", + }, + { + SQLs: sqls( + "select a >= b from binoptests_ss;", + ), + ExpErr: " operator '>=' incompatible with type 'STRING'", + }, + { + SQLs: sqls( + "select a < b from binoptests_ss;", + ), + ExpErr: " operator '<' incompatible with type 'STRING'", + }, + { + SQLs: sqls( + "select a > b from binoptests_ss;", + ), + ExpErr: " operator '>' incompatible with type 'STRING'", + }, + { + SQLs: sqls( + "select a & b from binoptests_ss;", + ), + ExpErr: " operator '&' incompatible with type 'STRING'", + }, + { + SQLs: sqls( + "select a | b from binoptests_ss;", + ), + ExpErr: " operator '|' incompatible with type 'STRING'", + }, + { + SQLs: sqls( + "select a << b from binoptests_ss;", + ), + ExpErr: " operator '<<' incompatible with type 'STRING'", + }, + { + SQLs: sqls( + "select a >> b from binoptests_ss;", + ), + ExpErr: " operator '>>' incompatible with type 'STRING'", + }, + { + SQLs: sqls( + "select a + b from binoptests_ss;", + ), + ExpErr: " operator '+' incompatible with type 'STRING'", + }, + { + SQLs: sqls( + "select a - b from binoptests_ss;", + ), + ExpErr: " operator '-' incompatible with type 'STRING'", + }, + { + SQLs: sqls( + "select a * b from binoptests_ss;", + ), + ExpErr: " operator '*' incompatible with type 'STRING'", + }, + { + SQLs: sqls( + "select a / b from binoptests_ss;", + ), + ExpErr: " operator '/' incompatible with type 'STRING'", + }, + { + SQLs: sqls( + "select a % b from binoptests_ss;", + ), + ExpErr: " operator '%' incompatible with type 'STRING'", + }, + { + SQLs: sqls( + "select a || b from binoptests_ss;", + ), + ExpErr: "operator '||' incompatible with type 'STRINGSET'", + }, + }, +} + +// STRINGSET bin op tests +var binOpExprWithStringSetInt = TableTest{ + Table: tbl( + "binoptestss_i", + srcHdrs( + srcHdr("_id", fldTypeID), + srcHdr("b", fldTypeInt), + srcHdr("d", fldTypeStringSet), + ), + srcRows( + srcRow(int64(10), int64(20), []string{"20", "21"}), + ), + ), + SQLTests: []SQLTest{ + { + SQLs: sqls( + "select d != b from binoptestss_i;", + ), + ExpErr: "types 'STRINGSET' and 'INT' are not equatable", + }, + { + SQLs: sqls( + "select d = b from binoptestss_i;", + ), + ExpErr: "types 'STRINGSET' and 'INT' are not equatable", + }, + { + SQLs: sqls( + "select d <= b from binoptestss_i;", + ), + ExpErr: "operator '<=' incompatible with type 'STRINGSET'", + }, + { + SQLs: sqls( + "select d >= b from binoptestss_i;", + ), + ExpErr: "operator '>=' incompatible with type 'STRINGSET'", + }, + { + SQLs: sqls( + "select d < b from binoptestss_i;", + ), + ExpErr: "operator '<' incompatible with type 'STRINGSET'", + }, + { + SQLs: sqls( + "select d > b from binoptestss_i;", + ), + ExpErr: "operator '>' incompatible with type 'STRINGSET'", + }, + { + SQLs: sqls( + "select d & b from binoptestss_i;", + ), + ExpErr: "operator '&' incompatible with type 'STRINGSET'", + }, + { + SQLs: sqls( + "select d | b from binoptestss_i;", + ), + ExpErr: "operator '|' incompatible with type 'STRINGSET'", + }, + { + SQLs: sqls( + "select d << b from binoptestss_i;", + ), + ExpErr: "operator '<<' incompatible with type 'STRINGSET'", + }, + { + SQLs: sqls( + "select d >> b from binoptestss_i;", + ), + ExpErr: "operator '>>' incompatible with type 'STRINGSET'", + }, + { + SQLs: sqls( + "select d + b from binoptestss_i;", + ), + ExpErr: "operator '+' incompatible with type 'STRINGSET'", + }, + { + SQLs: sqls( + "select d - b from binoptestss_i;", + ), + ExpErr: "operator '-' incompatible with type 'STRINGSET'", + }, + { + SQLs: sqls( + "select d * b from binoptestss_i;", + ), + ExpErr: "operator '*' incompatible with type 'STRINGSET'", + }, + { + SQLs: sqls( + "select d / b from binoptestss_i;", + ), + ExpErr: "operator '/' incompatible with type 'STRINGSET'", + }, + { + SQLs: sqls( + "select d % b from binoptestss_i;", + ), + ExpErr: "operator '%' incompatible with type 'STRINGSET'", + }, + { + SQLs: sqls( + "select d || b from binoptestss_i;", + ), + ExpErr: "operator '||' incompatible with type 'STRINGSET'", + }, + }, +} + +var binOpExprWithStringSetBool = TableTest{ + Table: tbl( + "binoptestss_b", + srcHdrs( + srcHdr("_id", fldTypeID), + srcHdr("b", fldTypeBool), + srcHdr("d", fldTypeStringSet), + ), + srcRows( + srcRow(int64(10), bool(true), []string{"20", "21"}), + ), + ), + SQLTests: []SQLTest{ + { + SQLs: sqls( + "select d != b from binoptestss_b;", + ), + ExpErr: "types 'STRINGSET' and 'BOOL' are not equatable", + }, + { + SQLs: sqls( + "select d = b from binoptestss_b;", + ), + ExpErr: "types 'STRINGSET' and 'BOOL' are not equatable", + }, + { + SQLs: sqls( + "select d <= b from binoptestss_b;", + ), + ExpErr: "operator '<=' incompatible with type 'STRINGSET'", + }, + { + SQLs: sqls( + "select d >= b from binoptestss_b;", + ), + ExpErr: "operator '>=' incompatible with type 'STRINGSET'", + }, + { + SQLs: sqls( + "select d < b from binoptestss_b;", + ), + ExpErr: "operator '<' incompatible with type 'STRINGSET'", + }, + { + SQLs: sqls( + "select d > b from binoptestss_b;", + ), + ExpErr: "operator '>' incompatible with type 'STRINGSET'", + }, + { + SQLs: sqls( + "select d & b from binoptestss_b;", + ), + ExpErr: "operator '&' incompatible with type 'STRINGSET'", + }, + { + SQLs: sqls( + "select d | b from binoptestss_b;", + ), + ExpErr: "operator '|' incompatible with type 'STRINGSET'", + }, + { + SQLs: sqls( + "select d << b from binoptestss_b;", + ), + ExpErr: "operator '<<' incompatible with type 'STRINGSET'", + }, + { + SQLs: sqls( + "select d >> b from binoptestss_b;", + ), + ExpErr: "operator '>>' incompatible with type 'STRINGSET'", + }, + { + SQLs: sqls( + "select d + b from binoptestss_b;", + ), + ExpErr: "operator '+' incompatible with type 'STRINGSET'", + }, + { + SQLs: sqls( + "select d - b from binoptestss_b;", + ), + ExpErr: "operator '-' incompatible with type 'STRINGSET'", + }, + { + SQLs: sqls( + "select d * b from binoptestss_b;", + ), + ExpErr: "operator '*' incompatible with type 'STRINGSET'", + }, + { + SQLs: sqls( + "select d / b from binoptestss_b;", + ), + ExpErr: "operator '/' incompatible with type 'STRINGSET'", + }, + { + SQLs: sqls( + "select d % b from binoptestss_b;", + ), + ExpErr: "operator '%' incompatible with type 'STRINGSET'", + }, + { + SQLs: sqls( + "select d || b from binoptestss_b;", + ), + ExpErr: "operator '||' incompatible with type 'STRINGSET'", + }, + }, +} + +var binOpExprWithStringSetID = TableTest{ + Table: tbl( + "binoptestss_id", + srcHdrs( + srcHdr("_id", fldTypeID), + srcHdr("b", fldTypeID), + srcHdr("d", fldTypeStringSet), + ), + srcRows( + srcRow(int64(10), int64(20), []string{"20", "21"}), + ), + ), + SQLTests: []SQLTest{ + { + SQLs: sqls( + "select d != b from binoptestss_id;", + ), + ExpErr: "types 'STRINGSET' and 'ID' are not equatable", + }, + { + SQLs: sqls( + "select d = b from binoptestss_id;", + ), + ExpErr: "types 'STRINGSET' and 'ID' are not equatable", + }, + { + SQLs: sqls( + "select d <= b from binoptestss_id;", + ), + ExpErr: "operator '<=' incompatible with type 'STRINGSET'", + }, + { + SQLs: sqls( + "select d >= b from binoptestss_id;", + ), + ExpErr: "operator '>=' incompatible with type 'STRINGSET'", + }, + { + SQLs: sqls( + "select d < b from binoptestss_id;", + ), + ExpErr: "operator '<' incompatible with type 'STRINGSET'", + }, + { + SQLs: sqls( + "select d > b from binoptestss_id;", + ), + ExpErr: "operator '>' incompatible with type 'STRINGSET'", + }, + { + SQLs: sqls( + "select d & b from binoptestss_id;", + ), + ExpErr: "operator '&' incompatible with type 'STRINGSET'", + }, + { + SQLs: sqls( + "select d | b from binoptestss_id;", + ), + ExpErr: "operator '|' incompatible with type 'STRINGSET'", + }, + { + SQLs: sqls( + "select d << b from binoptestss_id;", + ), + ExpErr: "operator '<<' incompatible with type 'STRINGSET'", + }, + { + SQLs: sqls( + "select d >> b from binoptestss_id;", + ), + ExpErr: "operator '>>' incompatible with type 'STRINGSET'", + }, + { + SQLs: sqls( + "select d + b from binoptestss_id;", + ), + ExpErr: "operator '+' incompatible with type 'STRINGSET'", + }, + { + SQLs: sqls( + "select d - b from binoptestss_id;", + ), + ExpErr: "operator '-' incompatible with type 'STRINGSET'", + }, + { + SQLs: sqls( + "select d * b from binoptestss_id;", + ), + ExpErr: "operator '*' incompatible with type 'STRINGSET'", + }, + { + SQLs: sqls( + "select d / b from binoptestss_id;", + ), + ExpErr: "operator '/' incompatible with type 'STRINGSET'", + }, + { + SQLs: sqls( + "select d % b from binoptestss_id;", + ), + ExpErr: "operator '%' incompatible with type 'STRINGSET'", + }, + { + SQLs: sqls( + "select d || b from binoptestss_id;", + ), + ExpErr: "operator '||' incompatible with type 'STRINGSET'", + }, + }, +} + +var binOpExprWithStringSetDecimal = TableTest{ + Table: tbl( + "binoptestss_d", + srcHdrs( + srcHdr("_id", fldTypeID), + srcHdr("a", fldTypeStringSet), + srcHdr("d", fldTypeDecimal2), + ), + srcRows( + srcRow(int64(1), []string{"20", "21"}, float64(12.34)), + ), + ), + SQLTests: []SQLTest{ + { + SQLs: sqls( + "select a != d from binoptestss_d;", + ), + ExpErr: "types 'STRINGSET' and 'DECIMAL(2)' are not equatable", + }, + { + SQLs: sqls( + "select a = d from binoptestss_d;", + ), + ExpErr: "types 'STRINGSET' and 'DECIMAL(2)' are not equatable", + }, + { + SQLs: sqls( + "select a <= d from binoptestss_d;", + ), + ExpErr: "operator '<=' incompatible with type 'STRINGSET'", + }, + { + SQLs: sqls( + "select a >= d from binoptestss_d;", + ), + ExpErr: "operator '>=' incompatible with type 'STRINGSET'", + }, + { + SQLs: sqls( + "select a < d from binoptestss_d;", + ), + ExpErr: "operator '<' incompatible with type 'STRINGSET'", + }, + { + SQLs: sqls( + "select a > d from binoptestss_d;", + ), + ExpErr: "operator '>' incompatible with type 'STRINGSET'", + }, + { + SQLs: sqls( + "select a & d from binoptestss_d;", + ), + ExpErr: "operator '&' incompatible with type 'STRINGSET'", + }, + { + SQLs: sqls( + "select a | d from binoptestss_d;", + ), + ExpErr: "operator '|' incompatible with type 'STRINGSET'", + }, + { + SQLs: sqls( + "select a << d from binoptestss_d;", + ), + ExpErr: "operator '<<' incompatible with type 'STRINGSET'", + }, + { + SQLs: sqls( + "select a >> d from binoptestss_d;", + ), + ExpErr: "operator '>>' incompatible with type 'STRINGSET'", + }, + { + SQLs: sqls( + "select a + d from binoptestss_d;", + ), + ExpErr: "operator '+' incompatible with type 'STRINGSET'", + }, + { + SQLs: sqls( + "select a - d from binoptestss_d;", + ), + ExpErr: "operator '-' incompatible with type 'STRINGSET'", + }, + { + SQLs: sqls( + "select a * d from binoptestss_d;", + ), + ExpErr: "operator '*' incompatible with type 'STRINGSET'", + }, + { + SQLs: sqls( + "select a / d from binoptestss_d;", + ), + ExpErr: "operator '/' incompatible with type 'STRINGSET'", + }, + { + SQLs: sqls( + "select a % d from binoptestss_d;", + ), + ExpErr: "operator '%' incompatible with type 'STRINGSET'", + }, + { + SQLs: sqls( + "select a || d from binoptestss_d;", + ), + ExpErr: "operator '||' incompatible with type 'STRINGSET'", + }, + }, +} + +var binOpExprWithStringSetTimestamp = TableTest{ + Table: tbl( + "binoptestss_ts", + srcHdrs( + srcHdr("_id", fldTypeID), + srcHdr("a", fldTypeStringSet), + srcHdr("ts", fldTypeTimestamp), + ), + srcRows( + srcRow(int64(1), []string{"20", "21"}, time.Time(knownTimestamp())), + ), + ), + SQLTests: []SQLTest{ + { + SQLs: sqls( + "select a != ts from binoptestss_ts;", + ), + ExpErr: "types 'STRINGSET' and 'TIMESTAMP' are not equatable", + }, + { + SQLs: sqls( + "select a = ts from binoptestss_ts;", + ), + ExpErr: "types 'STRINGSET' and 'TIMESTAMP' are not equatable", + }, + { + SQLs: sqls( + "select a <= ts from binoptestss_ts;", + ), + ExpErr: " operator '<=' incompatible with type 'STRINGSET'", + }, + { + SQLs: sqls( + "select a >= ts from binoptestss_ts;", + ), + ExpErr: " operator '>=' incompatible with type 'STRINGSET'", + }, + { + SQLs: sqls( + "select a < ts from binoptestss_ts;", + ), + ExpErr: " operator '<' incompatible with type 'STRINGSET'", + }, + { + SQLs: sqls( + "select a > ts from binoptestss_ts;", + ), + ExpErr: " operator '>' incompatible with type 'STRINGSET'", + }, + { + SQLs: sqls( + "select a & ts from binoptestss_ts;", + ), + ExpErr: "operator '&' incompatible with type 'STRINGSET'", + }, + { + SQLs: sqls( + "select a | ts from binoptestss_ts;", + ), + ExpErr: "operator '|' incompatible with type 'STRINGSET'", + }, + { + SQLs: sqls( + "select a << ts from binoptestss_ts;", + ), + ExpErr: "operator '<<' incompatible with type 'STRINGSET'", + }, + { + SQLs: sqls( + "select a >> ts from binoptestss_ts;", + ), + ExpErr: "operator '>>' incompatible with type 'STRINGSET'", + }, + { + SQLs: sqls( + "select a + ts from binoptestss_ts;", + ), + ExpErr: "operator '+' incompatible with type 'STRINGSET'", + }, + { + SQLs: sqls( + "select a - ts from binoptestss_ts;", + ), + ExpErr: "operator '-' incompatible with type 'STRINGSET'", + }, + { + SQLs: sqls( + "select a * ts from binoptestss_ts;", + ), + ExpErr: "operator '*' incompatible with type 'STRINGSET'", + }, + { + SQLs: sqls( + "select a / ts from binoptestss_ts;", + ), + ExpErr: "operator '/' incompatible with type 'STRINGSET'", + }, + { + SQLs: sqls( + "select a % ts from binoptestss_ts;", + ), + ExpErr: "operator '%' incompatible with type 'STRINGSET'", + }, + { + SQLs: sqls( + "select a || ts from binoptestss_ts;", + ), + ExpErr: "operator '||' incompatible with type 'STRINGSET'", + }, + }, +} + +var binOpExprWithStringSetIDSet = TableTest{ + Table: tbl( + "binoptestss_ids", + srcHdrs( + srcHdr("_id", fldTypeID), + srcHdr("a", fldTypeStringSet), + srcHdr("b", fldTypeIDSet), + ), + srcRows( + srcRow(int64(1), []string{"101", "103"}, []int64{101, 102}), + ), + ), + SQLTests: []SQLTest{ + { + SQLs: sqls( + "select a != b from binoptestss_ids;", + ), + ExpErr: "types 'STRINGSET' and 'IDSET' are not equatable", + }, + { + SQLs: sqls( + "select a = b from binoptestss_ids;", + ), + ExpErr: "types 'STRINGSET' and 'IDSET' are not equatable", + }, + { + SQLs: sqls( + "select a <= b from binoptestss_ids;", + ), + ExpErr: " operator '<=' incompatible with type 'STRINGSET'", + }, + { + SQLs: sqls( + "select a >= b from binoptestss_ids;", + ), + ExpErr: " operator '>=' incompatible with type 'STRINGSET'", + }, + { + SQLs: sqls( + "select a < b from binoptestss_ids;", + ), + ExpErr: " operator '<' incompatible with type 'STRINGSET'", + }, + { + SQLs: sqls( + "select a > b from binoptestss_ids;", + ), + ExpErr: " operator '>' incompatible with type 'STRINGSET'", + }, + { + SQLs: sqls( + "select a & b from binoptestss_ids;", + ), + ExpErr: " operator '&' incompatible with type 'STRINGSET'", + }, + { + SQLs: sqls( + "select a | b from binoptestss_ids;", + ), + ExpErr: " operator '|' incompatible with type 'STRINGSET'", + }, + { + SQLs: sqls( + "select a << b from binoptestss_ids;", + ), + ExpErr: " operator '<<' incompatible with type 'STRINGSET'", + }, + { + SQLs: sqls( + "select a >> b from binoptestss_ids;", + ), + ExpErr: " operator '>>' incompatible with type 'STRINGSET'", + }, + { + SQLs: sqls( + "select a + b from binoptestss_ids;", + ), + ExpErr: " operator '+' incompatible with type 'STRINGSET'", + }, + { + SQLs: sqls( + "select a - b from binoptestss_ids;", + ), + ExpErr: " operator '-' incompatible with type 'STRINGSET'", + }, + { + SQLs: sqls( + "select a * b from binoptestss_ids;", + ), + ExpErr: " operator '*' incompatible with type 'STRINGSET'", + }, + { + SQLs: sqls( + "select a / b from binoptestss_ids;", + ), + ExpErr: " operator '/' incompatible with type 'STRINGSET'", + }, + { + SQLs: sqls( + "select a % b from binoptestss_ids;", + ), + ExpErr: " operator '%' incompatible with type 'STRINGSET'", + }, + { + SQLs: sqls( + "select a || b from binoptestss_ids;", + ), + ExpErr: "operator '||' incompatible with type 'STRINGSET'", + }, + }, +} + +var binOpExprWithStringSetString = TableTest{ + Table: tbl( + "binoptestss_s", + srcHdrs( + srcHdr("_id", fldTypeID), + srcHdr("a", fldTypeStringSet), + srcHdr("b", fldTypeString), + ), + srcRows( + srcRow(int64(1), []string{"101", "102"}, string("101")), + ), + ), + SQLTests: []SQLTest{ + { + SQLs: sqls( + "select a != b from binoptestss_s;", + ), + ExpErr: "types 'STRINGSET' and 'STRING' are not equatable", + }, + { + SQLs: sqls( + "select a = b from binoptestss_s;", + ), + ExpErr: "types 'STRINGSET' and 'STRING' are not equatable", + }, + { + SQLs: sqls( + "select a <= b from binoptestss_s;", + ), + ExpErr: " operator '<=' incompatible with type 'STRINGSET'", + }, + { + SQLs: sqls( + "select a >= b from binoptestss_s;", + ), + ExpErr: " operator '>=' incompatible with type 'STRINGSET'", + }, + { + SQLs: sqls( + "select a < b from binoptestss_s;", + ), + ExpErr: " operator '<' incompatible with type 'STRINGSET'", + }, + { + SQLs: sqls( + "select a > b from binoptestss_s;", + ), + ExpErr: " operator '>' incompatible with type 'STRINGSET'", + }, + { + SQLs: sqls( + "select a & b from binoptestss_s;", + ), + ExpErr: " operator '&' incompatible with type 'STRINGSET'", + }, + { + SQLs: sqls( + "select a | b from binoptestss_s;", + ), + ExpErr: " operator '|' incompatible with type 'STRINGSET'", + }, + { + SQLs: sqls( + "select a << b from binoptestss_s;", + ), + ExpErr: " operator '<<' incompatible with type 'STRINGSET'", + }, + { + SQLs: sqls( + "select a >> b from binoptestss_s;", + ), + ExpErr: " operator '>>' incompatible with type 'STRINGSET'", + }, + { + SQLs: sqls( + "select a + b from binoptestss_s;", + ), + ExpErr: " operator '+' incompatible with type 'STRINGSET'", + }, + { + SQLs: sqls( + "select a - b from binoptestss_s;", + ), + ExpErr: " operator '-' incompatible with type 'STRINGSET'", + }, + { + SQLs: sqls( + "select a * b from binoptestss_s;", + ), + ExpErr: " operator '*' incompatible with type 'STRINGSET'", + }, + { + SQLs: sqls( + "select a / b from binoptestss_s;", + ), + ExpErr: " operator '/' incompatible with type 'STRINGSET'", + }, + { + SQLs: sqls( + "select a % b from binoptestss_s;", + ), + ExpErr: " operator '%' incompatible with type 'STRINGSET'", + }, + { + SQLs: sqls( + "select a || b from binoptestss_s;", + ), + ExpErr: "operator '||' incompatible with type 'STRINGSET'", + }, + }, +} + +var binOpExprWithStringSetStringSet = TableTest{ + Table: tbl( + "binoptestss_ss", + srcHdrs( + srcHdr("_id", fldTypeID), + srcHdr("a", fldTypeStringSet), + srcHdr("b", fldTypeStringSet), + ), + srcRows( + srcRow(int64(1), []string{"102", "103"}, []string{"101", "102"}), + ), + ), + SQLTests: []SQLTest{ + { + SQLs: sqls( + "select a != b from binoptestss_ss;", + ), + ExpHdrs: hdrs( + hdr("", fldTypeBool), + ), + ExpRows: rows( + row(bool(true)), + ), + Compare: CompareExactUnordered, + }, + { + SQLs: sqls( + "select a = b from binoptestss_ss;", + ), + ExpHdrs: hdrs( + hdr("", fldTypeBool), + ), + ExpRows: rows( + row(bool(false)), + ), + Compare: CompareExactUnordered, + }, + { + SQLs: sqls( + "select a <= b from binoptestss_ss;", + ), + ExpErr: " operator '<=' incompatible with type 'STRINGSET'", + }, + { + SQLs: sqls( + "select a >= b from binoptestss_ss;", + ), + ExpErr: " operator '>=' incompatible with type 'STRINGSET'", + }, + { + SQLs: sqls( + "select a < b from binoptestss_ss;", + ), + ExpErr: " operator '<' incompatible with type 'STRINGSET'", + }, + { + SQLs: sqls( + "select a > b from binoptestss_ss;", + ), + ExpErr: " operator '>' incompatible with type 'STRINGSET'", + }, + { + SQLs: sqls( + "select a & b from binoptestss_ss;", + ), + ExpErr: " operator '&' incompatible with type 'STRINGSET'", + }, + { + SQLs: sqls( + "select a | b from binoptestss_ss;", + ), + ExpErr: " operator '|' incompatible with type 'STRINGSET'", + }, + { + SQLs: sqls( + "select a << b from binoptestss_ss;", + ), + ExpErr: " operator '<<' incompatible with type 'STRINGSET'", + }, + { + SQLs: sqls( + "select a >> b from binoptestss_ss;", + ), + ExpErr: " operator '>>' incompatible with type 'STRINGSET'", + }, + { + SQLs: sqls( + "select a + b from binoptestss_ss;", + ), + ExpErr: " operator '+' incompatible with type 'STRINGSET'", + }, + { + SQLs: sqls( + "select a - b from binoptestss_ss;", + ), + ExpErr: " operator '-' incompatible with type 'STRINGSET'", + }, + { + SQLs: sqls( + "select a * b from binoptestss_ss;", + ), + ExpErr: " operator '*' incompatible with type 'STRINGSET'", + }, + { + SQLs: sqls( + "select a / b from binoptestss_ss;", + ), + ExpErr: " operator '/' incompatible with type 'STRINGSET'", + }, + { + SQLs: sqls( + "select a % b from binoptestss_ss;", + ), + ExpErr: " operator '%' incompatible with type 'STRINGSET'", + }, + { + SQLs: sqls( + "select a || b from binoptestss_ss;", + ), + ExpErr: "operator '||' incompatible with type 'STRINGSET'", + }, + }, +} diff --git a/sql3/sql_defs_bool_test.go b/sql3/test/defs/defs_bool.go similarity index 75% rename from sql3/sql_defs_bool_test.go rename to sql3/test/defs/defs_bool.go index de58620be..717286bb6 100644 --- a/sql3/sql_defs_bool_test.go +++ b/sql3/test/defs/defs_bool.go @@ -1,9 +1,9 @@ -package sql3_test +package defs // BOOL tests -var boolTests = tableTest{ +var boolTests = TableTest{ name: "single-bool-field", - table: tbl( + Table: tbl( "singleboolfield", srcHdrs( srcHdr("_id", fldTypeID), @@ -11,11 +11,11 @@ var boolTests = tableTest{ ), srcRows(), ), - sqlTests: []sqlTest{ + SQLTests: []SQLTest{ { // Insert, step 1. name: "insert1", - sqls: sqls( + SQLs: sqls( `insert into singleboolfield (_id, a_bool) values (1, true), (2, true), @@ -24,21 +24,21 @@ var boolTests = tableTest{ (5, null), (6, null)`, ), - expHdrs: hdrs(), - expRows: rows(), - compare: compareExactOrdered, + ExpHdrs: hdrs(), + ExpRows: rows(), + Compare: CompareExactOrdered, }, { // Select all, step 1. name: "select-all1", - sqls: sqls( + SQLs: sqls( "select * from singleboolfield", ), - expHdrs: hdrs( + ExpHdrs: hdrs( hdr("_id", fldTypeID), hdr("a_bool", fldTypeBool), ), - expRows: rows( + ExpRows: rows( row(int64(1), true), row(int64(2), true), row(int64(3), false), @@ -46,12 +46,12 @@ var boolTests = tableTest{ row(int64(5), nil), row(int64(6), nil), ), - compare: compareExactOrdered, + Compare: CompareExactOrdered, }, { // Insert, step 2. Change bool values to all other combinations. name: "insert2", - sqls: sqls( + SQLs: sqls( `insert into singleboolfield (_id, a_bool) values (1, false), (2, null), @@ -60,21 +60,21 @@ var boolTests = tableTest{ (5, false), (6, true)`, ), - expHdrs: hdrs(), - expRows: rows(), - compare: compareExactOrdered, + ExpHdrs: hdrs(), + ExpRows: rows(), + Compare: CompareExactOrdered, }, { // Select all, step 2. name: "select-all2", - sqls: sqls( + SQLs: sqls( "select * from singleboolfield", ), - expHdrs: hdrs( + ExpHdrs: hdrs( hdr("_id", fldTypeID), hdr("a_bool", fldTypeBool), ), - expRows: rows( + ExpRows: rows( row(int64(1), false), row(int64(2), nil), row(int64(3), true), @@ -82,7 +82,7 @@ var boolTests = tableTest{ row(int64(5), false), row(int64(6), true), ), - compare: compareExactOrdered, + Compare: CompareExactOrdered, }, }, } diff --git a/sql3/sql_defs_cast_test.go b/sql3/test/defs/defs_cast.go similarity index 66% rename from sql3/sql_defs_cast_test.go rename to sql3/test/defs/defs_cast.go index ea2b1c2d4..83bce2573 100644 --- a/sql3/sql_defs_cast_test.go +++ b/sql3/test/defs/defs_cast.go @@ -1,4 +1,4 @@ -package sql3_test +package defs import ( "time" @@ -10,114 +10,114 @@ func expectedCastTime() time.Time { return time.Unix(1000, 0).UTC() } -var castIntLiteral = tableTest{ - table: tbl( +var castIntLiteral = TableTest{ + Table: tbl( "", nil, nil, ), - sqlTests: []sqlTest{ + SQLTests: []SQLTest{ { - sqls: sqls( + SQLs: sqls( "select cast(1 as int)", ), - expHdrs: hdrs( + ExpHdrs: hdrs( hdr("", fldTypeInt), ), - expRows: rows( + ExpRows: rows( row(int64(1)), ), - compare: compareExactUnordered, + Compare: CompareExactUnordered, }, { - sqls: sqls( + SQLs: sqls( "select cast(1 as bool)", ), - expHdrs: hdrs( + ExpHdrs: hdrs( hdr("", fldTypeBool), ), - expRows: rows( + ExpRows: rows( row(bool(true)), ), - compare: compareExactUnordered, + Compare: CompareExactUnordered, }, { - sqls: sqls( + SQLs: sqls( "select cast(0 as bool)", ), - expHdrs: hdrs( + ExpHdrs: hdrs( hdr("", fldTypeBool), ), - expRows: rows( + ExpRows: rows( row(bool(false)), ), - compare: compareExactUnordered, + Compare: CompareExactUnordered, }, { - sqls: sqls( + SQLs: sqls( "select cast(1 as decimal(2))", ), - expHdrs: hdrs( + ExpHdrs: hdrs( hdr("", fldTypeDecimal2), ), - expRows: rows( + ExpRows: rows( row(pql.NewDecimal(100, 2)), ), - compare: compareExactUnordered, + Compare: CompareExactUnordered, }, { - sqls: sqls( + SQLs: sqls( "select cast(1 as id)", ), - expHdrs: hdrs( + ExpHdrs: hdrs( hdr("", fldTypeID), ), - expRows: rows( + ExpRows: rows( row(int64(1)), ), - compare: compareExactUnordered, + Compare: CompareExactUnordered, }, { - sqls: sqls( + SQLs: sqls( "select cast(1 as idset)", ), - expErr: "'INT' cannot be cast to 'IDSET'", + ExpErr: "'INT' cannot be cast to 'IDSET'", }, { - sqls: sqls( + SQLs: sqls( "select cast(1 as string)", ), - expHdrs: hdrs( + ExpHdrs: hdrs( hdr("", fldTypeString), ), - expRows: rows( + ExpRows: rows( row(string("1")), ), - compare: compareExactUnordered, + Compare: CompareExactUnordered, }, { - sqls: sqls( + SQLs: sqls( "select cast(1 as stringset)", ), - expErr: "'INT' cannot be cast to 'STRINGSET'", + ExpErr: "'INT' cannot be cast to 'STRINGSET'", }, { - sqls: sqls( + SQLs: sqls( "select cast(1000 as timestamp)", ), - expHdrs: hdrs( + ExpHdrs: hdrs( hdr("", fldTypeTimestamp), ), - expRows: rows( + ExpRows: rows( row(time.Time(expectedCastTime())), ), - compare: compareExactUnordered, + Compare: CompareExactUnordered, }, }, } -var castInt = tableTest{ - table: tbl( +var castInt = TableTest{ + Table: tbl( "cast_int", srcHdrs( srcHdr("_id", fldTypeID), @@ -134,102 +134,102 @@ var castInt = tableTest{ srcRow(int64(1), int64(1000), bool(true), float64(12.34), int64(20), []int64{101, 102}, string("foo"), []string{"101", "102"}, knownTimestamp()), ), ), - sqlTests: []sqlTest{ + SQLTests: []SQLTest{ { - sqls: sqls( + SQLs: sqls( "select _id, cast(i1 as int) from cast_int", ), - expHdrs: hdrs( + ExpHdrs: hdrs( hdr("_id", fldTypeID), hdr("", fldTypeInt), ), - expRows: rows( + ExpRows: rows( row(int64(1), int64(1000)), ), - compare: compareExactUnordered, + Compare: CompareExactUnordered, }, { - sqls: sqls( + SQLs: sqls( "select _id, cast(i1 as bool) from cast_int", ), - expHdrs: hdrs( + ExpHdrs: hdrs( hdr("_id", fldTypeID), hdr("", fldTypeBool), ), - expRows: rows( + ExpRows: rows( row(int64(1), bool(true)), ), - compare: compareExactUnordered, + Compare: CompareExactUnordered, }, { - sqls: sqls( + SQLs: sqls( "select _id, cast(i1 as decimal(2)) from cast_int", ), - expHdrs: hdrs( + ExpHdrs: hdrs( hdr("_id", fldTypeID), hdr("", fldTypeDecimal2), ), - expRows: rows( + ExpRows: rows( row(int64(1), pql.NewDecimal(100000, 2)), ), - compare: compareExactUnordered, + Compare: CompareExactUnordered, }, { - sqls: sqls( + SQLs: sqls( "select _id, cast(i1 as id) from cast_int", ), - expHdrs: hdrs( + ExpHdrs: hdrs( hdr("_id", fldTypeID), hdr("", fldTypeID), ), - expRows: rows( + ExpRows: rows( row(int64(1), int64(1000)), ), - compare: compareExactUnordered, + Compare: CompareExactUnordered, }, { - sqls: sqls( + SQLs: sqls( "select _id, cast(i1 as idset) from cast_int", ), - expErr: "'INT' cannot be cast to 'IDSET'", + ExpErr: "'INT' cannot be cast to 'IDSET'", }, { - sqls: sqls( + SQLs: sqls( "select _id, cast(i1 as string) from cast_int", ), - expHdrs: hdrs( + ExpHdrs: hdrs( hdr("_id", fldTypeID), hdr("", fldTypeString), ), - expRows: rows( + ExpRows: rows( row(int64(1), string("1000")), ), - compare: compareExactUnordered, + Compare: CompareExactUnordered, }, { - sqls: sqls( + SQLs: sqls( "select _id, cast(i1 as stringset) from cast_int", ), - expErr: "'INT' cannot be cast to 'STRINGSET'", + ExpErr: "'INT' cannot be cast to 'STRINGSET'", }, { - sqls: sqls( + SQLs: sqls( "select _id, cast(i1 as timestamp) from cast_int", ), - expHdrs: hdrs( + ExpHdrs: hdrs( hdr("_id", fldTypeID), hdr("", fldTypeTimestamp), ), - expRows: rows( + ExpRows: rows( row(int64(1), time.Time(expectedCastTime())), ), - compare: compareExactUnordered, + Compare: CompareExactUnordered, }, }, } -var castBool = tableTest{ - table: tbl( +var castBool = TableTest{ + Table: tbl( "cast_bool", srcHdrs( srcHdr("_id", fldTypeID), @@ -246,81 +246,81 @@ var castBool = tableTest{ srcRow(int64(1), int64(1000), bool(true), float64(12.34), int64(20), []int64{101, 102}, string("foo"), []string{"101", "102"}, knownTimestamp()), ), ), - sqlTests: []sqlTest{ + SQLTests: []SQLTest{ { - sqls: sqls( + SQLs: sqls( "select _id, cast(b1 as int) from cast_bool", ), - expHdrs: hdrs( + ExpHdrs: hdrs( hdr("_id", fldTypeID), hdr("", fldTypeInt), ), - expRows: rows( + ExpRows: rows( row(int64(1), int64(1)), ), - compare: compareExactUnordered, + Compare: CompareExactUnordered, }, { - sqls: sqls( + SQLs: sqls( "select _id, cast(b1 as bool) from cast_bool", ), - expHdrs: hdrs( + ExpHdrs: hdrs( hdr("_id", fldTypeID), hdr("", fldTypeBool), ), - expRows: rows( + ExpRows: rows( row(int64(1), bool(true)), ), - compare: compareExactUnordered, + Compare: CompareExactUnordered, }, { - sqls: sqls( + SQLs: sqls( "select _id, cast(b1 as decimal(2)) from cast_bool", ), - expErr: "'BOOL' cannot be cast to 'DECIMAL(2)'", + ExpErr: "'BOOL' cannot be cast to 'DECIMAL(2)'", }, { - sqls: sqls( + SQLs: sqls( "select _id, cast(b1 as id) from cast_bool", ), - expErr: "'BOOL' cannot be cast to 'ID'", + ExpErr: "'BOOL' cannot be cast to 'ID'", }, { - sqls: sqls( + SQLs: sqls( "select _id, cast(b1 as idset) from cast_bool", ), - expErr: "'BOOL' cannot be cast to 'IDSET'", + ExpErr: "'BOOL' cannot be cast to 'IDSET'", }, { - sqls: sqls( + SQLs: sqls( "select _id, cast(b1 as string) from cast_bool", ), - expHdrs: hdrs( + ExpHdrs: hdrs( hdr("_id", fldTypeID), hdr("", fldTypeString), ), - expRows: rows( + ExpRows: rows( row(int64(1), string("true")), ), - compare: compareExactUnordered, + Compare: CompareExactUnordered, }, { - sqls: sqls( + SQLs: sqls( "select _id, cast(b1 as stringset) from cast_bool", ), - expErr: "'BOOL' cannot be cast to 'STRINGSET'", + ExpErr: "'BOOL' cannot be cast to 'STRINGSET'", }, { - sqls: sqls( + SQLs: sqls( "select _id, cast(b1 as timestamp) from cast_bool", ), - expErr: "'BOOL' cannot be cast to 'TIMESTAMP'", + ExpErr: "'BOOL' cannot be cast to 'TIMESTAMP'", }, }, } -var castDecimal = tableTest{ - table: tbl( +var castDecimal = TableTest{ + Table: tbl( "cast_dec", srcHdrs( srcHdr("_id", fldTypeID), @@ -337,74 +337,74 @@ var castDecimal = tableTest{ srcRow(int64(1), int64(1000), bool(true), float64(12.34), int64(20), []int64{101, 102}, string("foo"), []string{"101", "102"}, knownTimestamp()), ), ), - sqlTests: []sqlTest{ + SQLTests: []SQLTest{ { - sqls: sqls( + SQLs: sqls( "select _id, cast(d1 as int) from cast_dec", ), - expErr: "'DECIMAL(2)' cannot be cast to 'INT'", + ExpErr: "'DECIMAL(2)' cannot be cast to 'INT'", }, { - sqls: sqls( + SQLs: sqls( "select _id, cast(d1 as bool) from cast_dec", ), - expErr: "'DECIMAL(2)' cannot be cast to 'BOOL'", + ExpErr: "'DECIMAL(2)' cannot be cast to 'BOOL'", }, { - sqls: sqls( + SQLs: sqls( "select _id, cast(d1 as decimal(2)) from cast_dec", ), - expHdrs: hdrs( + ExpHdrs: hdrs( hdr("_id", fldTypeID), hdr("", fldTypeDecimal2), ), - expRows: rows( + ExpRows: rows( row(int64(1), pql.NewDecimal(1234, 2)), ), - compare: compareExactUnordered, + Compare: CompareExactUnordered, }, { - sqls: sqls( + SQLs: sqls( "select _id, cast(d1 as id) from cast_dec", ), - expErr: "'DECIMAL(2)' cannot be cast to 'ID'", + ExpErr: "'DECIMAL(2)' cannot be cast to 'ID'", }, { - sqls: sqls( + SQLs: sqls( "select _id, cast(d1 as idset) from cast_dec", ), - expErr: "'DECIMAL(2)' cannot be cast to 'IDSET'", + ExpErr: "'DECIMAL(2)' cannot be cast to 'IDSET'", }, { - sqls: sqls( + SQLs: sqls( "select _id, cast(d1 as string) from cast_dec", ), - expHdrs: hdrs( + ExpHdrs: hdrs( hdr("_id", fldTypeID), hdr("", fldTypeString), ), - expRows: rows( + ExpRows: rows( row(int64(1), string("12.34")), ), - compare: compareExactUnordered, + Compare: CompareExactUnordered, }, { - sqls: sqls( + SQLs: sqls( "select _id, cast(d1 as stringset) from cast_dec", ), - expErr: "'DECIMAL(2)' cannot be cast to 'STRINGSET'", + ExpErr: "'DECIMAL(2)' cannot be cast to 'STRINGSET'", }, { - sqls: sqls( + SQLs: sqls( "select _id, cast(d1 as timestamp) from cast_dec", ), - expErr: "'DECIMAL(2)' cannot be cast to 'TIMESTAMP'", + ExpErr: "'DECIMAL(2)' cannot be cast to 'TIMESTAMP'", }, }, } -var castID = tableTest{ - table: tbl( +var castID = TableTest{ + Table: tbl( "cast_id", srcHdrs( srcHdr("_id", fldTypeID), @@ -421,88 +421,88 @@ var castID = tableTest{ srcRow(int64(1), int64(1000), bool(true), float64(12.34), int64(20), []int64{101, 102}, string("foo"), []string{"101", "102"}, knownTimestamp()), ), ), - sqlTests: []sqlTest{ + SQLTests: []SQLTest{ { - sqls: sqls( + SQLs: sqls( "select _id, cast(id1 as int) from cast_id", ), - expHdrs: hdrs( + ExpHdrs: hdrs( hdr("_id", fldTypeID), hdr("", fldTypeInt), ), - expRows: rows( + ExpRows: rows( row(int64(1), int64(20)), ), - compare: compareExactUnordered, + Compare: CompareExactUnordered, }, { - sqls: sqls( + SQLs: sqls( "select _id, cast(id1 as bool) from cast_id", ), - expHdrs: hdrs( + ExpHdrs: hdrs( hdr("_id", fldTypeID), hdr("", fldTypeBool), ), - expRows: rows( + ExpRows: rows( row(int64(1), bool(true)), ), - compare: compareExactUnordered, + Compare: CompareExactUnordered, }, { - sqls: sqls( + SQLs: sqls( "select _id, cast(id1 as decimal(2)) from cast_id", ), - expHdrs: hdrs( + ExpHdrs: hdrs( hdr("_id", fldTypeID), hdr("", fldTypeDecimal2), ), - expRows: rows( + ExpRows: rows( row(int64(1), pql.NewDecimal(2000, 2)), ), - compare: compareExactUnordered, + Compare: CompareExactUnordered, }, { - sqls: sqls( + SQLs: sqls( "select _id, cast(id1 as id) from cast_id", ), - expHdrs: hdrs( + ExpHdrs: hdrs( hdr("_id", fldTypeID), hdr("", fldTypeID), ), - expRows: rows( + ExpRows: rows( row(int64(1), int64(20)), ), - compare: compareExactUnordered, + Compare: CompareExactUnordered, }, { - sqls: sqls( + SQLs: sqls( "select _id, cast(id1 as idset) from cast_id", ), - expErr: "'ID' cannot be cast to 'IDSET'", + ExpErr: "'ID' cannot be cast to 'IDSET'", }, { - sqls: sqls( + SQLs: sqls( "select _id, cast(id1 as string) from cast_id", ), - expErr: "'ID' cannot be cast to 'STRING'", + ExpErr: "'ID' cannot be cast to 'STRING'", }, { - sqls: sqls( + SQLs: sqls( "select _id, cast(id1 as stringset) from cast_id", ), - expErr: "'ID' cannot be cast to 'STRINGSET'", + ExpErr: "'ID' cannot be cast to 'STRINGSET'", }, { - sqls: sqls( + SQLs: sqls( "select _id, cast(id1 as timestamp) from cast_id", ), - expErr: "'ID' cannot be cast to 'TIMESTAMP'", + ExpErr: "'ID' cannot be cast to 'TIMESTAMP'", }, }, } -var castIDSet = tableTest{ - table: tbl( +var castIDSet = TableTest{ + Table: tbl( "cast_ids", srcHdrs( srcHdr("_id", fldTypeID), @@ -519,74 +519,74 @@ var castIDSet = tableTest{ srcRow(int64(1), int64(1000), bool(true), float64(12.34), int64(20), []int64{101, 102}, string("foo"), []string{"101", "102"}, knownTimestamp()), ), ), - sqlTests: []sqlTest{ + SQLTests: []SQLTest{ { - sqls: sqls( + SQLs: sqls( "select _id, cast(ids1 as int) from cast_ids", ), - expErr: "'IDSET' cannot be cast to 'INT'", + ExpErr: "'IDSET' cannot be cast to 'INT'", }, { - sqls: sqls( + SQLs: sqls( "select _id, cast(ids1 as bool) from cast_ids", ), - expErr: "'IDSET' cannot be cast to 'BOOL'", + ExpErr: "'IDSET' cannot be cast to 'BOOL'", }, { - sqls: sqls( + SQLs: sqls( "select _id, cast(ids1 as decimal(2)) from cast_ids", ), - expErr: "'IDSET' cannot be cast to 'DECIMAL(2)'", + ExpErr: "'IDSET' cannot be cast to 'DECIMAL(2)'", }, { - sqls: sqls( + SQLs: sqls( "select _id, cast(ids1 as id) from cast_ids", ), - expErr: "'IDSET' cannot be cast to 'ID'", + ExpErr: "'IDSET' cannot be cast to 'ID'", }, { - sqls: sqls( + SQLs: sqls( "select _id, cast(ids1 as idset) from cast_ids", ), - expHdrs: hdrs( + ExpHdrs: hdrs( hdr("_id", fldTypeID), hdr("", fldTypeIDSet), ), - expRows: rows( + ExpRows: rows( row(int64(1), []int64{101, 102}), ), - compare: compareExactUnordered, + Compare: CompareExactUnordered, }, { - sqls: sqls( + SQLs: sqls( "select _id, cast(ids1 as string) from cast_ids", ), - expHdrs: hdrs( + ExpHdrs: hdrs( hdr("_id", fldTypeID), hdr("", fldTypeString), ), - expRows: rows( + ExpRows: rows( row(int64(1), string("[101 102]")), ), - compare: compareExactUnordered, + Compare: CompareExactUnordered, }, { - sqls: sqls( + SQLs: sqls( "select _id, cast(ids1 as stringset) from cast_ids", ), - expErr: "'IDSET' cannot be cast to 'STRINGSET'", + ExpErr: "'IDSET' cannot be cast to 'STRINGSET'", }, { - sqls: sqls( + SQLs: sqls( "select _id, cast(ids1 as timestamp) from cast_ids", ), - expErr: "'IDSET' cannot be cast to 'TIMESTAMP'", + ExpErr: "'IDSET' cannot be cast to 'TIMESTAMP'", }, }, } -var castString = tableTest{ - table: tbl( +var castString = TableTest{ + Table: tbl( "cast_string", srcHdrs( srcHdr("_id", fldTypeID), @@ -603,132 +603,132 @@ var castString = tableTest{ srcRow(int64(1), int64(1000), bool(true), float64(12.34), int64(20), []int64{101, 102}, string("foo"), []string{"101", "102"}, knownTimestamp()), ), ), - sqlTests: []sqlTest{ + SQLTests: []SQLTest{ { - sqls: sqls( + SQLs: sqls( "select _id, cast(s1 as int) from cast_string", ), - expErr: "'foo' cannot be cast to 'INT'", + ExpErr: "'foo' cannot be cast to 'INT'", }, { - sqls: sqls( + SQLs: sqls( "select _id, cast('11' as int) from cast_string", ), - expHdrs: hdrs( + ExpHdrs: hdrs( hdr("_id", fldTypeID), hdr("", fldTypeInt), ), - expRows: rows( + ExpRows: rows( row(int64(1), int64(11)), ), - compare: compareExactUnordered, + Compare: CompareExactUnordered, }, { - sqls: sqls( + SQLs: sqls( "select _id, cast(s1 as bool) from cast_string", ), - expErr: "'foo' cannot be cast to 'BOOL'", + ExpErr: "'foo' cannot be cast to 'BOOL'", }, { - sqls: sqls( + SQLs: sqls( "select _id, cast('true' as bool) from cast_string", ), - expHdrs: hdrs( + ExpHdrs: hdrs( hdr("_id", fldTypeID), hdr("", fldTypeBool), ), - expRows: rows( + ExpRows: rows( row(int64(1), bool(true)), ), - compare: compareExactUnordered, + Compare: CompareExactUnordered, }, { - sqls: sqls( + SQLs: sqls( "select _id, cast(s1 as decimal(2)) from cast_string", ), - expErr: "'foo' cannot be cast to 'DECIMAL(2)'", + ExpErr: "'foo' cannot be cast to 'DECIMAL(2)'", }, { - sqls: sqls( + SQLs: sqls( "select _id, cast('12.34' as decimal(2)) from cast_string", ), - expHdrs: hdrs( + ExpHdrs: hdrs( hdr("_id", fldTypeID), hdr("", fldTypeDecimal2), ), - expRows: rows( + ExpRows: rows( row(int64(1), pql.NewDecimal(1234, 2)), ), - compare: compareExactUnordered, + Compare: CompareExactUnordered, }, { - sqls: sqls( + SQLs: sqls( "select _id, cast(s1 as id) from cast_string", ), - expErr: "'foo' cannot be cast to 'ID'", + ExpErr: "'foo' cannot be cast to 'ID'", }, { - sqls: sqls( + SQLs: sqls( "select _id, cast('11' as id) from cast_string", ), - expHdrs: hdrs( + ExpHdrs: hdrs( hdr("_id", fldTypeID), hdr("", fldTypeID), ), - expRows: rows( + ExpRows: rows( row(int64(1), int64(11)), ), - compare: compareExactUnordered, + Compare: CompareExactUnordered, }, { - sqls: sqls( + SQLs: sqls( "select _id, cast(s1 as idset) from cast_string", ), - expErr: "'STRING' cannot be cast to 'IDSET'", + ExpErr: "'STRING' cannot be cast to 'IDSET'", }, { - sqls: sqls( + SQLs: sqls( "select _id, cast(s1 as string) from cast_string", ), - expHdrs: hdrs( + ExpHdrs: hdrs( hdr("_id", fldTypeID), hdr("", fldTypeString), ), - expRows: rows( + ExpRows: rows( row(int64(1), string("foo")), ), - compare: compareExactUnordered, + Compare: CompareExactUnordered, }, { - sqls: sqls( + SQLs: sqls( "select _id, cast(s1 as stringset) from cast_string", ), - expErr: "'STRING' cannot be cast to 'STRINGSET'", + ExpErr: "'STRING' cannot be cast to 'STRINGSET'", }, { - sqls: sqls( + SQLs: sqls( "select _id, cast(s1 as timestamp) from cast_string", ), - expErr: "'foo' cannot be cast to 'TIMESTAMP'", + ExpErr: "'foo' cannot be cast to 'TIMESTAMP'", }, { - sqls: sqls( + SQLs: sqls( "select _id, cast('1970-01-01T00:16:40Z' as timestamp) from cast_string", ), - expHdrs: hdrs( + ExpHdrs: hdrs( hdr("_id", fldTypeID), hdr("", fldTypeTimestamp), ), - expRows: rows( + ExpRows: rows( row(int64(1), time.Time(expectedCastTime())), ), - compare: compareExactUnordered, + Compare: CompareExactUnordered, }, }, } -var castStringSet = tableTest{ - table: tbl( +var castStringSet = TableTest{ + Table: tbl( "cast_ss", srcHdrs( srcHdr("_id", fldTypeID), @@ -745,75 +745,75 @@ var castStringSet = tableTest{ srcRow(int64(1), int64(1000), bool(true), float64(12.34), int64(20), []int64{101, 102}, string("foo"), []string{"101", "102"}, knownTimestamp()), ), ), - sqlTests: []sqlTest{ + SQLTests: []SQLTest{ { - sqls: sqls( + SQLs: sqls( "select _id, cast(ss1 as int) from cast_ss", ), - expErr: "'STRINGSET' cannot be cast to 'INT'", + ExpErr: "'STRINGSET' cannot be cast to 'INT'", }, { - sqls: sqls( + SQLs: sqls( "select _id, cast(ss1 as bool) from cast_ss", ), - expErr: "'STRINGSET' cannot be cast to 'BOOL'", + ExpErr: "'STRINGSET' cannot be cast to 'BOOL'", }, { - sqls: sqls( + SQLs: sqls( "select _id, cast(ss1 as decimal(2)) from cast_ss", ), - expErr: "'STRINGSET' cannot be cast to 'DECIMAL(2)'", + ExpErr: "'STRINGSET' cannot be cast to 'DECIMAL(2)'", }, { - sqls: sqls( + SQLs: sqls( "select _id, cast(ss1 as id) from cast_ss", ), - expErr: "'STRINGSET' cannot be cast to 'ID'", + ExpErr: "'STRINGSET' cannot be cast to 'ID'", }, { - sqls: sqls( + SQLs: sqls( "select _id, cast(ss1 as idset) from cast_ss", ), - expErr: "'STRINGSET' cannot be cast to 'IDSET'", + ExpErr: "'STRINGSET' cannot be cast to 'IDSET'", }, { - sqls: sqls( + SQLs: sqls( "select _id, cast(ss1 as string) from cast_ss", ), - expHdrs: hdrs( + ExpHdrs: hdrs( hdr("_id", fldTypeID), hdr("", fldTypeString), ), - expRows: rows( + ExpRows: rows( row(int64(1), string(`["101","102"]`)), ), - compare: compareExactUnordered, + Compare: CompareExactUnordered, }, { - sqls: sqls( + SQLs: sqls( "select _id, cast(ss1 as stringset) from cast_ss", ), - expHdrs: hdrs( + ExpHdrs: hdrs( hdr("_id", fldTypeID), hdr("", fldTypeStringSet), ), - expRows: rows( + ExpRows: rows( row(int64(1), []string{"101", "102"}), ), - compare: compareExactUnordered, - sortStringKeys: true, + Compare: CompareExactUnordered, + SortStringKeys: true, }, { - sqls: sqls( + SQLs: sqls( "select _id, cast(ss1 as timestamp) from cast_ss", ), - expErr: "'STRINGSET' cannot be cast to 'TIMESTAMP'", + ExpErr: "'STRINGSET' cannot be cast to 'TIMESTAMP'", }, }, } -var castTimestamp = tableTest{ - table: tbl( +var castTimestamp = TableTest{ + Table: tbl( "cast_ts", srcHdrs( srcHdr("_id", fldTypeID), @@ -830,75 +830,75 @@ var castTimestamp = tableTest{ srcRow(int64(1), int64(1000), bool(true), float64(12.34), int64(20), []int64{101, 102}, string("foo"), []string{"101", "102"}, knownTimestamp()), ), ), - sqlTests: []sqlTest{ + SQLTests: []SQLTest{ { - sqls: sqls( + SQLs: sqls( "select _id, cast(t1 as int) from cast_ts", ), - expHdrs: hdrs( + ExpHdrs: hdrs( hdr("_id", fldTypeID), hdr("", fldTypeInt), ), - expRows: rows( + ExpRows: rows( row(int64(1), int64(1351807721)), ), - compare: compareExactUnordered, + Compare: CompareExactUnordered, }, { - sqls: sqls( + SQLs: sqls( "select _id, cast(t1 as bool) from cast_ts", ), - expErr: "'TIMESTAMP' cannot be cast to 'BOOL'", + ExpErr: "'TIMESTAMP' cannot be cast to 'BOOL'", }, { - sqls: sqls( + SQLs: sqls( "select _id, cast(t1 as decimal(2)) from cast_ts", ), - expErr: "'TIMESTAMP' cannot be cast to 'DECIMAL(2)'", + ExpErr: "'TIMESTAMP' cannot be cast to 'DECIMAL(2)'", }, { - sqls: sqls( + SQLs: sqls( "select _id, cast(t1 as id) from cast_ts", ), - expErr: "'TIMESTAMP' cannot be cast to 'ID'", + ExpErr: "'TIMESTAMP' cannot be cast to 'ID'", }, { - sqls: sqls( + SQLs: sqls( "select _id, cast(t1 as idset) from cast_ts", ), - expErr: "'TIMESTAMP' cannot be cast to 'IDSET'", + ExpErr: "'TIMESTAMP' cannot be cast to 'IDSET'", }, { - sqls: sqls( + SQLs: sqls( "select _id, cast(t1 as string) from cast_ts", ), - expHdrs: hdrs( + ExpHdrs: hdrs( hdr("_id", fldTypeID), hdr("", fldTypeString), ), - expRows: rows( + ExpRows: rows( row(int64(1), string("2012-11-01T22:08:41Z")), ), - compare: compareExactUnordered, + Compare: CompareExactUnordered, }, { - sqls: sqls( + SQLs: sqls( "select _id, cast(t1 as stringset) from cast_ts", ), - expErr: "'TIMESTAMP' cannot be cast to 'STRINGSET'", + ExpErr: "'TIMESTAMP' cannot be cast to 'STRINGSET'", }, { - sqls: sqls( + SQLs: sqls( "select _id, cast(t1 as timestamp) from cast_ts", ), - expHdrs: hdrs( + ExpHdrs: hdrs( hdr("_id", fldTypeID), hdr("", fldTypeTimestamp), ), - expRows: rows( + ExpRows: rows( row(int64(1), knownTimestamp()), ), - compare: compareExactUnordered, + Compare: CompareExactUnordered, }, }, } diff --git a/sql3/sql_defs_create_table_test.go b/sql3/test/defs/defs_create_table.go similarity index 64% rename from sql3/sql_defs_create_table_test.go rename to sql3/test/defs/defs_create_table.go index dceded5a7..fe2767704 100644 --- a/sql3/sql_defs_create_table_test.go +++ b/sql3/test/defs/defs_create_table.go @@ -1,46 +1,46 @@ -package sql3_test +package defs -var createTable = tableTest{ +var createTable = TableTest{ name: "createTable", - sqlTests: []sqlTest{ + SQLTests: []SQLTest{ { name: "keyPartitionsSetTo0", - sqls: sqls( + SQLs: sqls( "create table foo (_id id, i1 int) keypartitions 0", ), - expErr: "invalid value '0' for key partitions (should be a number between 1-10000)", + ExpErr: "invalid value '0' for key partitions (should be a number between 1-10000)", }, { name: "keyPartitionsSetTo10001", - sqls: sqls( + SQLs: sqls( "create table foo (_id id, i1 int) keypartitions 10001", ), - expErr: "invalid value '10001' for key partitions (should be a number between 1-10000)", + ExpErr: "invalid value '10001' for key partitions (should be a number between 1-10000)", }, { name: "shardWidthSetTo0", - sqls: sqls( + SQLs: sqls( "create table foo (_id id, i1 int) shardwidth 0", ), - expErr: "invalid value '0' for shardwidth (should be a number that is a power of 2 and greater or equal to 2^16)", + ExpErr: "invalid value '0' for shardwidth (should be a number that is a power of 2 and greater or equal to 2^16)", }, { name: "shardWidthSetTo11", - sqls: sqls( + SQLs: sqls( "create table foo (_id id, i1 int) shardwidth 11", ), - expErr: "invalid value '11' for shardwidth (should be a number that is a power of 2 and greater or equal to 2^16)", + ExpErr: "invalid value '11' for shardwidth (should be a number that is a power of 2 and greater or equal to 2^16)", }, { name: "shardWidthSetTo11", - sqls: sqls( + SQLs: sqls( "create table foo (_id id, i1 int) shardwidth 32", ), - expErr: "invalid value '32' for shardwidth (should be a number that is a power of 2 and greater or equal to 2^16)", + ExpErr: "invalid value '32' for shardwidth (should be a number that is a power of 2 and greater or equal to 2^16)", }, { name: "shardWidthSetTo131072", - sqls: sqls( + SQLs: sqls( "create table foo (_id id, i1 int) shardwidth 131072", ), }, diff --git a/sql3/sql_defs_date_functions_test.go b/sql3/test/defs/defs_date_functions.go similarity index 64% rename from sql3/sql_defs_date_functions_test.go rename to sql3/test/defs/defs_date_functions.go index 359f4a8b4..5b083b6fd 100644 --- a/sql3/sql_defs_date_functions_test.go +++ b/sql3/test/defs/defs_date_functions.go @@ -1,9 +1,9 @@ -package sql3_test +package defs // datepart tests -var datePartTests = tableTest{ +var datePartTests = TableTest{ - table: tbl( + Table: tbl( "dateparttests", srcHdrs( srcHdr("_id", fldTypeID), @@ -15,173 +15,173 @@ var datePartTests = tableTest{ srcRow(int64(1), int64(10), int64(100), knownTimestamp()), ), ), - sqlTests: []sqlTest{ + SQLTests: []SQLTest{ { - sqls: sqls( + SQLs: sqls( "select datepart()", ), - expErr: "count of formal parameters (2) does not match count of actual parameters (0)", + ExpErr: "count of formal parameters (2) does not match count of actual parameters (0)", }, { - sqls: sqls( + SQLs: sqls( "select datepart(1, 2)", ), - expErr: "an expression of type 'INT' cannot be passed to a parameter of type 'STRING'", + ExpErr: "an expression of type 'INT' cannot be passed to a parameter of type 'STRING'", }, { - sqls: sqls( + SQLs: sqls( "select datepart('1', 2)", ), - expErr: "an expression of type 'INT' cannot be passed to a parameter of type 'TIMESTAMP'", + ExpErr: "an expression of type 'INT' cannot be passed to a parameter of type 'TIMESTAMP'", }, { - sqls: sqls( + SQLs: sqls( "select datepart('1', current_timestamp)", ), - expErr: "invalid value '1' for parameter 'interval'", + ExpErr: "invalid value '1' for parameter 'interval'", }, { - sqls: sqls( + SQLs: sqls( "select _id, datepart('yy', ts) from dateparttests", ), - expHdrs: hdrs( + ExpHdrs: hdrs( hdr("_id", fldTypeID), hdr("", fldTypeInt), ), - expRows: rows( + ExpRows: rows( row(int64(1), int64(2012)), ), - compare: compareExactUnordered, + Compare: CompareExactUnordered, }, { - sqls: sqls( + SQLs: sqls( "select _id, datepart('yd', ts) from dateparttests", ), - expHdrs: hdrs( + ExpHdrs: hdrs( hdr("_id", fldTypeID), hdr("", fldTypeInt), ), - expRows: rows( + ExpRows: rows( row(int64(1), int64(306)), ), - compare: compareExactUnordered, + Compare: CompareExactUnordered, }, { - sqls: sqls( + SQLs: sqls( "select _id, datepart('m', ts) from dateparttests", ), - expHdrs: hdrs( + ExpHdrs: hdrs( hdr("_id", fldTypeID), hdr("", fldTypeInt), ), - expRows: rows( + ExpRows: rows( row(int64(1), int64(11)), ), - compare: compareExactUnordered, + Compare: CompareExactUnordered, }, { - sqls: sqls( + SQLs: sqls( "select _id, datepart('d', ts) from dateparttests", ), - expHdrs: hdrs( + ExpHdrs: hdrs( hdr("_id", fldTypeID), hdr("", fldTypeInt), ), - expRows: rows( + ExpRows: rows( row(int64(1), int64(1)), ), - compare: compareExactUnordered, + Compare: CompareExactUnordered, }, { - sqls: sqls( + SQLs: sqls( "select _id, datepart('w', ts) from dateparttests", ), - expHdrs: hdrs( + ExpHdrs: hdrs( hdr("_id", fldTypeID), hdr("", fldTypeInt), ), - expRows: rows( + ExpRows: rows( row(int64(1), int64(4)), ), - compare: compareExactUnordered, + Compare: CompareExactUnordered, }, { - sqls: sqls( + SQLs: sqls( "select _id, datepart('wk', ts) from dateparttests", ), - expHdrs: hdrs( + ExpHdrs: hdrs( hdr("_id", fldTypeID), hdr("", fldTypeInt), ), - expRows: rows( + ExpRows: rows( row(int64(1), int64(44)), ), - compare: compareExactUnordered, + Compare: CompareExactUnordered, }, { - sqls: sqls( + SQLs: sqls( "select _id, datepart('hh', ts) from dateparttests", ), - expHdrs: hdrs( + ExpHdrs: hdrs( hdr("_id", fldTypeID), hdr("", fldTypeInt), ), - expRows: rows( + ExpRows: rows( row(int64(1), int64(22)), ), - compare: compareExactUnordered, + Compare: CompareExactUnordered, }, { - sqls: sqls( + SQLs: sqls( "select _id, datepart('mi', ts) from dateparttests", ), - expHdrs: hdrs( + ExpHdrs: hdrs( hdr("_id", fldTypeID), hdr("", fldTypeInt), ), - expRows: rows( + ExpRows: rows( row(int64(1), int64(8)), ), - compare: compareExactUnordered, + Compare: CompareExactUnordered, }, { - sqls: sqls( + SQLs: sqls( "select _id, datepart('s', ts) from dateparttests", ), - expHdrs: hdrs( + ExpHdrs: hdrs( hdr("_id", fldTypeID), hdr("", fldTypeInt), ), - expRows: rows( + ExpRows: rows( row(int64(1), int64(41)), ), - compare: compareExactUnordered, + Compare: CompareExactUnordered, }, { - sqls: sqls( + SQLs: sqls( "select _id, datepart('ms', ts) from dateparttests", ), - expHdrs: hdrs( + ExpHdrs: hdrs( hdr("_id", fldTypeID), hdr("", fldTypeInt), ), - expRows: rows( + ExpRows: rows( row(int64(1), int64(0)), ), - compare: compareExactUnordered, + Compare: CompareExactUnordered, }, { - sqls: sqls( + SQLs: sqls( "select _id, datepart('ns', ts) from dateparttests", ), - expHdrs: hdrs( + ExpHdrs: hdrs( hdr("_id", fldTypeID), hdr("", fldTypeInt), ), - expRows: rows( + ExpRows: rows( row(int64(1), int64(0)), ), - compare: compareExactUnordered, + Compare: CompareExactUnordered, }, }, } diff --git a/sql3/sql_defs_groupby_test.go b/sql3/test/defs/defs_groupby.go similarity index 77% rename from sql3/sql_defs_groupby_test.go rename to sql3/test/defs/defs_groupby.go index f12cf784a..399dbb0ce 100644 --- a/sql3/sql_defs_groupby_test.go +++ b/sql3/test/defs/defs_groupby.go @@ -1,4 +1,4 @@ -package sql3_test +package defs import ( "github.com/molecula/featurebase/v3/pql" @@ -6,8 +6,8 @@ import ( ) // groupby tests -var groupByTests = tableTest{ - table: tbl( +var groupByTests = TableTest{ + Table: tbl( "groupby_test", srcHdrs( srcHdr("_id", fldTypeID), @@ -25,134 +25,134 @@ var groupByTests = tableTest{ srcRow(int64(6), int64(13), float64(13), string("13"), nil), ), ), - sqlTests: []sqlTest{ + SQLTests: []SQLTest{ { - sqls: sqls( + SQLs: sqls( "SELECT COUNT(*), i1 FROM groupby_test group by i1", "SELECT COUNT(_id), i1 FROM groupby_test group by i1", ), - expHdrs: hdrs( + ExpHdrs: hdrs( hdr("", fldTypeInt), hdr("i1", fldTypeInt), ), - expRows: rows( + ExpRows: rows( row(int64(2), int64(10)), row(int64(1), int64(11)), row(int64(2), int64(12)), row(int64(1), int64(13)), ), - compare: compareExactUnordered, + Compare: CompareExactUnordered, }, { - sqls: sqls( + SQLs: sqls( "SELECT COUNT(distinct i2) AS count_rows, i1 FROM groupby_test group by i1", ), - expHdrs: hdrs( + ExpHdrs: hdrs( hdr("count_rows", fldTypeInt), hdr("i1", fldTypeInt), ), - expRows: rows( + ExpRows: rows( row(int64(2), int64(10)), row(int64(0), int64(11)), row(int64(0), int64(12)), row(int64(0), int64(13)), ), - compare: compareExactUnordered, + Compare: CompareExactUnordered, }, { - sqls: sqls( + SQLs: sqls( "SELECT sum(i2) AS sum_rows, i1 FROM groupby_test group by i1", ), - expHdrs: hdrs( + ExpHdrs: hdrs( hdr("sum_rows", fldTypeInt), hdr("i1", fldTypeInt), ), - expRows: rows( + ExpRows: rows( row(int64(300), int64(10)), ), - compare: compareExactUnordered, + Compare: CompareExactUnordered, }, { - sqls: sqls( + SQLs: sqls( "SELECT COUNT(*) FROM groupby_test group by i1", ), - expHdrs: hdrs( + ExpHdrs: hdrs( hdr("", fldTypeInt), ), - expRows: rows( + ExpRows: rows( row(int64(2)), row(int64(1)), row(int64(2)), row(int64(1)), ), - compare: compareExactUnordered, + Compare: CompareExactUnordered, }, { - sqls: sqls( + SQLs: sqls( "select count(distinct i2) AS count_rows, sum(i2) as sum_rows, i1 from groupby_test group by i1", ), - expHdrs: hdrs( + ExpHdrs: hdrs( hdr("count_rows", fldTypeInt), hdr("sum_rows", fldTypeInt), hdr("i1", fldTypeInt), ), - expRows: rows( + ExpRows: rows( row(int64(2), int64(300), int64(10)), row(int64(0), nil, int64(11)), row(int64(0), nil, int64(12)), row(int64(0), nil, int64(13)), ), - compare: compareExactUnordered, + Compare: CompareExactUnordered, }, { - sqls: sqls( + SQLs: sqls( "select avg(i1) as avg_rows, i1 from groupby_test group by i1", ), - expHdrs: hdrs( + ExpHdrs: hdrs( hdr("avg_rows", parser.NewDataTypeDecimal(4)), hdr("i1", fldTypeInt), ), - expRows: rows( + ExpRows: rows( row(pql.NewDecimal(100000, 4), int64(10)), row(pql.NewDecimal(110000, 4), int64(11)), row(pql.NewDecimal(120000, 4), int64(12)), row(pql.NewDecimal(130000, 4), int64(13)), ), - compare: compareExactUnordered, + Compare: CompareExactUnordered, }, { - sqls: sqls( + SQLs: sqls( "select avg(d1) as avg_rows, i1 from groupby_test group by i1", ), - expHdrs: hdrs( + ExpHdrs: hdrs( hdr("avg_rows", parser.NewDataTypeDecimal(4)), hdr("i1", fldTypeInt), ), - expRows: rows( + ExpRows: rows( row(pql.NewDecimal(100000, 4), int64(10)), row(pql.NewDecimal(110000, 4), int64(11)), row(pql.NewDecimal(120000, 4), int64(12)), row(pql.NewDecimal(130000, 4), int64(13)), ), - compare: compareExactUnordered, + Compare: CompareExactUnordered, }, { - sqls: sqls( + SQLs: sqls( "select percentile(i1, 0) as p_rows, i1 from groupby_test group by i1", ), - expErr: "aggregate 'PERCENTILE()' not allowed in GROUP BY", + ExpErr: "aggregate 'PERCENTILE()' not allowed in GROUP BY", }, { - sqls: sqls( + SQLs: sqls( "select min(i1) as p_rows, i1 from groupby_test group by i1", ), - expErr: "aggregate 'MIN()' not allowed in GROUP BY", + ExpErr: "aggregate 'MIN()' not allowed in GROUP BY", }, { - sqls: sqls( + SQLs: sqls( "select max(i1) as p_rows, i1 from groupby_test group by i1", ), - expErr: "aggregate 'MAX()' not allowed in GROUP BY", + ExpErr: "aggregate 'MAX()' not allowed in GROUP BY", }, }, } diff --git a/sql3/sql_defs_in_test.go b/sql3/test/defs/defs_in.go similarity index 68% rename from sql3/sql_defs_in_test.go rename to sql3/test/defs/defs_in.go index 76467b7b5..e2d0dfaf1 100644 --- a/sql3/sql_defs_in_test.go +++ b/sql3/test/defs/defs_in.go @@ -1,8 +1,8 @@ -package sql3_test +package defs // IN tests -var inTests = tableTest{ - table: tbl( +var inTests = TableTest{ + Table: tbl( "in_all_types", srcHdrs( srcHdr("_id", fldTypeID), @@ -19,121 +19,121 @@ var inTests = tableTest{ srcRow(int64(1), int64(1000), bool(true), float64(12.34), int64(20), []int64{101, 102}, string("foo"), []string{"101", "102"}, knownTimestamp()), ), ), - sqlTests: []sqlTest{ + SQLTests: []SQLTest{ { - sqls: sqls( + SQLs: sqls( "select _id in (1, 10) from in_all_types", ), - expHdrs: hdrs( + ExpHdrs: hdrs( hdr("", fldTypeBool), ), - expRows: rows( + ExpRows: rows( row(bool(true)), ), - compare: compareExactUnordered, + Compare: CompareExactUnordered, }, { - sqls: sqls( + SQLs: sqls( "select i1 in (1, 1000) from in_all_types", ), - expHdrs: hdrs( + ExpHdrs: hdrs( hdr("", fldTypeBool), ), - expRows: rows( + ExpRows: rows( row(bool(true)), ), - compare: compareExactUnordered, + Compare: CompareExactUnordered, }, { - sqls: sqls( + SQLs: sqls( "select b1 in (true, false) from in_all_types", ), - expHdrs: hdrs( + ExpHdrs: hdrs( hdr("", fldTypeBool), ), - expRows: rows( + ExpRows: rows( row(bool(true)), ), - compare: compareExactUnordered, + Compare: CompareExactUnordered, }, { - sqls: sqls( + SQLs: sqls( "select d1 in (1.23, 4.56) from in_all_types", ), - expHdrs: hdrs( + ExpHdrs: hdrs( hdr("", fldTypeBool), ), - expRows: rows( + ExpRows: rows( row(bool(false)), ), - compare: compareExactUnordered, + Compare: CompareExactUnordered, }, { - sqls: sqls( + SQLs: sqls( "select id1 in (3, 7) from in_all_types", ), - expHdrs: hdrs( + ExpHdrs: hdrs( hdr("", fldTypeBool), ), - expRows: rows( + ExpRows: rows( row(bool(false)), ), - compare: compareExactUnordered, + Compare: CompareExactUnordered, }, { - sqls: sqls( + SQLs: sqls( "select ids1 in ([101, 102], [456, 789]) from in_all_types", ), - expHdrs: hdrs( + ExpHdrs: hdrs( hdr("", fldTypeBool), ), - expRows: rows( + ExpRows: rows( row(bool(true)), ), - compare: compareExactUnordered, + Compare: CompareExactUnordered, }, { - sqls: sqls( + SQLs: sqls( "select s1 in ('foo', 'bar') from in_all_types", ), - expHdrs: hdrs( + ExpHdrs: hdrs( hdr("", fldTypeBool), ), - expRows: rows( + ExpRows: rows( row(bool(true)), ), - compare: compareExactUnordered, + Compare: CompareExactUnordered, }, { - sqls: sqls( + SQLs: sqls( "select ss1 in (['a', 'b'], ['101', '102']) from in_all_types", ), - expHdrs: hdrs( + ExpHdrs: hdrs( hdr("", fldTypeBool), ), - expRows: rows( + ExpRows: rows( row(bool(true)), ), - compare: compareExactUnordered, + Compare: CompareExactUnordered, }, { - sqls: sqls( + SQLs: sqls( "select t1 in ('2010-11-01T22:08:41+00:00', '2013-11-01T22:08:41+00:00', '2012-11-01T22:08:41+00:00') from in_all_types", ), - expHdrs: hdrs( + ExpHdrs: hdrs( hdr("", fldTypeBool), ), - expRows: rows( + ExpRows: rows( row(bool(true)), ), - compare: compareExactUnordered, + Compare: CompareExactUnordered, }, }, } // NOT IN tests -var notInTests = tableTest{ - table: tbl( +var notInTests = TableTest{ + Table: tbl( "not_in_all_types", srcHdrs( srcHdr("_id", fldTypeID), @@ -150,114 +150,114 @@ var notInTests = tableTest{ srcRow(int64(1), int64(1000), bool(true), float64(12.34), int64(20), []int64{101, 102}, string("foo"), []string{"101", "102"}, knownTimestamp()), ), ), - sqlTests: []sqlTest{ + SQLTests: []SQLTest{ { - sqls: sqls( + SQLs: sqls( "select _id not in (1, 10) from not_in_all_types", ), - expHdrs: hdrs( + ExpHdrs: hdrs( hdr("", fldTypeBool), ), - expRows: rows( + ExpRows: rows( row(bool(false)), ), - compare: compareExactUnordered, + Compare: CompareExactUnordered, }, { - sqls: sqls( + SQLs: sqls( "select i1 not in (1, 1000) from not_in_all_types", ), - expHdrs: hdrs( + ExpHdrs: hdrs( hdr("", fldTypeBool), ), - expRows: rows( + ExpRows: rows( row(bool(false)), ), - compare: compareExactUnordered, + Compare: CompareExactUnordered, }, { - sqls: sqls( + SQLs: sqls( "select b1 not in (true, false) from not_in_all_types", ), - expHdrs: hdrs( + ExpHdrs: hdrs( hdr("", fldTypeBool), ), - expRows: rows( + ExpRows: rows( row(bool(false)), ), - compare: compareExactUnordered, + Compare: CompareExactUnordered, }, { - sqls: sqls( + SQLs: sqls( "select d1 not in (1.23, 4.56) from not_in_all_types", ), - expHdrs: hdrs( + ExpHdrs: hdrs( hdr("", fldTypeBool), ), - expRows: rows( + ExpRows: rows( row(bool(true)), ), - compare: compareExactUnordered, + Compare: CompareExactUnordered, }, { - sqls: sqls( + SQLs: sqls( "select id1 not in (3, 7) from not_in_all_types", ), - expHdrs: hdrs( + ExpHdrs: hdrs( hdr("", fldTypeBool), ), - expRows: rows( + ExpRows: rows( row(bool(true)), ), - compare: compareExactUnordered, + Compare: CompareExactUnordered, }, { - sqls: sqls( + SQLs: sqls( "select ids1 not in ([101, 102], [456, 789]) from not_in_all_types", ), - expHdrs: hdrs( + ExpHdrs: hdrs( hdr("", fldTypeBool), ), - expRows: rows( + ExpRows: rows( row(bool(false)), ), - compare: compareExactUnordered, + Compare: CompareExactUnordered, }, { - sqls: sqls( + SQLs: sqls( "select s1 not in ('foo', 'bar') from not_in_all_types", ), - expHdrs: hdrs( + ExpHdrs: hdrs( hdr("", fldTypeBool), ), - expRows: rows( + ExpRows: rows( row(bool(false)), ), - compare: compareExactUnordered, + Compare: CompareExactUnordered, }, { - sqls: sqls( + SQLs: sqls( "select ss1 not in (['a', 'b'], ['101', '102']) from not_in_all_types", ), - expHdrs: hdrs( + ExpHdrs: hdrs( hdr("", fldTypeBool), ), - expRows: rows( + ExpRows: rows( row(bool(false)), ), - compare: compareExactUnordered, + Compare: CompareExactUnordered, }, { - sqls: sqls( + SQLs: sqls( "select t1 not in ('2010-11-01T22:08:41+00:00', '2013-11-01T22:08:41+00:00', '2012-11-01T22:08:41+00:00') from not_in_all_types", ), - expHdrs: hdrs( + ExpHdrs: hdrs( hdr("", fldTypeBool), ), - expRows: rows( + ExpRows: rows( row(bool(false)), ), - compare: compareExactUnordered, + Compare: CompareExactUnordered, }, }, } diff --git a/sql3/test/defs/defs_inserts.go b/sql3/test/defs/defs_inserts.go new file mode 100644 index 000000000..e366c7a16 --- /dev/null +++ b/sql3/test/defs/defs_inserts.go @@ -0,0 +1,129 @@ +package defs + +var insertTest = TableTest{ + Table: tbl( + "testinsert", + srcHdrs( + srcHdr("_id", fldTypeID), + srcHdr("a", fldTypeInt, "min 0", "max 1000"), + srcHdr("b", fldTypeInt, "min 0", "max 1000"), + srcHdr("s", fldTypeString), + srcHdr("bl", fldTypeBool), + srcHdr("d", fldTypeDecimal2), + srcHdr("event", fldTypeStringSet), + srcHdr("ievent", fldTypeIDSet), + ), + nil, + ), + SQLTests: []SQLTest{ + { + // Insert + SQLs: sqls( + "insert into testinsert (_id, a, b, s, bl, d, event, ievent) values (4, 40, 400, 'foo', false, 10.12, ['A', 'B', 'C'], [1, 2, 3])", + ), + ExpHdrs: hdrs(), + ExpRows: rows(), + Compare: CompareExactUnordered, + }, + { + // Replace + SQLs: sqls( + "replace into testinsert (_id, a, b, s, bl, d, event, ievent) values (4, 40, 400, 'foo', false, 10.12, ['A', 'B', 'C'], [1, 2, 3])", + ), + ExpHdrs: hdrs(), + ExpRows: rows(), + Compare: CompareExactUnordered, + }, + { + // Insert multiple tuples + SQLs: sqls( + "insert into testinsert (_id, a, b, s, bl, d, event, ievent) values (4, 40, 400, 'foo', false, 10.12, ['A', 'B', 'C'], [1, 2, 3]), (5, 50, 500, 'var', true, 20.24, ['X', 'Y', 'Z'], [4, 5, 6])", + ), + ExpHdrs: hdrs(), + ExpRows: rows(), + Compare: CompareExactUnordered, + }, + { + // Insert with nulls + SQLs: sqls( + "insert into testinsert (_id, a, b, s, bl, d, event, ievent) values (5, null, null, null, null, null, null, null)", + "insert into testinsert (_id, a, b, s, bl, d, event, ievent) values (6, 1, null, null, null, null, null, null)", + ), + ExpHdrs: hdrs(), + ExpRows: rows(), + Compare: CompareExactUnordered, + }, + { + // Insert with exprs + SQLs: sqls( + "insert into testinsert (_id, a, b, s, bl, d, event, ievent) values (4, 40*10, 400+1, 'foo' || 'bar', 1 > 2, 10.12 + 3.1, ['A', 'B', 'C'], [1, 2, 3])", + ), + ExpHdrs: hdrs(), + ExpRows: rows(), + Compare: CompareExactUnordered, + }, + { + // InsertBadTable + SQLs: sqls( + "insert into ifoo (a, b) values (1, 2)", + ), + ExpErr: "table 'ifoo' not found", + }, + { + // InsertBadColumn + SQLs: sqls( + "insert into testinsert (c, b) values (1, 2)", + ), + ExpErr: "column 'c' not found", + }, + { + // InsertDupeColumn + SQLs: sqls( + "insert into testinsert (a, a, b) values (1, 2)", + ), + ExpErr: "duplicate column 'a'", + }, + { + // InsertMismatchColumnValues + SQLs: sqls( + "insert into testinsert (_id, a, b) values (1)", + ), + ExpErr: "mismatch in the count of expressions and target columns", + }, + { + // InsertHandleMissingColumns + SQLs: sqls( + "insert into testinsert values (4, 40, 400)", + ), + ExpErr: "mismatch in the count of expressions and target columns", + }, + { + // InsertHandleMissingId + SQLs: sqls( + "insert into testinsert (a, b) values (1, 2)", + ), + ExpErr: "insert column list must have '_id' column specified", + }, + { + // InsertHandleMissingIdPlusOneOther + SQLs: sqls( + "insert into testinsert (_id) values (1)", + ), + ExpErr: "insert column list must have at least one non '_id' column specified", + }, + { + // InsertSetsTypeError + SQLs: sqls( + "insert into testinsert (_id, a, event) values (4, 40, [101, 150])", + ), + ExpErr: "an expression of type 'IDSET' cannot be assigned to type 'STRINGSET'", + }, + { + // InsertSetsTypeError2 + SQLs: sqls( + "insert into testinsert (_id, a, ievent) values (4, 40, ['POST', 'GET'])", + ), + ExpErr: "an expression of type 'STRINGSET' cannot be assigned to type 'IDSET'", + }, + }, +} diff --git a/sql3/sql_defs_join_test.go b/sql3/test/defs/defs_join.go similarity index 81% rename from sql3/sql_defs_join_test.go rename to sql3/test/defs/defs_join.go index 226a3dffe..80a5232d1 100644 --- a/sql3/sql_defs_join_test.go +++ b/sql3/test/defs/defs_join.go @@ -1,9 +1,9 @@ -package sql3_test +package defs // join tests -var joinTestsUsers = tableTest{ +var joinTestsUsers = TableTest{ name: "jointestusers", - table: tbl( + Table: tbl( "users", srcHdrs( srcHdr("_id", fldTypeID), @@ -17,12 +17,12 @@ var joinTestsUsers = tableTest{ srcRow(int64(3), string("d"), int64(34)), ), ), - sqlTests: nil, + SQLTests: nil, } -var joinTestsOrders = tableTest{ +var joinTestsOrders = TableTest{ name: "jointestorders", - table: tbl( + Table: tbl( "orders", srcHdrs( srcHdr("_id", fldTypeID), @@ -38,28 +38,28 @@ var joinTestsOrders = tableTest{ srcRow(int64(5), int64(2), float64(1.99)), ), ), - sqlTests: nil, + SQLTests: nil, } -var joinTests = tableTest{ +var joinTests = TableTest{ name: "innerjointest", - sqlTests: []sqlTest{ + SQLTests: []SQLTest{ { name: "innerjoin-aggregate-groupby", - sqls: sqls( + SQLs: sqls( "select u._id, sum(orders.price) from orders o inner join users u on o.userid = u._id group by u._id;", ), - expHdrs: hdrs( + ExpHdrs: hdrs( hdr("_id", fldTypeID), hdr("", fldTypeDecimal2), ), - expRows: rows( + ExpRows: rows( row(int64(1), float64(22.98)), row(int64(0), float64(3.99)), row(int64(2), float64(16.98)), row(int64(3), float64(5.99)), ), - compare: compareExactOrdered, + Compare: CompareExactOrdered, }, }, } diff --git a/sql3/test/defs/defs_keyed.go b/sql3/test/defs/defs_keyed.go new file mode 100644 index 000000000..dd3ed858e --- /dev/null +++ b/sql3/test/defs/defs_keyed.go @@ -0,0 +1,93 @@ +package defs + +var keyed = TableTest{ + Table: tbl( + "keyed", + srcHdrs( + srcHdr("_id", fldTypeString), + srcHdr("an_int", fldTypeInt, "min 0", "max 100"), + srcHdr("an_id_set", fldTypeIDSet), + srcHdr("an_id", fldTypeID), + srcHdr("a_string", fldTypeString), + srcHdr("a_string_set", fldTypeStringSet), + ), + srcRows( + srcRow("one", int64(11), []int64{11, 12, 13}, int64(101), "str1", []string{"a1", "b1", "c1"}), + srcRow("two", int64(22), []int64{21, 22, 23}, int64(201), "str2", []string{"a2", "b2", "c2"}), + srcRow("three", int64(33), []int64{31, 32, 33}, int64(301), "str3", []string{"a3", "b3", "c3"}), + srcRow("four", int64(44), []int64{41, 42, 43}, int64(401), "str4", []string{"a4", "b4", "c4"}), + ), + ), + SQLTests: []SQLTest{ + { + // Select all. + name: "select-all", + SQLs: sqls( + "select * from keyed", + "select _id, an_int, an_id_set, an_id, a_string, a_string_set from keyed", + ), + ExpHdrs: hdrs( + hdr("_id", fldTypeString), + hdr("an_int", fldTypeInt), + hdr("an_id_set", fldTypeIDSet), + hdr("an_id", fldTypeID), + hdr("a_string", fldTypeString), + hdr("a_string_set", fldTypeStringSet), + ), + ExpRows: rows( + row("one", int64(11), []int64{11, 12, 13}, int64(101), "str1", []string{"a1", "b1", "c1"}), + row("two", int64(22), []int64{21, 22, 23}, int64(201), "str2", []string{"a2", "b2", "c2"}), + row("three", int64(33), []int64{31, 32, 33}, int64(301), "str3", []string{"a3", "b3", "c3"}), + row("four", int64(44), []int64{41, 42, 43}, int64(401), "str4", []string{"a4", "b4", "c4"}), + ), + Compare: CompareExactUnordered, + SortStringKeys: true, + }, + { + // Select all with top. + name: "select-all-with-top", + SQLs: sqls( + "select top(2) * from keyed", + ), + ExpHdrs: hdrs( + hdr("_id", fldTypeString), + hdr("an_int", fldTypeInt), + hdr("an_id_set", fldTypeIDSet), + hdr("an_id", fldTypeID), + hdr("a_string", fldTypeString), + hdr("a_string_set", fldTypeStringSet), + ), + ExpRows: rows( + row("one", int64(11), []int64{11, 12, 13}, int64(101), "str1", []string{"a1", "b1", "c1"}), + row("two", int64(22), []int64{21, 22, 23}, int64(201), "str2", []string{"a2", "b2", "c2"}), + row("three", int64(33), []int64{31, 32, 33}, int64(301), "str3", []string{"a3", "b3", "c3"}), + row("four", int64(44), []int64{41, 42, 43}, int64(401), "str4", []string{"a4", "b4", "c4"}), + ), + Compare: CompareIncludedIn, + SortStringKeys: true, + ExpRowCount: 2, + }, + { + // Select all with where on int field. + name: "select-all-with-where", + SQLs: sqls( + "select * from keyed where an_int = 22", + "select * from keyed where a_string = 'str2'", + "select * from keyed where an_id = 201", + ), + ExpHdrs: hdrs( + hdr("_id", fldTypeString), + hdr("an_int", fldTypeInt), + hdr("an_id_set", fldTypeIDSet), + hdr("an_id", fldTypeID), + hdr("a_string", fldTypeString), + hdr("a_string_set", fldTypeStringSet), + ), + ExpRows: rows( + row("two", int64(22), []int64{21, 22, 23}, int64(201), "str2", []string{"a2", "b2", "c2"}), + ), + Compare: CompareExactUnordered, + SortStringKeys: true, + }, + }, +} diff --git a/sql3/test/defs/defs_keyed_insert.go b/sql3/test/defs/defs_keyed_insert.go new file mode 100644 index 000000000..48f150c6d --- /dev/null +++ b/sql3/test/defs/defs_keyed_insert.go @@ -0,0 +1,30 @@ +package defs + +var keyedInsertTest = TableTest{ + name: "keyedinsert", + Table: tbl( + "testkeyedinsert", + srcHdrs( + srcHdr("_id", fldTypeString), + srcHdr("a", fldTypeInt, "min 0", "max 1000"), + srcHdr("b", fldTypeInt, "min 0", "max 1000"), + srcHdr("s", fldTypeString), + srcHdr("bl", fldTypeBool), + srcHdr("d", fldTypeDecimal2), + srcHdr("event", fldTypeStringSet), + srcHdr("ievent", fldTypeIDSet), + ), + nil, + ), + SQLTests: []SQLTest{ + { + // Insert + SQLs: sqls( + "insert into testkeyedinsert (_id, a, b, s, bl, d, event, ievent) values ('four', 40, 400, 'foo', false, 10.12, ['A', 'B', 'C'], [1, 2, 3])", + ), + ExpHdrs: hdrs(), + ExpRows: rows(), + Compare: CompareExactUnordered, + }, + }, +} diff --git a/sql3/sql_defs_like_test.go b/sql3/test/defs/defs_like.go similarity index 61% rename from sql3/sql_defs_like_test.go rename to sql3/test/defs/defs_like.go index fabf339ea..e7276bec6 100644 --- a/sql3/sql_defs_like_test.go +++ b/sql3/test/defs/defs_like.go @@ -1,8 +1,8 @@ -package sql3_test +package defs // LIKE tests -var likeTests = tableTest{ - table: tbl( +var likeTests = TableTest{ + Table: tbl( "like_all_types", srcHdrs( srcHdr("_id", fldTypeID), @@ -19,73 +19,73 @@ var likeTests = tableTest{ srcRow(int64(1), int64(1000), bool(true), float64(12.34), int64(20), []int64{101, 102}, string("foo"), []string{"101", "102"}, knownTimestamp()), ), ), - sqlTests: []sqlTest{ + SQLTests: []SQLTest{ { - sqls: sqls( + SQLs: sqls( "select _id like '%f_' from like_all_types", ), - expErr: "operator 'LIKE' incompatible with type 'ID'", + ExpErr: "operator 'LIKE' incompatible with type 'ID'", }, { - sqls: sqls( + SQLs: sqls( "select i1 like '%f_' from like_all_types", ), - expErr: "operator 'LIKE' incompatible with type 'INT'", + ExpErr: "operator 'LIKE' incompatible with type 'INT'", }, { - sqls: sqls( + SQLs: sqls( "select b1 like '%f_' from like_all_types", ), - expErr: "operator 'LIKE' incompatible with type 'BOOL'", + ExpErr: "operator 'LIKE' incompatible with type 'BOOL'", }, { - sqls: sqls( + SQLs: sqls( "select d1 like '%f_' from like_all_types", ), - expErr: "operator 'LIKE' incompatible with type 'DECIMAL(2)'", + ExpErr: "operator 'LIKE' incompatible with type 'DECIMAL(2)'", }, { - sqls: sqls( + SQLs: sqls( "select id1 like '%f_' from like_all_types", ), - expErr: "operator 'LIKE' incompatible with type 'ID'", + ExpErr: "operator 'LIKE' incompatible with type 'ID'", }, { - sqls: sqls( + SQLs: sqls( "select ids1 like '%f_' from like_all_types", ), - expErr: "operator 'LIKE' incompatible with type 'IDSET'", + ExpErr: "operator 'LIKE' incompatible with type 'IDSET'", }, { - sqls: sqls( + SQLs: sqls( "select s1 like '%f_' from like_all_types", ), - expHdrs: hdrs( + ExpHdrs: hdrs( hdr("", fldTypeBool), ), - expRows: rows( + ExpRows: rows( row(bool(true)), ), - compare: compareExactUnordered, + Compare: CompareExactUnordered, }, { - sqls: sqls( + SQLs: sqls( "select ss1 like '%f_' from like_all_types", ), - expErr: "operator 'LIKE' incompatible with type 'STRINGSET'", + ExpErr: "operator 'LIKE' incompatible with type 'STRINGSET'", }, { - sqls: sqls( + SQLs: sqls( "select t1 like '%f_' from like_all_types", ), - expErr: "operator 'LIKE' incompatible with type 'TIMESTAMP'", + ExpErr: "operator 'LIKE' incompatible with type 'TIMESTAMP'", }, }, } // NOT LIKE tests -var notLikeTests = tableTest{ - table: tbl( +var notLikeTests = TableTest{ + Table: tbl( "not_like_all_types", srcHdrs( srcHdr("_id", fldTypeID), @@ -102,66 +102,66 @@ var notLikeTests = tableTest{ srcRow(int64(1), int64(1000), bool(true), float64(12.34), int64(20), []int64{101, 102}, string("foo"), []string{"101", "102"}, knownTimestamp()), ), ), - sqlTests: []sqlTest{ + SQLTests: []SQLTest{ { - sqls: sqls( + SQLs: sqls( "select _id not like '%f_' from not_like_all_types", ), - expErr: "operator 'NOTLIKE' incompatible with type 'ID'", + ExpErr: "operator 'NOTLIKE' incompatible with type 'ID'", }, { - sqls: sqls( + SQLs: sqls( "select i1 not like '%f_' from not_like_all_types", ), - expErr: "operator 'NOTLIKE' incompatible with type 'INT'", + ExpErr: "operator 'NOTLIKE' incompatible with type 'INT'", }, { - sqls: sqls( + SQLs: sqls( "select b1 not like '%f_' from not_like_all_types", ), - expErr: "operator 'NOTLIKE' incompatible with type 'BOOL'", + ExpErr: "operator 'NOTLIKE' incompatible with type 'BOOL'", }, { - sqls: sqls( + SQLs: sqls( "select d1 not like '%f_' from not_like_all_types", ), - expErr: "operator 'NOTLIKE' incompatible with type 'DECIMAL(2)'", + ExpErr: "operator 'NOTLIKE' incompatible with type 'DECIMAL(2)'", }, { - sqls: sqls( + SQLs: sqls( "select id1 not like '%f_' from not_like_all_types", ), - expErr: "operator 'NOTLIKE' incompatible with type 'ID'", + ExpErr: "operator 'NOTLIKE' incompatible with type 'ID'", }, { - sqls: sqls( + SQLs: sqls( "select ids1 not like '%f_' from not_like_all_types", ), - expErr: "operator 'NOTLIKE' incompatible with type 'IDSET'", + ExpErr: "operator 'NOTLIKE' incompatible with type 'IDSET'", }, { - sqls: sqls( + SQLs: sqls( "select s1 not like '%f_' from not_like_all_types", ), - expHdrs: hdrs( + ExpHdrs: hdrs( hdr("", fldTypeBool), ), - expRows: rows( + ExpRows: rows( row(bool(false)), ), - compare: compareExactUnordered, + Compare: CompareExactUnordered, }, { - sqls: sqls( + SQLs: sqls( "select ss1 not like '%f_' from not_like_all_types", ), - expErr: "operator 'NOTLIKE' incompatible with type 'STRINGSET'", + ExpErr: "operator 'NOTLIKE' incompatible with type 'STRINGSET'", }, { - sqls: sqls( + SQLs: sqls( "select t1 not like '%f_' from not_like_all_types", ), - expErr: "operator 'NOTLIKE' incompatible with type 'TIMESTAMP'", + ExpErr: "operator 'NOTLIKE' incompatible with type 'TIMESTAMP'", }, }, } diff --git a/sql3/test/defs/defs_minmaxnegative.go b/sql3/test/defs/defs_minmaxnegative.go new file mode 100644 index 000000000..7f3d918d5 --- /dev/null +++ b/sql3/test/defs/defs_minmaxnegative.go @@ -0,0 +1,19 @@ +package defs + +var minmaxnegatives = TableTest{ + name: "minmaxnegatives", + Table: tbl( + "minmaxnegatives", + srcHdrs( + srcHdr("_id", fldTypeID), + srcHdr("positive_int", fldTypeInt, "min 10", "max 100"), + srcHdr("negative_int", fldTypeInt, "min -100", "max -10"), + ), + srcRows( + srcRow(int64(1), int64(11), int64(-11)), + srcRow(int64(2), int64(22), int64(-22)), + srcRow(int64(3), int64(33), int64(-33)), + ), + ), + SQLTests: []SQLTest{}, +} diff --git a/sql3/sql_defs_null_test.go b/sql3/test/defs/defs_null.go similarity index 64% rename from sql3/sql_defs_null_test.go rename to sql3/test/defs/defs_null.go index c55b2cda6..936b13718 100644 --- a/sql3/sql_defs_null_test.go +++ b/sql3/test/defs/defs_null.go @@ -1,8 +1,8 @@ -package sql3_test +package defs // NULL tests -var nullTests = tableTest{ - table: tbl( +var nullTests = TableTest{ + Table: tbl( "null_all_types", srcHdrs( srcHdr("_id", fldTypeID), @@ -20,133 +20,133 @@ var nullTests = tableTest{ srcRow(int64(1), int64(1), nil, nil, nil, nil, nil, nil, nil, nil), ), ), - sqlTests: []sqlTest{ + SQLTests: []SQLTest{ { - sqls: sqls( + SQLs: sqls( "select _id is null from null_all_types", ), - expHdrs: hdrs( + ExpHdrs: hdrs( hdr("", fldTypeBool), ), - expRows: rows( + ExpRows: rows( row(bool(false)), ), - compare: compareExactUnordered, + Compare: CompareExactUnordered, }, { - sqls: sqls( + SQLs: sqls( "select i is null from null_all_types", ), - expHdrs: hdrs( + ExpHdrs: hdrs( hdr("", fldTypeBool), ), - expRows: rows( + ExpRows: rows( row(bool(false)), ), - compare: compareExactUnordered, + Compare: CompareExactUnordered, }, { - sqls: sqls( + SQLs: sqls( "select i1 is null from null_all_types", ), - expHdrs: hdrs( + ExpHdrs: hdrs( hdr("", fldTypeBool), ), - expRows: rows( + ExpRows: rows( row(bool(true)), ), - compare: compareExactUnordered, + Compare: CompareExactUnordered, }, { - sqls: sqls( + SQLs: sqls( "select b1 is null from null_all_types", ), - expHdrs: hdrs( + ExpHdrs: hdrs( hdr("", fldTypeBool), ), - expRows: rows( + ExpRows: rows( row(bool(true)), ), - compare: compareExactUnordered, + Compare: CompareExactUnordered, }, { - sqls: sqls( + SQLs: sqls( "select d1 is null from null_all_types", ), - expHdrs: hdrs( + ExpHdrs: hdrs( hdr("", fldTypeBool), ), - expRows: rows( + ExpRows: rows( row(bool(true)), ), - compare: compareExactUnordered, + Compare: CompareExactUnordered, }, { - sqls: sqls( + SQLs: sqls( "select id1 is null from null_all_types", ), - expHdrs: hdrs( + ExpHdrs: hdrs( hdr("", fldTypeBool), ), - expRows: rows( + ExpRows: rows( row(bool(true)), ), - compare: compareExactUnordered, + Compare: CompareExactUnordered, }, { - sqls: sqls( + SQLs: sqls( "select ids1 is null from null_all_types", ), - expHdrs: hdrs( + ExpHdrs: hdrs( hdr("", fldTypeBool), ), - expRows: rows( + ExpRows: rows( row(bool(true)), ), - compare: compareExactUnordered, + Compare: CompareExactUnordered, }, { - sqls: sqls( + SQLs: sqls( "select s1 is null from null_all_types", ), - expHdrs: hdrs( + ExpHdrs: hdrs( hdr("", fldTypeBool), ), - expRows: rows( + ExpRows: rows( row(bool(true)), ), - compare: compareExactUnordered, + Compare: CompareExactUnordered, }, { - sqls: sqls( + SQLs: sqls( "select ss1 is null from null_all_types", ), - expHdrs: hdrs( + ExpHdrs: hdrs( hdr("", fldTypeBool), ), - expRows: rows( + ExpRows: rows( row(bool(true)), ), - compare: compareExactUnordered, + Compare: CompareExactUnordered, }, { - sqls: sqls( + SQLs: sqls( "select t1 is null from null_all_types", ), - expHdrs: hdrs( + ExpHdrs: hdrs( hdr("", fldTypeBool), ), - expRows: rows( + ExpRows: rows( row(bool(true)), ), - compare: compareExactUnordered, + Compare: CompareExactUnordered, }, }, } // NOT NULL tests -var notNullTests = tableTest{ - table: tbl( +var notNullTests = TableTest{ + Table: tbl( "not_null_all_types", srcHdrs( srcHdr("_id", fldTypeID), @@ -164,121 +164,121 @@ var notNullTests = tableTest{ srcRow(int64(1), int64(1), nil, nil, nil, nil, nil, nil, nil, nil), ), ), - sqlTests: []sqlTest{ + SQLTests: []SQLTest{ { - sqls: sqls( + SQLs: sqls( "select _id is not null from not_null_all_types", ), - expHdrs: hdrs( + ExpHdrs: hdrs( hdr("", fldTypeBool), ), - expRows: rows( + ExpRows: rows( row(bool(true)), ), - compare: compareExactUnordered, + Compare: CompareExactUnordered, }, { - sqls: sqls( + SQLs: sqls( "select i1 is not null from not_null_all_types", ), - expHdrs: hdrs( + ExpHdrs: hdrs( hdr("", fldTypeBool), ), - expRows: rows( + ExpRows: rows( row(bool(false)), ), - compare: compareExactUnordered, + Compare: CompareExactUnordered, }, { - sqls: sqls( + SQLs: sqls( "select b1 is not null from not_null_all_types", ), - expHdrs: hdrs( + ExpHdrs: hdrs( hdr("", fldTypeBool), ), - expRows: rows( + ExpRows: rows( row(bool(false)), ), - compare: compareExactUnordered, + Compare: CompareExactUnordered, }, { - sqls: sqls( + SQLs: sqls( "select d1 is not null from not_null_all_types", ), - expHdrs: hdrs( + ExpHdrs: hdrs( hdr("", fldTypeBool), ), - expRows: rows( + ExpRows: rows( row(bool(false)), ), - compare: compareExactUnordered, + Compare: CompareExactUnordered, }, { - sqls: sqls( + SQLs: sqls( "select id1 is not null from not_null_all_types", ), - expHdrs: hdrs( + ExpHdrs: hdrs( hdr("", fldTypeBool), ), - expRows: rows( + ExpRows: rows( row(bool(false)), ), - compare: compareExactUnordered, + Compare: CompareExactUnordered, }, { - sqls: sqls( + SQLs: sqls( "select ids1 is not null from not_null_all_types", ), - expHdrs: hdrs( + ExpHdrs: hdrs( hdr("", fldTypeBool), ), - expRows: rows( + ExpRows: rows( row(bool(false)), ), - compare: compareExactUnordered, + Compare: CompareExactUnordered, }, { - sqls: sqls( + SQLs: sqls( "select s1 is not null from not_null_all_types", ), - expHdrs: hdrs( + ExpHdrs: hdrs( hdr("", fldTypeBool), ), - expRows: rows( + ExpRows: rows( row(bool(false)), ), - compare: compareExactUnordered, + Compare: CompareExactUnordered, }, { - sqls: sqls( + SQLs: sqls( "select ss1 is not null from not_null_all_types", ), - expHdrs: hdrs( + ExpHdrs: hdrs( hdr("", fldTypeBool), ), - expRows: rows( + ExpRows: rows( row(bool(false)), ), - compare: compareExactUnordered, + Compare: CompareExactUnordered, }, { - sqls: sqls( + SQLs: sqls( "select t1 is not null from not_null_all_types", ), - expHdrs: hdrs( + ExpHdrs: hdrs( hdr("", fldTypeBool), ), - expRows: rows( + ExpRows: rows( row(bool(false)), ), - compare: compareExactUnordered, + Compare: CompareExactUnordered, }, }, } // NULL filter condition tests -var nullFilterTests = tableTest{ - table: tbl( +var nullFilterTests = TableTest{ + Table: tbl( "null_filter_all_types", srcHdrs( srcHdr("_id", fldTypeID), @@ -297,150 +297,150 @@ var nullFilterTests = tableTest{ srcRow(int64(2), int64(1), int64(10), bool(true), float64(10), int64(20), []int64{101}, string("foo"), []string{"GET", "POST"}, knownTimestamp()), ), ), - sqlTests: []sqlTest{ + SQLTests: []SQLTest{ { - sqls: sqls( + SQLs: sqls( "select _id from null_filter_all_types where _id is null", ), - expErr: "'_id' column cannot be used in a is/is not null filter expression", + ExpErr: "'_id' column cannot be used in a is/is not null filter expression", }, { - sqls: sqls( + SQLs: sqls( "select _id from null_filter_all_types where _id is not null", ), - expErr: "'_id' column cannot be used in a is/is not null filter expression", + ExpErr: "'_id' column cannot be used in a is/is not null filter expression", }, { - sqls: sqls( + SQLs: sqls( "select _id from null_filter_all_types where i1 is null", ), - expHdrs: hdrs( + ExpHdrs: hdrs( hdr("_id", fldTypeID), ), - expRows: rows( + ExpRows: rows( row(int64(1)), ), - compare: compareExactUnordered, + Compare: CompareExactUnordered, }, { - sqls: sqls( + SQLs: sqls( "select _id from null_filter_all_types where i1 is not null", ), - expHdrs: hdrs( + ExpHdrs: hdrs( hdr("_id", fldTypeID), ), - expRows: rows( + ExpRows: rows( row(int64(2)), ), - compare: compareExactUnordered, + Compare: CompareExactUnordered, }, { - sqls: sqls( + SQLs: sqls( "select _id from null_filter_all_types where b1 is null", ), - expErr: "unsupported type 'BOOL' for is/is not null filter expression", + ExpErr: "unsupported type 'BOOL' for is/is not null filter expression", }, { - sqls: sqls( + SQLs: sqls( "select _id from null_filter_all_types where b1 is not null", ), - expErr: "unsupported type 'BOOL' for is/is not null filter expression", + ExpErr: "unsupported type 'BOOL' for is/is not null filter expression", }, { - sqls: sqls( + SQLs: sqls( "select _id from null_filter_all_types where d1 is null", ), - expHdrs: hdrs( + ExpHdrs: hdrs( hdr("_id", fldTypeID), ), - expRows: rows( + ExpRows: rows( row(int64(1)), ), - compare: compareExactUnordered, + Compare: CompareExactUnordered, }, { - sqls: sqls( + SQLs: sqls( "select _id from null_filter_all_types where d1 is not null", ), - expHdrs: hdrs( + ExpHdrs: hdrs( hdr("_id", fldTypeID), ), - expRows: rows( + ExpRows: rows( row(int64(2)), ), - compare: compareExactUnordered, + Compare: CompareExactUnordered, }, { - sqls: sqls( + SQLs: sqls( "select _id from null_filter_all_types where id1 is null", ), - expErr: "unsupported type 'ID' for is/is not null filter expression", + ExpErr: "unsupported type 'ID' for is/is not null filter expression", }, { - sqls: sqls( + SQLs: sqls( "select _id from null_filter_all_types where id1 is not null", ), - expErr: "unsupported type 'ID' for is/is not null filter expression", + ExpErr: "unsupported type 'ID' for is/is not null filter expression", }, { - sqls: sqls( + SQLs: sqls( "select _id from null_filter_all_types where ids1 is null", ), - expErr: "unsupported type 'IDSET' for is/is not null filter expression", + ExpErr: "unsupported type 'IDSET' for is/is not null filter expression", }, { - sqls: sqls( + SQLs: sqls( "select _id from null_filter_all_types where ids1 is not null", ), - expErr: "unsupported type 'IDSET' for is/is not null filter expression", + ExpErr: "unsupported type 'IDSET' for is/is not null filter expression", }, { - sqls: sqls( + SQLs: sqls( "select _id from null_filter_all_types where s1 is null", ), - expErr: "unsupported type 'STRING' for is/is not null filter expression", + ExpErr: "unsupported type 'STRING' for is/is not null filter expression", }, { - sqls: sqls( + SQLs: sqls( "select _id from null_filter_all_types where s1 is not null", ), - expErr: "unsupported type 'STRING' for is/is not null filter expression", + ExpErr: "unsupported type 'STRING' for is/is not null filter expression", }, { - sqls: sqls( + SQLs: sqls( "select _id from null_filter_all_types where ss1 is null", ), - expErr: "unsupported type 'STRINGSET' for is/is not null filter expression", + ExpErr: "unsupported type 'STRINGSET' for is/is not null filter expression", }, { - sqls: sqls( + SQLs: sqls( "select _id from null_filter_all_types where ss1 is not null", ), - expErr: "unsupported type 'STRINGSET' for is/is not null filter expression", + ExpErr: "unsupported type 'STRINGSET' for is/is not null filter expression", }, { - sqls: sqls( + SQLs: sqls( "select _id from null_filter_all_types where t1 is null", ), - expHdrs: hdrs( + ExpHdrs: hdrs( hdr("_id", fldTypeID), ), - expRows: rows( + ExpRows: rows( row(int64(1)), ), - compare: compareExactUnordered, + Compare: CompareExactUnordered, }, { - sqls: sqls( + SQLs: sqls( "select _id from null_filter_all_types where t1 is not null", ), - expHdrs: hdrs( + ExpHdrs: hdrs( hdr("_id", fldTypeID), ), - expRows: rows( + ExpRows: rows( row(int64(2)), ), - compare: compareExactUnordered, + Compare: CompareExactUnordered, }, }, } diff --git a/sql3/sql_defs_set_functions_test.go b/sql3/test/defs/defs_set_functions.go similarity index 78% rename from sql3/sql_defs_set_functions_test.go rename to sql3/test/defs/defs_set_functions.go index 35b5b61f6..51f474c02 100644 --- a/sql3/sql_defs_set_functions_test.go +++ b/sql3/test/defs/defs_set_functions.go @@ -1,9 +1,9 @@ -package sql3_test +package defs // set literal tests -var setLiteralTests = tableTest{ +var setLiteralTests = TableTest{ name: "selectwithsetliterals", - table: tbl( + Table: tbl( "selectwithsetliterals", srcHdrs( srcHdr("_id", fldTypeID), @@ -18,40 +18,40 @@ var setLiteralTests = tableTest{ srcRow(int64(3), int64(30), int64(300), []string{"GET", "POST"}, []int64{101}), ), ), - sqlTests: []sqlTest{ + SQLTests: []SQLTest{ { // SetContainsSelectList name: "set-contains-select-list", - sqls: sqls( + SQLs: sqls( "select _id, setcontains(event, 'POST') from selectwithsetliterals", ), - expHdrs: hdrs( + ExpHdrs: hdrs( hdr("_id", fldTypeID), hdr("", fldTypeBool), ), - expRows: rows( + ExpRows: rows( row(int64(1), true), row(int64(2), false), row(int64(3), true), ), - compare: compareExactUnordered, + Compare: CompareExactUnordered, }, { // SetContainsSelectListInt name: "set-contains-select-list-int", - sqls: sqls( + SQLs: sqls( "select _id, setcontains(ievent, 101) from selectwithsetliterals", ), - expHdrs: hdrs( + ExpHdrs: hdrs( hdr("_id", fldTypeID), hdr("", fldTypeBool), ), - expRows: rows( + ExpRows: rows( row(int64(1), nil), row(int64(2), nil), row(int64(3), true), ), - compare: compareExactUnordered, + Compare: CompareExactUnordered, }, { // SetContainsWithLiteral @@ -61,7 +61,7 @@ var setLiteralTests = tableTest{ // SetContainsWithLiteralAll // SetContainsWithLiteralAllInt name: "set-contains-with-literal", - sqls: sqls( + SQLs: sqls( "select _id, setcontains(['POST'], 'POST') from selectwithsetliterals", "select _id, setcontains([101], 101) from selectwithsetliterals", "select _id, setcontainsany(['POST'], ['POST']) from selectwithsetliterals", @@ -69,24 +69,24 @@ var setLiteralTests = tableTest{ "select _id, setcontainsall(['POST'], ['POST']) from selectwithsetliterals", "select _id, setcontainsall([101], [101]) from selectwithsetliterals", ), - expHdrs: hdrs( + ExpHdrs: hdrs( hdr("_id", fldTypeID), hdr("", fldTypeBool), ), - expRows: rows( + ExpRows: rows( row(int64(1), true), row(int64(2), true), row(int64(3), true), ), - compare: compareExactUnordered, + Compare: CompareExactUnordered, }, }, } // set function tests -var setFunctionTests = tableTest{ +var setFunctionTests = TableTest{ name: "selectwithset", - table: tbl( + Table: tbl( "selectwithset", srcHdrs( srcHdr("_id", fldTypeID), @@ -101,139 +101,139 @@ var setFunctionTests = tableTest{ srcRow(int64(3), int64(30), int64(300), []string{"GET", "POST"}, nil), ), ), - sqlTests: []sqlTest{ + SQLTests: []SQLTest{ { name: "set-contains", - sqls: sqls( + SQLs: sqls( "select * from selectwithset where setcontains(event, 'POST')", ), - expHdrs: hdrs( + ExpHdrs: hdrs( hdr("_id", fldTypeID), hdr("a", fldTypeInt), hdr("b", fldTypeInt), hdr("event", fldTypeStringSet), hdr("ievent", fldTypeIDSet), ), - expRows: rows( + ExpRows: rows( row(int64(1), int64(10), int64(100), []string{"POST"}, []int64{101}), row(int64(3), int64(30), int64(300), []string{"GET", "POST"}, nil), ), - compare: compareExactUnordered, - sortStringKeys: true, + Compare: CompareExactUnordered, + SortStringKeys: true, }, { // SetContains - sqls: sqls( + SQLs: sqls( "select * from selectwithset where setcontains(event, 'POST')", ), - expHdrs: hdrs( + ExpHdrs: hdrs( hdr("_id", fldTypeID), hdr("a", fldTypeInt), hdr("b", fldTypeInt), hdr("event", fldTypeStringSet), hdr("ievent", fldTypeIDSet), ), - expRows: rows( + ExpRows: rows( row(int64(1), int64(10), int64(100), []string{"POST"}, []int64{101}), row(int64(3), int64(30), int64(300), []string{"GET", "POST"}, nil), ), - compare: compareExactUnordered, - sortStringKeys: true, + Compare: CompareExactUnordered, + SortStringKeys: true, }, { // SetContainsInt name: "set-contains-int", - sqls: sqls( + SQLs: sqls( "select * from selectwithset where setcontains(ievent, 101)", ), - expHdrs: hdrs( + ExpHdrs: hdrs( hdr("_id", fldTypeID), hdr("a", fldTypeInt), hdr("b", fldTypeInt), hdr("event", fldTypeStringSet), hdr("ievent", fldTypeIDSet), ), - expRows: rows( + ExpRows: rows( row(int64(1), int64(10), int64(100), []string{"POST"}, []int64{101}), ), - compare: compareExactUnordered, + Compare: CompareExactUnordered, }, { // SetContainsOrSetContains // SetContainsAny name: "set-contains-or-set-contains", - sqls: sqls( + SQLs: sqls( "select * from selectwithset where setcontains(event, 'POST') or setcontains(event, 'GET')", "select * from selectwithset where setcontainsany(event, ['POST', 'GET'])", ), - expHdrs: hdrs( + ExpHdrs: hdrs( hdr("_id", fldTypeID), hdr("a", fldTypeInt), hdr("b", fldTypeInt), hdr("event", fldTypeStringSet), hdr("ievent", fldTypeIDSet), ), - expRows: rows( + ExpRows: rows( row(int64(1), int64(10), int64(100), []string{"POST"}, []int64{101}), row(int64(2), int64(20), int64(200), []string{"GET"}, nil), row(int64(3), int64(30), int64(300), []string{"GET", "POST"}, nil), ), - compare: compareExactUnordered, - sortStringKeys: true, + Compare: CompareExactUnordered, + SortStringKeys: true, }, { // SetContainsAndSetContains // SetContainsAll name: "set-contains-and-set-contains", - sqls: sqls( + SQLs: sqls( "select * from selectwithset where setcontains(event, 'POST') and setcontains(event, 'GET')", "select * from selectwithset where setcontainsall(event, ['POST', 'GET'])", ), - expHdrs: hdrs( + ExpHdrs: hdrs( hdr("_id", fldTypeID), hdr("a", fldTypeInt), hdr("b", fldTypeInt), hdr("event", fldTypeStringSet), hdr("ievent", fldTypeIDSet), ), - expRows: rows( + ExpRows: rows( row(int64(3), int64(30), int64(300), []string{"GET", "POST"}, nil), ), - compare: compareExactUnordered, - sortStringKeys: true, + Compare: CompareExactUnordered, + SortStringKeys: true, }, { // SetContainsWrongType name: "set-contains-wrong-type", - sqls: sqls( + SQLs: sqls( "select * from selectwithset where setcontains(event, 1)", ), - expErr: "types 'STRINGSET' and 'INT' are not equatable", + ExpErr: "types 'STRINGSET' and 'INT' are not equatable", }, { // SetContainsWrongTypeInt name: "set-contains-wrong-type-int", - sqls: sqls( + SQLs: sqls( "select * from selectwithset where setcontains(ievent, 'foo')", ), - expErr: "types 'IDSET' and 'STRING' are not equatable", + ExpErr: "types 'IDSET' and 'STRING' are not equatable", }, { // SetContainsWrongTypeSet name: "set-contains-wrong-type-set", - sqls: sqls( + SQLs: sqls( "select * from selectwithset where setcontains(event, ['foo'])", ), - expErr: "types 'STRINGSET' and 'STRINGSET' are not equatable", + ExpErr: "types 'STRINGSET' and 'STRINGSET' are not equatable", }, }, } // set parameter tests -var setParameterTests = tableTest{ +var setParameterTests = TableTest{ - table: tbl( + Table: tbl( "selectwithsetparams", srcHdrs( srcHdr("_id", fldTypeID), @@ -248,59 +248,59 @@ var setParameterTests = tableTest{ srcRow(int64(3), int64(30), int64(300), []string{"GET", "POST"}, nil), ), ), - sqlTests: []sqlTest{ + SQLTests: []SQLTest{ { - sqls: sqls( + SQLs: sqls( "select setcontains(['POST', 'GET'])", ), - expErr: "count of formal parameters (2) does not match count of actual parameters (1)", + ExpErr: "count of formal parameters (2) does not match count of actual parameters (1)", }, { - sqls: sqls( + SQLs: sqls( "select setcontains(1, 2)", ), - expErr: "set expression expected", + ExpErr: "set expression expected", }, { - sqls: sqls( + SQLs: sqls( "select setcontains(['POST', 'GET'], 1)", ), - expErr: "types 'STRINGSET' and 'INT' are not equatable", + ExpErr: "types 'STRINGSET' and 'INT' are not equatable", }, { - sqls: sqls( + SQLs: sqls( "select setcontains([1, 2], '1')", ), - expErr: "types 'IDSET' and 'STRING' are not equatable", + ExpErr: "types 'IDSET' and 'STRING' are not equatable", }, { - sqls: sqls( + SQLs: sqls( "select setcontainsall(['POST', 'GET'])", "select setcontainsany(['POST', 'GET'])", ), - expErr: "count of formal parameters (2) does not match count of actual parameters (1)", + ExpErr: "count of formal parameters (2) does not match count of actual parameters (1)", }, { - sqls: sqls( + SQLs: sqls( "select setcontainsall(1, 2)", "select setcontainsany(1, 2)", ), - expErr: "set expression expected", + ExpErr: "set expression expected", }, { - sqls: sqls( + SQLs: sqls( "select setcontainsall(['POST', 'GET'], [1, 2])", "select setcontainsany(['POST', 'GET'], [1, 2])", ), - expErr: "types 'STRING' and 'ID' are not equatable", + ExpErr: "types 'STRING' and 'ID' are not equatable", }, { - sqls: sqls( + SQLs: sqls( "select setcontainsall([1, 2], ['1', '2'])", "select setcontainsany([1, 2], ['1', '2'])", ), - expErr: "types 'ID' and 'STRING' are not equatable", + ExpErr: "types 'ID' and 'STRING' are not equatable", }, }, } diff --git a/sql3/sql_defs_timequantum_test.go b/sql3/test/defs/defs_timequantum.go similarity index 73% rename from sql3/sql_defs_timequantum_test.go rename to sql3/test/defs/defs_timequantum.go index 0e37bdfff..6b4a0b5e2 100644 --- a/sql3/sql_defs_timequantum_test.go +++ b/sql3/test/defs/defs_timequantum.go @@ -1,8 +1,8 @@ -package sql3_test +package defs // time quantum insert tests -var timeQuantumInsertTest = tableTest{ - table: tbl( +var timeQuantumInsertTest = TableTest{ + Table: tbl( "time_quantum_insert", srcHdrs( srcHdr("_id", fldTypeID), @@ -11,21 +11,21 @@ var timeQuantumInsertTest = tableTest{ ), srcRows(), ), - sqlTests: []sqlTest{ + SQLTests: []SQLTest{ { - sqls: sqls( + SQLs: sqls( "insert into time_quantum_insert (_id, i1, ids1) values (1, 1, [1])", ), - expHdrs: hdrs(), - expRows: rows(), - compare: compareExactUnordered, + ExpHdrs: hdrs(), + ExpRows: rows(), + Compare: CompareExactUnordered, }, }, } // time quantum query tests -var timeQuantumQueryTest = tableTest{ - table: tbl( +var timeQuantumQueryTest = TableTest{ + Table: tbl( "timeQuantumQueryTest", srcHdrs( srcHdr("_id", fldTypeID), @@ -42,12 +42,12 @@ var timeQuantumQueryTest = tableTest{ srcRow(int64(1), int64(1000), bool(true), float64(12.34), int64(20), []int64{101, 102}, string("foo"), []string{"101", "102"}, knownTimestamp()), ), ), - sqlTests: []sqlTest{ + SQLTests: []SQLTest{ { - sqls: sqls( + SQLs: sqls( "select _id not like '%f_' from not_like_all_types", ), - expErr: "operator 'NOTLIKE' incompatible with type 'ID'", + ExpErr: "operator 'NOTLIKE' incompatible with type 'ID'", }, }, } diff --git a/sql3/test/defs/defs_timestamp_literals.go b/sql3/test/defs/defs_timestamp_literals.go new file mode 100644 index 000000000..72c531156 --- /dev/null +++ b/sql3/test/defs/defs_timestamp_literals.go @@ -0,0 +1,38 @@ +// Copyright 2021 Molecula Corp. All rights reserved. +package defs + +var timestampLiterals = TableTest{ + Table: tbl( + "testtimestampliterals", + srcHdrs( + srcHdr("_id", fldTypeID), + srcHdr("a", fldTypeInt, "min 0", "max 1000"), + srcHdr("b", fldTypeInt, "min 0", "max 1000"), + srcHdr("d", fldTypeDecimal2), + srcHdr("ts", fldTypeTimestamp), + srcHdr("event", fldTypeStringSet), + srcHdr("ievent", fldTypeIDSet), + ), + srcRows(), + ), + SQLTests: []SQLTest{ + { + // InsertWithCurrentTimestamp + SQLs: sqls( + "insert into testtimestampliterals (_id, a, b, d, ts, event, ievent) values (4, 40, 400, 10.12, current_timestamp, ['A', 'B', 'C'], [1, 2, 3])", + ), + ExpHdrs: hdrs(), + ExpRows: rows(), + Compare: CompareExactUnordered, + }, + { + // InsertWithCurrentDate + SQLs: sqls( + "insert into testtimestampliterals (_id, a, b, d, ts, event, ievent) values (4, 40, 400, 10.12, current_date, ['A', 'B', 'C'], [1, 2, 3])", + ), + ExpHdrs: hdrs(), + ExpRows: rows(), + Compare: CompareExactUnordered, + }, + }, +} diff --git a/sql3/test/defs/defs_unkeyed.go b/sql3/test/defs/defs_unkeyed.go new file mode 100644 index 000000000..b148f4931 --- /dev/null +++ b/sql3/test/defs/defs_unkeyed.go @@ -0,0 +1,97 @@ +package defs + +import "github.com/molecula/featurebase/v3/pql" + +var unkeyed = TableTest{ + name: "unkeyed", + Table: tbl( + "unkeyed", + srcHdrs( + srcHdr("_id", fldTypeID), + srcHdr("an_int", fldTypeInt, "min 0", "max 100"), + srcHdr("an_id_set", fldTypeIDSet), + srcHdr("an_id", fldTypeID), + srcHdr("a_string", fldTypeString), + srcHdr("a_string_set", fldTypeStringSet), + srcHdr("a_decimal", fldTypeDecimal2), + ), + srcRows( + srcRow(int64(1), int64(11), []int64{11, 12, 13}, int64(101), "str1", []string{"a1", "b1", "c1"}, float64(123.45)), + srcRow(int64(2), int64(22), []int64{21, 22, 23}, int64(201), "str2", []string{"a2", "b2", "c2"}, float64(234.56)), + srcRow(int64(3), int64(33), []int64{31, 32, 33}, int64(301), "str3", []string{"a3", "b3", "c3"}, float64(345.67)), + srcRow(int64(4), int64(44), []int64{41, 42, 43}, int64(401), "str4", []string{"a4", "b4", "c4"}, float64(456.78)), + ), + ), + SQLTests: []SQLTest{ + { + // Select all. + name: "select-all", + SQLs: sqls( + "select * from unkeyed", + "select _id, an_int, an_id_set, an_id, a_string, a_string_set, a_decimal from unkeyed", + ), + ExpHdrs: hdrs( + hdr("_id", fldTypeID), + hdr("an_int", fldTypeInt), + hdr("an_id_set", fldTypeIDSet), + hdr("an_id", fldTypeID), + hdr("a_string", fldTypeString), + hdr("a_string_set", fldTypeStringSet), + hdr("a_decimal", fldTypeDecimal2), + ), + ExpRows: rows( + row(int64(1), int64(11), []int64{11, 12, 13}, int64(101), "str1", []string{"a1", "b1", "c1"}, pql.NewDecimal(12345, 2)), + row(int64(2), int64(22), []int64{21, 22, 23}, int64(201), "str2", []string{"a2", "b2", "c2"}, pql.NewDecimal(23456, 2)), + row(int64(3), int64(33), []int64{31, 32, 33}, int64(301), "str3", []string{"a3", "b3", "c3"}, pql.NewDecimal(34567, 2)), + row(int64(4), int64(44), []int64{41, 42, 43}, int64(401), "str4", []string{"a4", "b4", "c4"}, pql.NewDecimal(45678, 2)), + ), + Compare: CompareExactUnordered, + SortStringKeys: true, + }, + { + // Select all with top. + name: "select-all-with-top", + SQLs: sqls( + "select top(2) * from unkeyed", + ), + ExpHdrs: hdrs( + hdr("_id", fldTypeID), + hdr("an_int", fldTypeInt), + hdr("an_id_set", fldTypeIDSet), + hdr("an_id", fldTypeID), + hdr("a_string", fldTypeString), + hdr("a_string_set", fldTypeStringSet), + hdr("a_decimal", fldTypeDecimal2), + ), + ExpRows: rows( + row(int64(1), int64(11), []int64{11, 12, 13}, int64(101), "str1", []string{"a1", "b1", "c1"}, pql.NewDecimal(12345, 2)), + row(int64(2), int64(22), []int64{21, 22, 23}, int64(201), "str2", []string{"a2", "b2", "c2"}, pql.NewDecimal(23456, 2)), + ), + Compare: CompareExactUnordered, + SortStringKeys: true, + }, + { + // Select all with where on each field. + name: "select-all-with-where", + SQLs: sqls( + "select * from unkeyed where an_int = 22", + "select * from unkeyed where a_string = 'str2'", + "select * from unkeyed where an_id = 201", + ), + ExpHdrs: hdrs( + hdr("_id", fldTypeID), + hdr("an_int", fldTypeInt), + hdr("an_id_set", fldTypeIDSet), + hdr("an_id", fldTypeID), + hdr("a_string", fldTypeString), + hdr("a_string_set", fldTypeStringSet), + hdr("a_decimal", fldTypeDecimal2), + ), + ExpRows: rows( + row(int64(2), int64(22), []int64{21, 22, 23}, int64(201), "str2", []string{"a2", "b2", "c2"}, pql.NewDecimal(23456, 2)), + ), + Compare: CompareExactOrdered, + SortStringKeys: true, + }, + }, +} diff --git a/sql3/sql_defs_unops_test.go b/sql3/test/defs/defs_unops.go similarity index 54% rename from sql3/sql_defs_unops_test.go rename to sql3/test/defs/defs_unops.go index a38c35afc..ca3fd7e01 100644 --- a/sql3/sql_defs_unops_test.go +++ b/sql3/test/defs/defs_unops.go @@ -1,9 +1,9 @@ -package sql3_test +package defs import "time" -var unaryOpExprWithInt = tableTest{ - table: tbl( +var unaryOpExprWithInt = TableTest{ + Table: tbl( "unoptesti", srcHdrs( srcHdr("_id", fldTypeID), @@ -13,48 +13,48 @@ var unaryOpExprWithInt = tableTest{ srcRow(int64(1), int64(10)), ), ), - sqlTests: []sqlTest{ + SQLTests: []SQLTest{ { - sqls: sqls( + SQLs: sqls( "select -i from unoptesti;", ), - expHdrs: hdrs( + ExpHdrs: hdrs( hdr("", fldTypeInt), ), - expRows: rows( + ExpRows: rows( row(int64(-10)), ), - compare: compareExactUnordered, + Compare: CompareExactUnordered, }, { - sqls: sqls( + SQLs: sqls( "select !i from unoptesti;", ), - expHdrs: hdrs( + ExpHdrs: hdrs( hdr("", fldTypeInt), ), - expRows: rows( + ExpRows: rows( row(int64(-11)), ), - compare: compareExactUnordered, + Compare: CompareExactUnordered, }, { - sqls: sqls( + SQLs: sqls( "select +i from unoptesti;", ), - expHdrs: hdrs( + ExpHdrs: hdrs( hdr("", fldTypeInt), ), - expRows: rows( + ExpRows: rows( row(int64(10)), ), - compare: compareExactUnordered, + Compare: CompareExactUnordered, }, }, } -var unaryOpExprWithBool = tableTest{ - table: tbl( +var unaryOpExprWithBool = TableTest{ + Table: tbl( "unoptest_b", srcHdrs( srcHdr("_id", fldTypeID), @@ -64,30 +64,30 @@ var unaryOpExprWithBool = tableTest{ srcRow(int64(1), bool(false)), ), ), - sqlTests: []sqlTest{ + SQLTests: []SQLTest{ { - sqls: sqls( + SQLs: sqls( "select -i from unoptest_b;", ), - expErr: "operator '-' incompatible with type 'BOOL'", + ExpErr: "operator '-' incompatible with type 'BOOL'", }, { - sqls: sqls( + SQLs: sqls( "select !i from unoptest_b;", ), - expErr: "operator '!' incompatible with type 'BOOL'", + ExpErr: "operator '!' incompatible with type 'BOOL'", }, { - sqls: sqls( + SQLs: sqls( "select +i from unoptest_b;", ), - expErr: "operator '+' incompatible with type 'BOOL'", + ExpErr: "operator '+' incompatible with type 'BOOL'", }, }, } -var unaryOpExprWithID = tableTest{ - table: tbl( +var unaryOpExprWithID = TableTest{ + Table: tbl( "unoptestid", srcHdrs( srcHdr("_id", fldTypeID), @@ -97,48 +97,48 @@ var unaryOpExprWithID = tableTest{ srcRow(int64(1), int64(10)), ), ), - sqlTests: []sqlTest{ + SQLTests: []SQLTest{ { - sqls: sqls( + SQLs: sqls( "select -_id from unoptestid;", ), - expHdrs: hdrs( + ExpHdrs: hdrs( hdr("", fldTypeInt), ), - expRows: rows( + ExpRows: rows( row(int64(-1)), ), - compare: compareExactUnordered, + Compare: CompareExactUnordered, }, { - sqls: sqls( + SQLs: sqls( "select !_id from unoptestid;", ), - expHdrs: hdrs( + ExpHdrs: hdrs( hdr("", fldTypeID), ), - expRows: rows( + ExpRows: rows( row(int64(-2)), ), - compare: compareExactUnordered, + Compare: CompareExactUnordered, }, { - sqls: sqls( + SQLs: sqls( "select +_id from unoptestid;", ), - expHdrs: hdrs( + ExpHdrs: hdrs( hdr("", fldTypeInt), ), - expRows: rows( + ExpRows: rows( row(int64(1)), ), - compare: compareExactUnordered, + Compare: CompareExactUnordered, }, }, } -var unaryOpExprWithDecimal = tableTest{ - table: tbl( +var unaryOpExprWithDecimal = TableTest{ + Table: tbl( "unoptestd", srcHdrs( srcHdr("_id", fldTypeID), @@ -148,42 +148,42 @@ var unaryOpExprWithDecimal = tableTest{ srcRow(int64(1), float64(12.34)), ), ), - sqlTests: []sqlTest{ + SQLTests: []SQLTest{ { - sqls: sqls( + SQLs: sqls( "select -d from unoptestd;", ), - expHdrs: hdrs( + ExpHdrs: hdrs( hdr("", fldTypeDecimal2), ), - expRows: rows( + ExpRows: rows( row(float64(-12.34)), ), - compare: compareExactUnordered, + Compare: CompareExactUnordered, }, { - sqls: sqls( + SQLs: sqls( "select !d from unoptestd;", ), - expErr: "operator '!' incompatible with type 'DECIMAL(2)'", + ExpErr: "operator '!' incompatible with type 'DECIMAL(2)'", }, { - sqls: sqls( + SQLs: sqls( "select +d from unoptestd;", ), - expHdrs: hdrs( + ExpHdrs: hdrs( hdr("", fldTypeDecimal2), ), - expRows: rows( + ExpRows: rows( row(float64(12.34)), ), - compare: compareExactUnordered, + Compare: CompareExactUnordered, }, }, } -var unaryOpExprWithTimestamp = tableTest{ - table: tbl( +var unaryOpExprWithTimestamp = TableTest{ + Table: tbl( "unoptestts", srcHdrs( srcHdr("_id", fldTypeID), @@ -193,30 +193,30 @@ var unaryOpExprWithTimestamp = tableTest{ srcRow(int64(1), time.Time(knownTimestamp())), ), ), - sqlTests: []sqlTest{ + SQLTests: []SQLTest{ { - sqls: sqls( + SQLs: sqls( "select -ts from unoptestts;", ), - expErr: "operator '-' incompatible with type 'TIMESTAMP'", + ExpErr: "operator '-' incompatible with type 'TIMESTAMP'", }, { - sqls: sqls( + SQLs: sqls( "select !ts from unoptestts;", ), - expErr: "operator '!' incompatible with type 'TIMESTAMP'", + ExpErr: "operator '!' incompatible with type 'TIMESTAMP'", }, { - sqls: sqls( + SQLs: sqls( "select +ts from unoptestts;", ), - expErr: "operator '+' incompatible with type 'TIMESTAMP'", + ExpErr: "operator '+' incompatible with type 'TIMESTAMP'", }, }, } -var unaryOpExprWithIDSet = tableTest{ - table: tbl( +var unaryOpExprWithIDSet = TableTest{ + Table: tbl( "unoptestids", srcHdrs( srcHdr("_id", fldTypeID), @@ -226,30 +226,30 @@ var unaryOpExprWithIDSet = tableTest{ srcRow(int64(1), []int64{11, 12, 13}), ), ), - sqlTests: []sqlTest{ + SQLTests: []SQLTest{ { - sqls: sqls( + SQLs: sqls( "select -ids from unoptestids;", ), - expErr: "operator '-' incompatible with type 'IDSET'", + ExpErr: "operator '-' incompatible with type 'IDSET'", }, { - sqls: sqls( + SQLs: sqls( "select !ids from unoptestids;", ), - expErr: "operator '!' incompatible with type 'IDSET'", + ExpErr: "operator '!' incompatible with type 'IDSET'", }, { - sqls: sqls( + SQLs: sqls( "select +ids from unoptestids;", ), - expErr: "operator '+' incompatible with type 'IDSET'", + ExpErr: "operator '+' incompatible with type 'IDSET'", }, }, } -var unaryOpExprWithString = tableTest{ - table: tbl( +var unaryOpExprWithString = TableTest{ + Table: tbl( "unoptest_s", srcHdrs( srcHdr("_id", fldTypeID), @@ -259,30 +259,30 @@ var unaryOpExprWithString = tableTest{ srcRow(int64(1), string("foo")), ), ), - sqlTests: []sqlTest{ + SQLTests: []SQLTest{ { - sqls: sqls( + SQLs: sqls( "select -s from unoptest_s;", ), - expErr: "operator '-' incompatible with type 'STRING'", + ExpErr: "operator '-' incompatible with type 'STRING'", }, { - sqls: sqls( + SQLs: sqls( "select !s from unoptest_s;", ), - expErr: "operator '!' incompatible with type 'STRING'", + ExpErr: "operator '!' incompatible with type 'STRING'", }, { - sqls: sqls( + SQLs: sqls( "select +s from unoptest_s;", ), - expErr: "operator '+' incompatible with type 'STRING'", + ExpErr: "operator '+' incompatible with type 'STRING'", }, }, } -var unaryOpExprWithStringSet = tableTest{ - table: tbl( +var unaryOpExprWithStringSet = TableTest{ + Table: tbl( "unoptestss", srcHdrs( srcHdr("_id", fldTypeID), @@ -292,24 +292,24 @@ var unaryOpExprWithStringSet = tableTest{ srcRow(int64(1), []string{"11", "12", "13"}), ), ), - sqlTests: []sqlTest{ + SQLTests: []SQLTest{ { - sqls: sqls( + SQLs: sqls( "select -s from unoptestss;", ), - expErr: "operator '-' incompatible with type 'STRINGSET'", + ExpErr: "operator '-' incompatible with type 'STRINGSET'", }, { - sqls: sqls( + SQLs: sqls( "select !s from unoptestss;", ), - expErr: "operator '!' incompatible with type 'STRINGSET'", + ExpErr: "operator '!' incompatible with type 'STRINGSET'", }, { - sqls: sqls( + SQLs: sqls( "select +s from unoptestss;", ), - expErr: "operator '+' incompatible with type 'STRINGSET'", + ExpErr: "operator '+' incompatible with type 'STRINGSET'", }, }, } diff --git a/sql3/test/defs/types.go b/sql3/test/defs/types.go new file mode 100644 index 000000000..9ddd28dc5 --- /dev/null +++ b/sql3/test/defs/types.go @@ -0,0 +1,253 @@ +// Copyright 2021 Molecula Corp. All rights reserved. +package defs + +import ( + "fmt" + "log" + "strings" + "testing" + "time" + + "github.com/molecula/featurebase/v3/sql3/parser" + planner_types "github.com/molecula/featurebase/v3/sql3/planner/types" +) + +type fldType parser.ExprDataType + +// fldType constants are providing a map of a defined test type to the +// parser.ExprDataType +var ( + fldTypeID fldType = parser.NewDataTypeID() + fldTypeBool fldType = parser.NewDataTypeBool() + fldTypeIDSet fldType = parser.NewDataTypeIDSet() + fldTypeInt fldType = parser.NewDataTypeInt() + fldTypeDecimal2 fldType = parser.NewDataTypeDecimal(2) + fldTypeString fldType = parser.NewDataTypeString() + fldTypeStringSet fldType = parser.NewDataTypeStringSet() + fldTypeTimestamp fldType = parser.NewDataTypeTimestamp() +) + +type compareMethod string + +const ( + CompareExactOrdered compareMethod = "exactOrdered" + CompareExactUnordered compareMethod = "exactUnordered" + CompareIncludedIn compareMethod = "includedIn" +) + +type TableTest struct { + name string + Table source + SQLTests []SQLTest +} + +// Name returns a string name which can be used to distingish test runs. It +// takes an integer value which will be used as part of a generic table name in +// the case where a name value was not provided in the definition. +func (tt TableTest) Name(i int) string { + name := fmt.Sprintf("table-%d", i) + if tt.name != "" { + name = tt.name + } else if tt.Table.name != "" { + name = tt.Table.name + } + return name +} + +// HasTable returns true is TableTest has a table defined which should be +// created. +func (tt TableTest) HasTable() bool { + return tt.Table.columns != nil +} + +// HasData returns true is TableTest has a data defined which should be +// inserted. +func (tt TableTest) HasData() bool { + return len(tt.Table.rows) > 0 +} + +func (tt TableTest) CreateTable() string { + if !tt.HasTable() { + return "" + } + return tt.Table.createTable() +} + +func (tt TableTest) InsertInto(t *testing.T) string { + if !tt.HasTable() { + return "" + } + return tt.Table.insertInto(t) +} + +type SQLTest struct { + name string + SQLs []string + ExpHdrs []*planner_types.PlannerColumn + ExpRows [][]interface{} + ExpErr string + Compare compareMethod + SortStringKeys bool + ExpRowCount int +} + +// Name returns a string name which can be used to distingish test runs. It +// takes an integer value which will be used as part of a generic table name in +// the case where a name value was not provided in the definition. +func (s SQLTest) Name(i int) string { + name := fmt.Sprintf("test-%d", i) + if s.name != "" { + name = s.name + } + return name +} + +// The following "source" types are helpers for creating a test table. +type sourceColumn struct { + name string + typ fldType + options string +} + +func tbl(name string, columns []sourceColumn, rows []sourceRow) source { + return source{ + name: name, + columns: columns, + rows: rows, + } +} + +func srcHdrs(hdrs ...sourceColumn) []sourceColumn { + return hdrs +} + +func srcHdr(name string, typ fldType, opts ...string) sourceColumn { + return sourceColumn{ + name: name, + typ: typ, + options: strings.Join(opts, " "), + } +} + +func srcRows(rows ...sourceRow) []sourceRow { + return rows +} +func srcRow(cells ...interface{}) sourceRow { + return cells +} + +type sourceRow []interface{} + +type sourceRows []sourceRow + +// insertTuples returns the list of tuples (as a single string) to use as the +// VALUES value in an INSERT INTO statement. +func (sr sourceRows) insertTuples(t *testing.T) string { + var afterFirstRow bool + var sb strings.Builder + for _, row := range sr { + if afterFirstRow { + sb.WriteString(",") + } + + var afterFirstCell bool + sb.WriteString("(") + + for _, cell := range row { + if afterFirstCell { + sb.WriteString(",") + } + switch v := cell.(type) { + case string: + sb.WriteString("'" + v + "'") + case int64: + sb.WriteString(fmt.Sprintf("%d", v)) + case float64: + sb.WriteString(fmt.Sprintf("%.2f", v)) + case []int64: + strs := make([]string, len(v)) + for i := range v { + strs[i] = fmt.Sprintf("%d", v[i]) + } + sb.WriteString("[" + strings.Join(strs, ",") + "]") + case []string: + if len(v) == 0 { + sb.WriteString("[]") + } else { + sb.WriteString("['" + strings.Join(v, "','") + "']") + } + case bool: + sb.WriteString(fmt.Sprintf("%v", v)) + case nil: + sb.WriteString("null") + case time.Time: + sb.WriteString("'" + v.Format(time.RFC3339) + "'") + + default: + t.Fatalf("unsupported cell type: %T", cell) + } + afterFirstCell = true + } + + sb.WriteString(")") + afterFirstRow = true + } + return sb.String() +} + +type source struct { + name string + columns []sourceColumn + rows []sourceRow +} + +func (s source) createTable() string { + ct := "CREATE TABLE " + s.name + " (" + + cols := []string{} + for _, col := range s.columns { + f := col.name + " " + col.typ.TypeName() + if col.options != "" { + f += " " + col.options + } + cols = append(cols, f) + } + ct += strings.Join(cols, ",") + + ct += `)` + + log.Printf("CREATE: %s", ct) + return ct +} + +func (s source) insertInto(t *testing.T) string { + ii := "INSERT INTO " + s.name + " VALUES " + ii += sourceRows(s.rows).insertTuples(t) + return ii +} + +// hdrs is just a helper function to make the test definition look cleaner. +func hdrs(hdrs ...*planner_types.PlannerColumn) []*planner_types.PlannerColumn { + return hdrs +} + +// hdr is just a helper function to make the test definition look cleaner. +func hdr(name string, typ fldType) *planner_types.PlannerColumn { + return &planner_types.PlannerColumn{ + ColumnName: name, + Type: typ, + } +} + +// row helpers for expected results +func rows(rows ...[]interface{}) [][]interface{} { + return rows +} + +func row(cells ...interface{}) []interface{} { + return cells +} + +func sqls(sqls ...string) []string { + return sqls +}