summaryrefslogtreecommitdiff
path: root/internal/mapr/query_test.go
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2023-09-05 16:38:23 +0300
committerPaul Buetow <pbuetow@mimecast.com>2023-09-07 15:32:29 +0300
commit9c77304550d65b8e7c2b724b991eef0dbc13694a (patch)
treeb0401269acf383760e2b2f962e71d11fd55147d2 /internal/mapr/query_test.go
parent360f67bf536372cb6a78fe35c15ba6128fda290b (diff)
Can quote fields in select conditions, e.g. select `count($foo)`, ..
Diffstat (limited to 'internal/mapr/query_test.go')
-rw-r--r--internal/mapr/query_test.go40
1 files changed, 40 insertions, 0 deletions
diff --git a/internal/mapr/query_test.go b/internal/mapr/query_test.go
index f03ccba..f37b8d4 100644
--- a/internal/mapr/query_test.go
+++ b/internal/mapr/query_test.go
@@ -252,3 +252,43 @@ func TestParseQueryDeep(t *testing.T) {
}
}
}
+
+func TestQuotedSelectCondition(t *testing.T) {
+ queryStr := "select `count($foo)`, foo, $foo, count($foo) logformat csv"
+
+ q, err := NewQuery(queryStr)
+ if err != nil {
+ t.Errorf("Query parse error: %s\n%v: %v", queryStr, q, err)
+ }
+ if len(q.Select) != 4 {
+ t.Errorf("Expected three elements in 'select' clause but got '%v': %s\n%v",
+ q.Select, queryStr, q)
+ }
+
+ if q.Select[0].Field != "count($foo)" {
+ t.Errorf("Expected 'num($foo)' as first element in 'select' clause but got '%v': %s\n%v",
+ q.Select[0].Field, queryStr, q)
+ }
+ if q.Select[0].Operation != Last {
+ t.Errorf("Expected 'Last' as aggregation function of first element in "+
+ "'select' clause but got '%v': %s\n%v", q.Select[0].Operation, queryStr, q)
+ }
+
+ if q.Select[1].Field != "foo" {
+ t.Errorf("Expected 'foo' as first element in 'select' clause but got '%v': %s\n%v",
+ q.Select[1].Field, queryStr, q)
+ }
+ if q.Select[2].Field != "$foo" {
+ t.Errorf("Expected '$foo' as first element in 'select' clause but got '%v': %s\n%v",
+ q.Select[2].Field, queryStr, q)
+ }
+
+ if q.Select[3].Field != "$foo" {
+ t.Errorf("Expected '$foo' as first element in 'select' clause but got '%v': %s\n%v",
+ q.Select[3].Field, queryStr, q)
+ }
+ if q.Select[3].Operation != Count {
+ t.Errorf("Expected 'count' as aggregation function of thourth element in "+
+ "'select' clause but got '%v': %s\n%v", q.Select[3].Operation, queryStr, q)
+ }
+}