mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-09-09 14:41:02 +00:00
Add tests cases for coverage in expressiontypes.go (#2345)
FB-2041 Added tests for typeIsTimeQuantum and typeIsSet and made them pass. Added tests for DataTypeTuple cases in typesAreAssignmentCompatible. Timestamp conversion checking is handled before it gets to that point but I left those branches in as a backstop. Checking to see if DataType[String,ID]SetQuantum can be assigned to themselves doesn't appear to be reachable currently but left those branches in, because something may use them in future. Added one test to the DAX skip list since it's the IDSetQ version of a StringSetQ test that was already on there, changed skip list to refer to both tests by name instead of by number.
This commit is contained in:
parent
9e39eee9c9
commit
fc74c8ecde
6 changed files with 154 additions and 5 deletions
|
|
@ -149,8 +149,9 @@ func TestDAXIntegration(t *testing.T) {
|
|||
"viewtests/drop-view", // drop view does a delete
|
||||
"viewtests/drop-view-if-exists-after-drop",
|
||||
"viewtests/select-view-after-drop",
|
||||
"time_quantum_insert/test-12", // orchestrator currently does not support to,from args on Rows()
|
||||
"select-having/string", // fails in DAX because the string isn't translated.
|
||||
"time_quantum_insert/stringset-rangeq", // orchestrator currently does not support to,from args on Rows()
|
||||
"time_quantum_insert/idset-rangeq",
|
||||
"select-having/string", // fails in DAX because the string isn't translated.
|
||||
}
|
||||
|
||||
doSkip := func(name string) bool {
|
||||
|
|
|
|||
|
|
@ -1720,7 +1720,7 @@ func (n *qualifiedRefPlanExpression) Evaluate(currentRow []interface{}) (interfa
|
|||
}
|
||||
|
||||
switch n.dataType.(type) {
|
||||
case *parser.DataTypeIDSet:
|
||||
case *parser.DataTypeIDSet, *parser.DataTypeIDSetQuantum:
|
||||
row, ok := currentRow[n.columnIndex].([]uint64)
|
||||
if !ok {
|
||||
return nil, sql3.NewErrInternalf("unexpected type for current row '%T'", currentRow[n.columnIndex])
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@ func (n *callPlanExpression) EvaluateSetContains(currentRow []interface{}) (inte
|
|||
return nil, sql3.NewErrInternalf("unable to convert value")
|
||||
}
|
||||
|
||||
return intSetContains(targetSet, int64(testValue)), nil
|
||||
return intSetContains(targetSet, testValue), nil
|
||||
|
||||
default:
|
||||
return nil, sql3.NewErrInternalf("unexpected data type '%T'", typ)
|
||||
|
|
|
|||
|
|
@ -45,6 +45,7 @@ var TableTests []TableTest = []TableTest{
|
|||
setLiteralTests,
|
||||
setFunctionTests,
|
||||
setParameterTests,
|
||||
setTimeQuantumTests,
|
||||
dateTimePartTests,
|
||||
dateTimeNameTests,
|
||||
toTimestampTests,
|
||||
|
|
|
|||
|
|
@ -304,3 +304,93 @@ var setParameterTests = TableTest{
|
|||
},
|
||||
},
|
||||
}
|
||||
|
||||
// test IDSetQ and StringSetQ functions
|
||||
var setTimeQuantumTests = TableTest{
|
||||
name: "selectwithsetqliterals",
|
||||
Table: tbl(
|
||||
"selectwithsetqliterals",
|
||||
srcHdrs(
|
||||
srcHdr("_id", fldTypeID),
|
||||
srcHdr("a", fldTypeInt, "min 0", "max 1000"),
|
||||
srcHdr("b", fldTypeInt, "min 0", "max 1000"),
|
||||
srcHdr("ssq1", fldTypeStringSetQ, "timequantum 'YMD'"),
|
||||
srcHdr("isq1", fldTypeIDSetQ, "timequantum 'YMD'"),
|
||||
),
|
||||
),
|
||||
SQLTests: []SQLTest{
|
||||
// can't find example syntax or docs for how to put time quantum fields in with srcRow()
|
||||
// so i'm inserting them with SQL statements.
|
||||
{
|
||||
SQLs: sqls(
|
||||
"insert into selectwithsetqliterals(_id, a, b, ssq1, isq1) values (1, 10, 100, {'2022-01-03T00:00:00Z', ['foo']}, {'2022-01-01T00:00:00Z', [99, 101]})",
|
||||
"insert into selectwithsetqliterals(_id, a, b, ssq1, isq1) values (2, 20, 200, {'2022-01-03T00:00:00Z', ['bar']}, {'2022-01-01T00:00:00Z', [100]})",
|
||||
"insert into selectwithsetqliterals(_id, a, b, ssq1, isq1) values (3, 30, 300, {'2022-01-03T00:00:00Z', ['foo', 'bar']}, {'2022-01-01T00:00:00Z', [101]})",
|
||||
),
|
||||
ExpHdrs: hdrs(),
|
||||
ExpRows: rows(),
|
||||
Compare: CompareExactUnordered,
|
||||
},
|
||||
{
|
||||
// SetContainsSelectList
|
||||
name: "set-contains-select-list",
|
||||
SQLs: sqls(
|
||||
"select _id, setcontains(ssq1, 'bar') from selectwithsetqliterals",
|
||||
),
|
||||
ExpHdrs: hdrs(
|
||||
hdr("_id", fldTypeID),
|
||||
hdr("", fldTypeBool),
|
||||
),
|
||||
ExpRows: rows(
|
||||
row(int64(1), false),
|
||||
row(int64(2), true),
|
||||
row(int64(3), true),
|
||||
),
|
||||
Compare: CompareExactUnordered,
|
||||
},
|
||||
{
|
||||
// SetContainsSelectListInt
|
||||
name: "set-contains-select-list-int",
|
||||
SQLs: sqls(
|
||||
"select _id, setcontains(isq1, 101) from selectwithsetqliterals",
|
||||
),
|
||||
ExpHdrs: hdrs(
|
||||
hdr("_id", fldTypeID),
|
||||
hdr("", fldTypeBool),
|
||||
),
|
||||
ExpRows: rows(
|
||||
row(int64(1), true),
|
||||
row(int64(2), false),
|
||||
row(int64(3), true),
|
||||
),
|
||||
Compare: CompareExactUnordered,
|
||||
},
|
||||
{
|
||||
// SetContainsWithLiteral
|
||||
// SetContainsWithLiteralInt
|
||||
// SetContainsWithLiteralAny
|
||||
// SetContainsWithLiteralAnyInt
|
||||
// SetContainsWithLiteralAll
|
||||
// SetContainsWithLiteralAllInt
|
||||
name: "set-contains-with-literal",
|
||||
SQLs: sqls(
|
||||
"select _id, setcontains(['foo'], 'foo') from selectwithsetqliterals",
|
||||
"select _id, setcontains([101], 101) from selectwithsetqliterals",
|
||||
"select _id, setcontainsany(['foo'], ['foo']) from selectwithsetqliterals",
|
||||
"select _id, setcontainsany([101], [101]) from selectwithsetqliterals",
|
||||
"select _id, setcontainsall(['foo'], ['foo']) from selectwithsetqliterals",
|
||||
"select _id, setcontainsall([101], [101]) from selectwithsetqliterals",
|
||||
),
|
||||
ExpHdrs: hdrs(
|
||||
hdr("_id", fldTypeID),
|
||||
hdr("", fldTypeBool),
|
||||
),
|
||||
ExpRows: rows(
|
||||
row(int64(1), true),
|
||||
row(int64(2), true),
|
||||
row(int64(3), true),
|
||||
),
|
||||
Compare: CompareExactUnordered,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,6 +26,48 @@ var timeQuantumTest = TableTest{
|
|||
),
|
||||
ExpErr: "an expression of type 'tuple(stringset)' cannot be assigned to type 'stringsetq'",
|
||||
},
|
||||
{
|
||||
SQLs: sqls(
|
||||
"insert into time_quantum_insert (_id, i1, ss1, ids1) values (1, 1, ['1'], {[1]})",
|
||||
),
|
||||
ExpErr: "an expression of type 'tuple(idset)' cannot be assigned to type 'idsetq'",
|
||||
},
|
||||
{
|
||||
SQLs: sqls(
|
||||
"insert into time_quantum_insert (_id, i1, ss1, ids1) values (1, 1, {'notatimestamp', ['1']}, [1])",
|
||||
),
|
||||
ExpErr: "unable to convert 'notatimestamp' to type 'timestamp'",
|
||||
},
|
||||
{
|
||||
SQLs: sqls(
|
||||
"insert into time_quantum_insert (_id, i1, ss1, ids1) values (1, 1, ['1'], {'notatimestamp', [1]})",
|
||||
),
|
||||
ExpErr: "unable to convert 'notatimestamp' to type 'timestamp'",
|
||||
},
|
||||
{
|
||||
SQLs: sqls(
|
||||
"insert into time_quantum_insert (_id, i1, ss1, ids1) values (1, 1, {'2022-01-01T00:00:00Z', [1]}, {[1]})",
|
||||
),
|
||||
ExpErr: "an expression of type 'tuple(string, idset)' cannot be assigned to type 'stringsetq'",
|
||||
},
|
||||
{
|
||||
SQLs: sqls(
|
||||
"insert into time_quantum_insert (_id, i1, ss1, ids1) values (1, 1, ['1'], {'2022-01-01T00:00:00Z', ['1']})",
|
||||
),
|
||||
ExpErr: "an expression of type 'tuple(string, stringset)' cannot be assigned to type 'idsetq'",
|
||||
},
|
||||
{
|
||||
SQLs: sqls(
|
||||
"insert into time_quantum_insert (_id, i1, ss1, ids1) values (1, 1, '1', {[1]})",
|
||||
),
|
||||
ExpErr: "an expression of type 'string' cannot be assigned to type 'stringsetq'",
|
||||
},
|
||||
{
|
||||
SQLs: sqls(
|
||||
"insert into time_quantum_insert (_id, i1, ss1, ids1) values (1, 1, ['1'], 1)",
|
||||
),
|
||||
ExpErr: "an expression of type 'int' cannot be assigned to type 'idsetq'",
|
||||
},
|
||||
{
|
||||
SQLs: sqls(
|
||||
"insert into time_quantum_insert (_id, i1, ss1, ids1) values (1, 1, {1676649734, ['1']}, {1676649734, [1]})",
|
||||
|
|
@ -84,7 +126,7 @@ var timeQuantumTest = TableTest{
|
|||
SQLs: sqls(
|
||||
"select a._id, a.ss1 from time_quantum_insert a where rangeq(a.ss1, null, null)",
|
||||
),
|
||||
ExpErr: "alling ranqeq() 'from' and 'to' parameters cannot both be null",
|
||||
ExpErr: "calling ranqeq() 'from' and 'to' parameters cannot both be null",
|
||||
},
|
||||
{
|
||||
SQLs: sqls(
|
||||
|
|
@ -99,6 +141,7 @@ var timeQuantumTest = TableTest{
|
|||
ExpErr: "calling ranqeq() usage invalid",
|
||||
},
|
||||
{
|
||||
name: "stringset-rangeq",
|
||||
SQLs: sqls(
|
||||
"select a._id, a.ss1 from time_quantum_insert a where rangeq(a.ss1, '2022-01-02T00:00:00Z', null)",
|
||||
),
|
||||
|
|
@ -111,6 +154,20 @@ var timeQuantumTest = TableTest{
|
|||
),
|
||||
Compare: CompareExactUnordered,
|
||||
},
|
||||
{
|
||||
name: "idset-rangeq",
|
||||
SQLs: sqls(
|
||||
"select a._id, a.ids1 from time_quantum_insert a where rangeq(a.ids1, '2022-01-02T00:00:00Z', null)",
|
||||
),
|
||||
ExpHdrs: hdrs(
|
||||
hdr("_id", fldTypeID),
|
||||
hdr("ids1", fldTypeIDSetQ),
|
||||
),
|
||||
ExpRows: rows(
|
||||
row(int64(1), []int64{1, 2}),
|
||||
),
|
||||
Compare: CompareExactUnordered,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue