MCPcopy Create free account
hub / github.com/rilldata/rill / TestArrayContainsCondition

Function TestArrayContainsCondition

runtime/metricsview/astexpr_test.go:13–228  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

11)
12
13func TestArrayContainsCondition(t *testing.T) {
14 mv := &runtimev1.MetricsViewSpec{
15 Table: "test_table",
16 Database: "",
17 Connector: "",
18 Dimensions: []*runtimev1.MetricsViewSpec_Dimension{
19 {Name: "id", Column: "id"},
20 {Name: "tags", Column: "tags", Unnest: true},
21 {Name: "city", Column: "city"},
22 },
23 Measures: []*runtimev1.MetricsViewSpec_Measure{
24 {Name: "count", Expression: "count(*)", Type: runtimev1.MetricsViewSpec_MEASURE_TYPE_SIMPLE},
25 },
26 }
27 sec := skipMetricsViewSecurity{}
28
29 tests := []struct {
30 name string
31 dialect drivers.Dialect
32 dims []Dimension
33 where *Expression
34 wantSQL string
35 wantArgs []any
36 }{
37 {
38 name: "duckdb: in on unnest dim uses list_has_any",
39 dialect: duckdb.DialectDuckDB,
40 where: &Expression{Condition: &Condition{
41 Operator: OperatorIn,
42 Expressions: []*Expression{
43 {Name: "tags"},
44 {Value: []any{"a", "b", "c"}},
45 },
46 }},
47 wantSQL: `(list_has_any(("tags"), [?,?,?]))`,
48 wantArgs: []any{"a", "b", "c"},
49 },
50 {
51 name: "duckdb: nin on unnest dim uses NOT list_has_any",
52 dialect: duckdb.DialectDuckDB,
53 where: &Expression{Condition: &Condition{
54 Operator: OperatorNin,
55 Expressions: []*Expression{
56 {Name: "tags"},
57 {Value: []any{"a", "b"}},
58 },
59 }},
60 wantSQL: `(NOT list_has_any(("tags"), [?,?]))`,
61 wantArgs: []any{"a", "b"},
62 },
63 {
64 name: "duckdb: in on unnest dim with empty list",
65 dialect: duckdb.DialectDuckDB,
66 where: &Expression{Condition: &Condition{
67 Operator: OperatorIn,
68 Expressions: []*Expression{
69 {Name: "tags"},
70 {Value: []any{}},

Callers

nothing calls this directly

Calls 3

SQLForExpressionMethod · 0.95
NewASTFunction · 0.85
RunMethod · 0.45

Tested by

no test coverage detected