@@ -5,10 +5,8 @@ package clickhouse
55import (
66 "bytes"
77 "fmt"
8- "github.com/QuesmaOrg/quesma/quesma/model"
98 "github.com/goccy/go-json"
109 "strings"
11- "time"
1210)
1311
1412// Code doesn't need to be pretty, 99.9% it's just for our purposes
@@ -110,50 +108,3 @@ func PrettyJson(jsonStr string) string {
110108 }
111109 return prettyJSON .String ()
112110}
113-
114- // TimestampGroupBy returns string to be used in the select part of Clickhouse query, when grouping by timestamp interval.
115- // e.g.
116- // - timestampGroupBy("@timestamp", DateTime64, 30 seconds) --> toInt64(toUnixTimestamp64Milli(`@timestamp`)/30000)
117- // - timestampGroupBy("@timestamp", DateTime, 30 seconds) --> toInt64(toUnixTimestamp(`@timestamp`)/30)
118- func TimestampGroupBy (fullTimestampExpr model.Expr , timestampField model.ColumnRef , groupByInterval time.Duration ) model.Expr {
119- toUnixTsFunc := model .NewInfixExpr (
120- model .NewFunction (model .ToUnixTimestampMs , fullTimestampExpr ),
121- " / " , // TODO nasty hack to make our string-based tests pass. Operator should not contain spaces obviously
122- model .NewMillisecondsLiteral (timestampField , groupByInterval .Milliseconds ()),
123- )
124- return model .NewFunction ("toInt64" , toUnixTsFunc )
125- }
126-
127- func TimestampGroupByWithTimezone (fullTimestampExpr model.Expr , timestampField model.ColumnRef , groupByInterval time.Duration , timezone string ) model.Expr {
128-
129- // If no timezone, or timezone is default (UTC), we just return TimestampGroupBy(...)
130- if timezone == "" {
131- return TimestampGroupBy (fullTimestampExpr , timestampField , groupByInterval )
132- }
133-
134- var offset model.Expr = model .NewInfixExpr (
135- model .NewFunction (
136- "timeZoneOffset" ,
137- model .NewFunction (
138- "toTimezone" ,
139- fullTimestampExpr , model .NewLiteralSingleQuoteString (timezone ),
140- ),
141- ),
142- "*" ,
143- model .NewMillisecondsLiteral (timestampField , 1000 ),
144- )
145-
146- unixTsWithOffset := model .NewInfixExpr (
147- model .NewFunction (model .ToUnixTimestampMs , fullTimestampExpr ),
148- "+" ,
149- offset ,
150- )
151-
152- groupByExpr := model .NewInfixExpr (
153- model .NewParenExpr (unixTsWithOffset ),
154- " / " , // TODO nasty hack to make our string-based tests pass. Operator should not contain spaces obviously
155- model .NewMillisecondsLiteral (timestampField , groupByInterval .Milliseconds ()),
156- )
157-
158- return model .NewFunction ("toInt64" , groupByExpr )
159- }
0 commit comments