mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-08-28 10:54:59 +00:00
Move SQL3 test definitions into sql3/test/defs package (#2289)
This so other packages can import and use them in their own tests.
This commit is contained in:
parent
e25e395bab
commit
eec278893a
26 changed files with 9805 additions and 9744 deletions
|
|
@ -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,
|
||||
},
|
||||
},
|
||||
}
|
||||
File diff suppressed because it is too large
Load diff
259
sql3/sql_test.go
259
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
|
||||
}
|
||||
|
|
|
|||
168
sql3/test/defs/defs.go
Normal file
168
sql3/test/defs/defs.go
Normal file
|
|
@ -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
|
||||
}
|
||||
|
|
@ -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,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
|
@ -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,
|
||||
},
|
||||
},
|
||||
}
|
||||
7923
sql3/test/defs/defs_binops.go
Normal file
7923
sql3/test/defs/defs_binops.go
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -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,
|
||||
},
|
||||
},
|
||||
}
|
||||
File diff suppressed because it is too large
Load diff
|
|
@ -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",
|
||||
),
|
||||
},
|
||||
|
|
@ -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,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
|
@ -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",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
|
@ -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,
|
||||
},
|
||||
},
|
||||
}
|
||||
129
sql3/test/defs/defs_inserts.go
Normal file
129
sql3/test/defs/defs_inserts.go
Normal file
|
|
@ -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'",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
|
@ -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,
|
||||
},
|
||||
},
|
||||
}
|
||||
93
sql3/test/defs/defs_keyed.go
Normal file
93
sql3/test/defs/defs_keyed.go
Normal file
|
|
@ -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,
|
||||
},
|
||||
},
|
||||
}
|
||||
30
sql3/test/defs/defs_keyed_insert.go
Normal file
30
sql3/test/defs/defs_keyed_insert.go
Normal file
|
|
@ -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,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
|
@ -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'",
|
||||
},
|
||||
},
|
||||
}
|
||||
19
sql3/test/defs/defs_minmaxnegative.go
Normal file
19
sql3/test/defs/defs_minmaxnegative.go
Normal file
|
|
@ -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{},
|
||||
}
|
||||
|
|
@ -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,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
|
@ -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",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
|
@ -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'",
|
||||
},
|
||||
},
|
||||
}
|
||||
38
sql3/test/defs/defs_timestamp_literals.go
Normal file
38
sql3/test/defs/defs_timestamp_literals.go
Normal file
|
|
@ -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,
|
||||
},
|
||||
},
|
||||
}
|
||||
97
sql3/test/defs/defs_unkeyed.go
Normal file
97
sql3/test/defs/defs_unkeyed.go
Normal file
|
|
@ -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,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
|
@ -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'",
|
||||
},
|
||||
},
|
||||
}
|
||||
253
sql3/test/defs/types.go
Normal file
253
sql3/test/defs/types.go
Normal file
|
|
@ -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
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue