-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsimplequery_test.go
More file actions
31 lines (29 loc) · 889 Bytes
/
Copy pathsimplequery_test.go
File metadata and controls
31 lines (29 loc) · 889 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package click
import (
"testing"
"time"
)
func TestSimpleQuery_BuildString(t *testing.T) {
q := SimpleQuery{
IsTimeSeriesQuery: true,
TimeColumn: "ts",
GranularityFunction: "toStartOfDay",
StartTime: time.Unix(1704038400, 0),
EndTime: time.Unix(1706716800, 0),
Select: []Expression{Count()},
From: "tbl",
Where: LiteralExpression(1),
GroupBy: []Expression{Column("b")},
OrderBy: []Expression{Column("c")},
Having: LiteralExpression("d"),
Limit: 0,
Offset: 0,
}
s, err := q.BuildString()
if err != nil {
t.Fatal(err)
}
if s != "SELECT count(), toStartOfDay(ts) FROM tbl WHERE (1 AND (ts >= 1704038400) AND (ts < 1706716800)) GROUP BY b, toStartOfDay(ts) HAVING d ORDER BY c, toStartOfDay(ts)" {
t.Fatal(s)
}
}