|
3 | 3 | package clickhouse |
4 | 4 |
|
5 | 5 | import ( |
6 | | - "bytes" |
7 | | - "fmt" |
8 | | - "github.com/QuesmaOrg/quesma/quesma/model" |
9 | | - "github.com/goccy/go-json" |
10 | 6 | "strings" |
11 | | - "time" |
12 | 7 | ) |
13 | 8 |
|
14 | 9 | // Code doesn't need to be pretty, 99.9% it's just for our purposes |
@@ -102,58 +97,3 @@ func parseTypeFromShowColumns(typ, name string) (Type, string) { |
102 | 97 | } |
103 | 98 | return parseTypeRec(typ, name) |
104 | 99 | } |
105 | | - |
106 | | -func PrettyJson(jsonStr string) string { |
107 | | - var prettyJSON bytes.Buffer |
108 | | - if err := json.Indent(&prettyJSON, []byte(jsonStr), "", " "); err != nil { |
109 | | - return fmt.Sprintf("PrettyJson err: %v\n", err) |
110 | | - } |
111 | | - return prettyJSON.String() |
112 | | -} |
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