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

Function TestExpressionToSQL

runtime/metricsview/query_expression_sql_test.go:7–221  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

5)
6
7func TestExpressionToSQL(t *testing.T) {
8 tests := []struct {
9 name string
10 e *Expression
11 want string
12 wantErr bool
13 }{
14 {
15 name: "empty expression",
16 e: nil,
17 want: "",
18 },
19 {
20 name: "name expression",
21 e: &Expression{Name: "foo"},
22 want: "foo",
23 },
24 {
25 name: "complex name expression",
26 e: &Expression{Name: "foo \" $.%&/' bar"},
27 want: `"foo "" $.%&/' bar"`,
28 },
29 {
30 name: "value expression",
31 e: &Expression{Value: 42},
32 want: "42",
33 },
34 {
35 name: "subquery expression",
36 e: &Expression{Subquery: &Subquery{
37 Dimension: Dimension{Name: "dim"},
38 Measures: []Measure{{Name: "count"}},
39 Having: &Expression{Condition: &Condition{
40 Operator: OperatorEq,
41 Expressions: []*Expression{
42 {Name: "count"},
43 {Value: 10},
44 },
45 }},
46 }},
47 want: "(SELECT dim FROM metrics_view HAVING count = 10)",
48 },
49 {
50 name: "condition expression",
51 e: &Expression{
52 Condition: &Condition{
53 Operator: OperatorEq,
54 Expressions: []*Expression{
55 {Name: "foo"},
56 {Value: 42},
57 },
58 },
59 },
60 want: "foo = 42",
61 },
62 {
63 name: "and expression",
64 e: &Expression{

Callers

nothing calls this directly

Calls 3

ExpressionToSQLFunction · 0.85
ErrorfMethod · 0.65
RunMethod · 0.45

Tested by

no test coverage detected