Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jakozaur committed Oct 14, 2024
1 parent 41a0f5f commit deee7f0
Show file tree
Hide file tree
Showing 11 changed files with 196 additions and 177 deletions.
6 changes: 3 additions & 3 deletions quesma/queryparser/query_parser_range_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ var parseRangeTests = []parseRangeTest{
`CREATE TABLE ` + tableName + `
( "message" String, "timestamp" DateTime64(3, 'UTC') )
ENGINE = Memory`,
`("timestamp">=toDateTime64(1.706881636029e+09,3) AND "timestamp"<=toDateTime64(1.707486436029e+09,3))`,
`("timestamp">=fromUnixTimestamp64Milli(1706881636029) AND "timestamp"<=fromUnixTimestamp64Milli(1707486436029))`,
},
{
"parseDateTimeBestEffort",
Expand All @@ -46,7 +46,7 @@ var parseRangeTests = []parseRangeTest{
`CREATE TABLE ` + tableName + `
( "message" String, "timestamp" DateTime )
ENGINE = Memory`,
`("timestamp">=toDateTime64(1.706881636029e+09,3) AND "timestamp"<=toDateTime64(1.707486436029e+09,3))`,
`("timestamp">=fromUnixTimestamp64Milli(1706881636029) AND "timestamp"<=fromUnixTimestamp64Milli(1707486436029))`,
},
{
"numeric range",
Expand All @@ -72,7 +72,7 @@ var parseRangeTests = []parseRangeTest{
`CREATE TABLE ` + tableName + `
( "message" String, "timestamp" DateTime64(3, 'UTC') )
ENGINE = Memory`,
`("timestamp">=toDateTime64(1.706881636e+09,3) AND "timestamp"<=toDateTime64(1.707486436e+09,3))`,
`("timestamp">=fromUnixTimestamp64Milli(1706881636000) AND "timestamp"<=fromUnixTimestamp64Milli(1707486436000))`,
},
}

Expand Down
4 changes: 2 additions & 2 deletions quesma/quesma/functionality/terms_enum/terms_enum_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ func testHandleTermsEnumRequest(t *testing.T, requestBody []byte) {
}
qt := &queryparser.ClickhouseQueryTranslator{ClickhouseLM: lm, Table: table, Ctx: context.Background(), Schema: s.Tables[schema.TableName(testTableName)]}
// Here we additionally verify that terms for `_tier` are **NOT** included in the SQL query
expectedQuery1 := `SELECT DISTINCT "client_name" FROM ` + testTableName + ` WHERE ("epoch_time">=toDateTime64(1.7090367e+09,3) AND "epoch_time"<=toDateTime64(1.709037659999e+09,3)) LIMIT 13`
expectedQuery2 := `SELECT DISTINCT "client_name" FROM ` + testTableName + ` WHERE ("epoch_time">=toDateTime64(1.7090367e+09,3) AND "epoch_time"<=toDateTime64(1.709037659999e+09,3)) LIMIT 13`
expectedQuery1 := `SELECT DISTINCT "client_name" FROM ` + testTableName + ` WHERE ("epoch_time">=fromUnixTimestamp64Milli(1709036700000) AND "epoch_time"<=fromUnixTimestamp64Milli(1709037659999)) LIMIT 13`
expectedQuery2 := `SELECT DISTINCT "client_name" FROM ` + testTableName + ` WHERE ("epoch_time">=fromUnixTimestamp64Milli(1709036700000) AND "epoch_time"<=fromUnixTimestamp64Milli(1709037659999)) LIMIT 13`

// Once in a while `AND` conditions could be swapped, so we match both cases
mock.ExpectQuery(fmt.Sprintf("%s|%s", regexp.QuoteMeta(expectedQuery1), regexp.QuoteMeta(expectedQuery2))).
Expand Down
43 changes: 23 additions & 20 deletions quesma/quesma/search_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -425,35 +425,38 @@ func TestHandlingDateTimeFields(t *testing.T) {
dateTimeTimestampField: `SELECT toInt64(toUnixTimestamp("timestamp") / 60) AS "aggr__0__key_0",
count(*) AS "aggr__0__count"
FROM __quesma_table_name
WHERE ((("timestamp64">=toDateTime64(1.706542596491e+09, 3) AND "timestamp64"<=
toDateTime64(1.706551896491e+09, 3)) AND ("timestamp">=toDateTime64(
1.706542596491e+09, 3) AND "timestamp"<=toDateTime64(1.706551896491e+09, 3)))
AND NOT (("@timestamp">=toDateTime64(1.706542596491e+09, 3) AND "@timestamp"<=
toDateTime64(1.706551896491e+09, 3))))
WHERE ((("timestamp64">=fromUnixTimestamp64Milli(1706542596491) AND
"timestamp64"<=fromUnixTimestamp64Milli(1706551896491)) AND ("timestamp">=
fromUnixTimestamp64Milli(1706542596491) AND "timestamp"<=
fromUnixTimestamp64Milli(1706551896491))) AND NOT (("@timestamp">=
fromUnixTimestamp64Milli(1706542596491) AND "@timestamp"<=
fromUnixTimestamp64Milli(1706551896491))))
GROUP BY toInt64(toUnixTimestamp("timestamp") / 60) AS "aggr__0__key_0"
ORDER BY "aggr__0__key_0" ASC`,
dateTime64TimestampField: `SELECT toInt64(toUnixTimestamp64Milli("timestamp64") / 60000) AS
"aggr__0__key_0", count(*) AS "aggr__0__count"
FROM __quesma_table_name
WHERE ((("timestamp64">=toDateTime64(1.706542596491e+09, 3) AND "timestamp64"<=
toDateTime64(1.706551896491e+09, 3)) AND ("timestamp">=toDateTime64(
1.706542596491e+09, 3) AND "timestamp"<=toDateTime64(1.706551896491e+09, 3)))
AND NOT (("@timestamp">=toDateTime64(1.706542596491e+09, 3) AND "@timestamp"<=
toDateTime64(1.706551896491e+09, 3))))
WHERE ((("timestamp64">=fromUnixTimestamp64Milli(1706542596491) AND
"timestamp64"<=fromUnixTimestamp64Milli(1706551896491)) AND ("timestamp">=
fromUnixTimestamp64Milli(1706542596491) AND "timestamp"<=
fromUnixTimestamp64Milli(1706551896491))) AND NOT (("@timestamp">=
fromUnixTimestamp64Milli(1706542596491) AND "@timestamp"<=
fromUnixTimestamp64Milli(1706551896491))))
GROUP BY toInt64(toUnixTimestamp64Milli("timestamp64") / 60000) AS
"aggr__0__key_0"
ORDER BY "aggr__0__key_0" ASC`,
dateTime64OurTimestampField: `SELECT toInt64(toUnixTimestamp64Milli("@timestamp") / 60000) AS "aggr__0__key_0"
, count(*) AS "aggr__0__count"
FROM __quesma_table_name
WHERE ((("timestamp64">=toDateTime64(1.706542596491e+09, 3) AND "timestamp64"<=
toDateTime64(1.706551896491e+09, 3)) AND ("timestamp">=toDateTime64(
1.706542596491e+09, 3) AND "timestamp"<=toDateTime64(1.706551896491e+09, 3)))
AND NOT (("@timestamp">=toDateTime64(1.706542596491e+09, 3) AND "@timestamp"<=
toDateTime64(1.706551896491e+09, 3))))
GROUP BY toInt64(toUnixTimestamp64Milli("@timestamp") / 60000) AS
"aggr__0__key_0"
ORDER BY "aggr__0__key_0" ASC`,
, count(*) AS "aggr__0__count"
FROM __quesma_table_name
WHERE ((("timestamp64">=fromUnixTimestamp64Milli(1706542596491) AND
"timestamp64"<=fromUnixTimestamp64Milli(1706551896491)) AND ("timestamp">=
fromUnixTimestamp64Milli(1706542596491) AND "timestamp"<=
fromUnixTimestamp64Milli(1706551896491))) AND NOT (("@timestamp">=
fromUnixTimestamp64Milli(1706542596491) AND "@timestamp"<=
fromUnixTimestamp64Milli(1706551896491))))
GROUP BY toInt64(toUnixTimestamp64Milli("@timestamp") / 60000) AS
"aggr__0__key_0"
ORDER BY "aggr__0__key_0" ASC`,
}

db, mock := util.InitSqlMockWithPrettySqlAndPrint(t, false)
Expand Down
Loading

0 comments on commit deee7f0

Please sign in to comment.