Skip to content
This repository was archived by the owner on Feb 21, 2024. It is now read-only.

Commit fc74c8e

Browse files
authored
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.
1 parent 9e39eee commit fc74c8e

6 files changed

Lines changed: 154 additions & 5 deletions

File tree

dax/test/dax/dax_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,9 @@ func TestDAXIntegration(t *testing.T) {
149149
"viewtests/drop-view", // drop view does a delete
150150
"viewtests/drop-view-if-exists-after-drop",
151151
"viewtests/select-view-after-drop",
152-
"time_quantum_insert/test-12", // orchestrator currently does not support to,from args on Rows()
153-
"select-having/string", // fails in DAX because the string isn't translated.
152+
"time_quantum_insert/stringset-rangeq", // orchestrator currently does not support to,from args on Rows()
153+
"time_quantum_insert/idset-rangeq",
154+
"select-having/string", // fails in DAX because the string isn't translated.
154155
}
155156

156157
doSkip := func(name string) bool {

sql3/planner/expression.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1720,7 +1720,7 @@ func (n *qualifiedRefPlanExpression) Evaluate(currentRow []interface{}) (interfa
17201720
}
17211721

17221722
switch n.dataType.(type) {
1723-
case *parser.DataTypeIDSet:
1723+
case *parser.DataTypeIDSet, *parser.DataTypeIDSetQuantum:
17241724
row, ok := currentRow[n.columnIndex].([]uint64)
17251725
if !ok {
17261726
return nil, sql3.NewErrInternalf("unexpected type for current row '%T'", currentRow[n.columnIndex])

sql3/planner/inbuiltfunctionsset.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func (n *callPlanExpression) EvaluateSetContains(currentRow []interface{}) (inte
4949
return nil, sql3.NewErrInternalf("unable to convert value")
5050
}
5151

52-
return intSetContains(targetSet, int64(testValue)), nil
52+
return intSetContains(targetSet, testValue), nil
5353

5454
default:
5555
return nil, sql3.NewErrInternalf("unexpected data type '%T'", typ)

sql3/test/defs/defs.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ var TableTests []TableTest = []TableTest{
4545
setLiteralTests,
4646
setFunctionTests,
4747
setParameterTests,
48+
setTimeQuantumTests,
4849
dateTimePartTests,
4950
dateTimeNameTests,
5051
toTimestampTests,

sql3/test/defs/defs_set_functions.go

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,3 +304,93 @@ var setParameterTests = TableTest{
304304
},
305305
},
306306
}
307+
308+
// test IDSetQ and StringSetQ functions
309+
var setTimeQuantumTests = TableTest{
310+
name: "selectwithsetqliterals",
311+
Table: tbl(
312+
"selectwithsetqliterals",
313+
srcHdrs(
314+
srcHdr("_id", fldTypeID),
315+
srcHdr("a", fldTypeInt, "min 0", "max 1000"),
316+
srcHdr("b", fldTypeInt, "min 0", "max 1000"),
317+
srcHdr("ssq1", fldTypeStringSetQ, "timequantum 'YMD'"),
318+
srcHdr("isq1", fldTypeIDSetQ, "timequantum 'YMD'"),
319+
),
320+
),
321+
SQLTests: []SQLTest{
322+
// can't find example syntax or docs for how to put time quantum fields in with srcRow()
323+
// so i'm inserting them with SQL statements.
324+
{
325+
SQLs: sqls(
326+
"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]})",
327+
"insert into selectwithsetqliterals(_id, a, b, ssq1, isq1) values (2, 20, 200, {'2022-01-03T00:00:00Z', ['bar']}, {'2022-01-01T00:00:00Z', [100]})",
328+
"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]})",
329+
),
330+
ExpHdrs: hdrs(),
331+
ExpRows: rows(),
332+
Compare: CompareExactUnordered,
333+
},
334+
{
335+
// SetContainsSelectList
336+
name: "set-contains-select-list",
337+
SQLs: sqls(
338+
"select _id, setcontains(ssq1, 'bar') from selectwithsetqliterals",
339+
),
340+
ExpHdrs: hdrs(
341+
hdr("_id", fldTypeID),
342+
hdr("", fldTypeBool),
343+
),
344+
ExpRows: rows(
345+
row(int64(1), false),
346+
row(int64(2), true),
347+
row(int64(3), true),
348+
),
349+
Compare: CompareExactUnordered,
350+
},
351+
{
352+
// SetContainsSelectListInt
353+
name: "set-contains-select-list-int",
354+
SQLs: sqls(
355+
"select _id, setcontains(isq1, 101) from selectwithsetqliterals",
356+
),
357+
ExpHdrs: hdrs(
358+
hdr("_id", fldTypeID),
359+
hdr("", fldTypeBool),
360+
),
361+
ExpRows: rows(
362+
row(int64(1), true),
363+
row(int64(2), false),
364+
row(int64(3), true),
365+
),
366+
Compare: CompareExactUnordered,
367+
},
368+
{
369+
// SetContainsWithLiteral
370+
// SetContainsWithLiteralInt
371+
// SetContainsWithLiteralAny
372+
// SetContainsWithLiteralAnyInt
373+
// SetContainsWithLiteralAll
374+
// SetContainsWithLiteralAllInt
375+
name: "set-contains-with-literal",
376+
SQLs: sqls(
377+
"select _id, setcontains(['foo'], 'foo') from selectwithsetqliterals",
378+
"select _id, setcontains([101], 101) from selectwithsetqliterals",
379+
"select _id, setcontainsany(['foo'], ['foo']) from selectwithsetqliterals",
380+
"select _id, setcontainsany([101], [101]) from selectwithsetqliterals",
381+
"select _id, setcontainsall(['foo'], ['foo']) from selectwithsetqliterals",
382+
"select _id, setcontainsall([101], [101]) from selectwithsetqliterals",
383+
),
384+
ExpHdrs: hdrs(
385+
hdr("_id", fldTypeID),
386+
hdr("", fldTypeBool),
387+
),
388+
ExpRows: rows(
389+
row(int64(1), true),
390+
row(int64(2), true),
391+
row(int64(3), true),
392+
),
393+
Compare: CompareExactUnordered,
394+
},
395+
},
396+
}

sql3/test/defs/defs_timequantum.go

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,48 @@ var timeQuantumTest = TableTest{
2626
),
2727
ExpErr: "an expression of type 'tuple(stringset)' cannot be assigned to type 'stringsetq'",
2828
},
29+
{
30+
SQLs: sqls(
31+
"insert into time_quantum_insert (_id, i1, ss1, ids1) values (1, 1, ['1'], {[1]})",
32+
),
33+
ExpErr: "an expression of type 'tuple(idset)' cannot be assigned to type 'idsetq'",
34+
},
35+
{
36+
SQLs: sqls(
37+
"insert into time_quantum_insert (_id, i1, ss1, ids1) values (1, 1, {'notatimestamp', ['1']}, [1])",
38+
),
39+
ExpErr: "unable to convert 'notatimestamp' to type 'timestamp'",
40+
},
41+
{
42+
SQLs: sqls(
43+
"insert into time_quantum_insert (_id, i1, ss1, ids1) values (1, 1, ['1'], {'notatimestamp', [1]})",
44+
),
45+
ExpErr: "unable to convert 'notatimestamp' to type 'timestamp'",
46+
},
47+
{
48+
SQLs: sqls(
49+
"insert into time_quantum_insert (_id, i1, ss1, ids1) values (1, 1, {'2022-01-01T00:00:00Z', [1]}, {[1]})",
50+
),
51+
ExpErr: "an expression of type 'tuple(string, idset)' cannot be assigned to type 'stringsetq'",
52+
},
53+
{
54+
SQLs: sqls(
55+
"insert into time_quantum_insert (_id, i1, ss1, ids1) values (1, 1, ['1'], {'2022-01-01T00:00:00Z', ['1']})",
56+
),
57+
ExpErr: "an expression of type 'tuple(string, stringset)' cannot be assigned to type 'idsetq'",
58+
},
59+
{
60+
SQLs: sqls(
61+
"insert into time_quantum_insert (_id, i1, ss1, ids1) values (1, 1, '1', {[1]})",
62+
),
63+
ExpErr: "an expression of type 'string' cannot be assigned to type 'stringsetq'",
64+
},
65+
{
66+
SQLs: sqls(
67+
"insert into time_quantum_insert (_id, i1, ss1, ids1) values (1, 1, ['1'], 1)",
68+
),
69+
ExpErr: "an expression of type 'int' cannot be assigned to type 'idsetq'",
70+
},
2971
{
3072
SQLs: sqls(
3173
"insert into time_quantum_insert (_id, i1, ss1, ids1) values (1, 1, {1676649734, ['1']}, {1676649734, [1]})",
@@ -84,7 +126,7 @@ var timeQuantumTest = TableTest{
84126
SQLs: sqls(
85127
"select a._id, a.ss1 from time_quantum_insert a where rangeq(a.ss1, null, null)",
86128
),
87-
ExpErr: "alling ranqeq() 'from' and 'to' parameters cannot both be null",
129+
ExpErr: "calling ranqeq() 'from' and 'to' parameters cannot both be null",
88130
},
89131
{
90132
SQLs: sqls(
@@ -99,6 +141,7 @@ var timeQuantumTest = TableTest{
99141
ExpErr: "calling ranqeq() usage invalid",
100142
},
101143
{
144+
name: "stringset-rangeq",
102145
SQLs: sqls(
103146
"select a._id, a.ss1 from time_quantum_insert a where rangeq(a.ss1, '2022-01-02T00:00:00Z', null)",
104147
),
@@ -111,6 +154,20 @@ var timeQuantumTest = TableTest{
111154
),
112155
Compare: CompareExactUnordered,
113156
},
157+
{
158+
name: "idset-rangeq",
159+
SQLs: sqls(
160+
"select a._id, a.ids1 from time_quantum_insert a where rangeq(a.ids1, '2022-01-02T00:00:00Z', null)",
161+
),
162+
ExpHdrs: hdrs(
163+
hdr("_id", fldTypeID),
164+
hdr("ids1", fldTypeIDSetQ),
165+
),
166+
ExpRows: rows(
167+
row(int64(1), []int64{1, 2}),
168+
),
169+
Compare: CompareExactUnordered,
170+
},
114171
},
115172
}
116173

0 commit comments

Comments
 (0)