Skip to content

Commit

Permalink
Updates
Browse files Browse the repository at this point in the history
  • Loading branch information
trzysiek committed Oct 29, 2024
1 parent c21fb6d commit 3992297
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 13 deletions.
5 changes: 4 additions & 1 deletion quesma/model/expr.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ type Expr interface {
Accept(v ExprVisitor) interface{}
}

var InvalidExpr = Expr(nil)
var (
InvalidExpr = Expr(nil)
TrueExpr = NewLiteral(true)
)

// ColumnRef is a reference to a column in a table, we can enrich it with more information (e.g. type used) as we go
type ColumnRef struct {
Expand Down
13 changes: 9 additions & 4 deletions quesma/queryparser/filters_aggregation.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package queryparser

import (
"quesma/logger"
"quesma/model"
"quesma/model/bucket_aggregations"
)

Expand Down Expand Up @@ -32,13 +33,17 @@ func (cw *ClickhouseQueryTranslator) parseFilters(queryMap QueryMap) (success bo
}

filters := make([]bucket_aggregations.Filter, 0, len(nestedMap))
for name, filter := range nestedMap {
filterMap, ok := filter.(QueryMap)
for name, filterRaw := range nestedMap {
filterMap, ok := filterRaw.(QueryMap)
if !ok {
logger.WarnWithCtx(cw.Ctx).Msgf("filter is not a map, but %T, value: %v. Skipping.", filter, filter)
logger.WarnWithCtx(cw.Ctx).Msgf("filter is not a map, but %T, value: %v. Skipping.", filterRaw, filterRaw)
continue
}
filters = append(filters, bucket_aggregations.NewFilter(name, cw.parseQueryMap(filterMap)))
filter := cw.parseQueryMap(filterMap)
if filter.WhereClause == nil {
filter = model.NewSimpleQuery(model.TrueExpr, true)
}
filters = append(filters, bucket_aggregations.NewFilter(name, filter))
}
return true, bucket_aggregations.NewFilters(cw.Ctx, filters)
}
3 changes: 3 additions & 0 deletions quesma/queryparser/pancake_aggregation_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,9 @@ func (cw *ClickhouseQueryTranslator) pancakeParseAggregation(aggregationName str
if filterRaw, ok := queryMap["filter"]; ok {
if filter, ok := filterRaw.(QueryMap); ok {
whereClause := cw.parseQueryMap(filter).WhereClause
if whereClause == nil { // empty filter same as true
whereClause = model.TrueExpr
}
aggregation.queryType = bucket_aggregations.NewFilterAgg(cw.Ctx, whereClause)
} else {
logger.WarnWithCtx(cw.Ctx).Msgf("filter is not a map, but %T, value: %v. Skipping", filterRaw, filterRaw)
Expand Down
6 changes: 4 additions & 2 deletions quesma/queryparser/pancake_sql_query_generation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/stretchr/testify/assert"
"quesma/clickhouse"
"quesma/concurrent"
"quesma/logger"
"quesma/model"
"quesma/model/bucket_aggregations"
"quesma/quesma/config"
Expand All @@ -24,7 +25,7 @@ const TableName = model.SingleTableNamePlaceHolder

func TestPancakeQueryGeneration(t *testing.T) {

// logger.InitSimpleLoggerForTests()
logger.InitSimpleLoggerForTests()
table := clickhouse.Table{
Cols: map[string]*clickhouse.Column{
"@timestamp": {Name: "@timestamp", Type: clickhouse.NewBaseType("DateTime64")},
Expand Down Expand Up @@ -61,7 +62,7 @@ func TestPancakeQueryGeneration(t *testing.T) {
}

if test.TestName == "multiple buckets_path(file:clients/clover,nr:1)" {
t.Skip("Unskip after merge of auto_date_histogram")
t.Skip("This needs fixing ASAP, easy to fix")
}

fmt.Println("i:", i, "test:", test.TestName)
Expand All @@ -79,6 +80,7 @@ func TestPancakeQueryGeneration(t *testing.T) {
assert.Len(t, pancakeSqls, 1+len(test.ExpectedAdditionalPancakeSQLs),
"Mismatch pancake sqls vs main and 'ExpectedAdditionalPancakeSQLs'")
for pancakeIdx, pancakeSql := range pancakeSqls {
pp.Println("=== Pancake SQL:", pancakeSql.SelectCommand)
pancakeSqlStr := model.AsString(pancakeSql.SelectCommand)

prettyPancakeSql := util.SqlPrettyPrint([]byte(pancakeSqlStr))
Expand Down
12 changes: 6 additions & 6 deletions quesma/testdata/clients/clover.go
Original file line number Diff line number Diff line change
Expand Up @@ -333,17 +333,17 @@ var CloverTests = []testdata.AggregationTestCase{
ExpectedPancakeResults: []model.QueryResultRow{
{Cols: []model.QueryResultCol{
model.NewQueryResultCol("aggr__timeseries__count", int64(202)),
model.NewQueryResultCol("metric__timeseries__a2-numerator_col_0", int64(202)),
model.NewQueryResultCol("aggr__timeseries__a2-denominator__count", int64(202)),
}},
},
ExpectedPancakeSQL: `
SELECT count(*) AS "aggr__timeseries__count",
countIf(True) AS
"name",
countIf(NOT ("field" = 'sth')) AS
"name"
countIf(NOT ("table.flower" = 'clover')) AS "metric__timeseries__a2-numerator_col_0",
countIf(true) AS "aggr__timeseries__a2-denominator__count"
FROM __quesma_table_name
WHERE ("@timestamp">=parseDateTime64BestEffort('2024-10-11T09:58:03.723Z') AND
"@timestamp"<=parseDateTime64BestEffort('2024-10-11T10:13:03.723Z'))`,
WHERE ("@timestamp">=fromUnixTimestamp64Milli(1728640683723) AND "@timestamp"<=
fromUnixTimestamp64Milli(1728641583723))`,
},
{ // [2]
TestName: "simplest auto_date_histogram",
Expand Down

0 comments on commit 3992297

Please sign in to comment.