Skip to content

Commit

Permalink
Update tests to new logic
Browse files Browse the repository at this point in the history
  • Loading branch information
trzysiek committed Oct 3, 2024
1 parent 832f6f9 commit 4e70fbe
Show file tree
Hide file tree
Showing 11 changed files with 162 additions and 310 deletions.
4 changes: 2 additions & 2 deletions quesma/kibana/dates_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"testing"
)

func TestDateManager_MissingInDateHistogramToUnixTimestamp(t *testing.T) {
func TestDateManager_parseStrictDateOptionalTimeOrEpochMillis(t *testing.T) {
tests := []struct {
missing any
wantUnixTimestamp int64
Expand Down Expand Up @@ -38,7 +38,7 @@ func TestDateManager_MissingInDateHistogramToUnixTimestamp(t *testing.T) {
for _, tt := range tests {
t.Run(fmt.Sprintf("%v", tt.missing), func(t *testing.T) {
dm := NewDateManager()
gotUnixTs, gotParsingSucceeded := dm.MissingInDateHistogramToUnixTimestamp(tt.missing)
gotUnixTs, gotParsingSucceeded := dm.parseStrictDateOptionalTimeOrEpochMillis(tt.missing)
assert.Equalf(t, tt.wantUnixTimestamp, gotUnixTs, "MissingInDateHistogramToUnixTimestamp(%v)", tt.missing)
assert.Equalf(t, tt.wantParsingSucceeded, gotParsingSucceeded, "MissingInDateHistogramToUnixTimestamp(%v)", tt.missing)
})
Expand Down
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">=parseDateTime64BestEffort('2024-02-02T13:47:16.029Z') AND "timestamp"<=parseDateTime64BestEffort('2024-02-09T13:47:16.029Z'))`,
`("timestamp">=toDateTime(1706881636029) AND "timestamp"<=toDateTime(1707486436029))`,
},
{
"parseDateTimeBestEffort",
Expand All @@ -46,7 +46,7 @@ var parseRangeTests = []parseRangeTest{
`CREATE TABLE ` + tableName + `
( "message" String, "timestamp" DateTime )
ENGINE = Memory`,
`("timestamp">=parseDateTimeBestEffort('2024-02-02T13:47:16.029Z') AND "timestamp"<=parseDateTimeBestEffort('2024-02-09T13:47:16.029Z'))`,
`("timestamp">=toDateTime(1706881636029) AND "timestamp"<=toDateTime(1707486436029))`,
},
{
"numeric range",
Expand All @@ -72,7 +72,7 @@ var parseRangeTests = []parseRangeTest{
`CREATE TABLE ` + tableName + `
( "message" String, "timestamp" DateTime64(3, 'UTC') )
ENGINE = Memory`,
`("timestamp">=parseDateTime64BestEffort('2024-02-02T13:47:16') AND "timestamp"<=parseDateTime64BestEffort('2024-02-09T13:47:16'))`,
`("timestamp">=toDateTime(1706881636000) AND "timestamp"<=toDateTime(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 @@ -108,8 +108,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">=parseDateTimeBestEffort('2024-02-27T12:25:00.000Z') AND "epoch_time"<=parseDateTimeBestEffort('2024-02-27T12:40:59.999Z')) LIMIT 13`
expectedQuery2 := `SELECT DISTINCT "client_name" FROM ` + testTableName + ` WHERE ("epoch_time"<=parseDateTimeBestEffort('2024-02-27T12:40:59.999Z') AND "epoch_time">=parseDateTimeBestEffort('2024-02-27T12:25:00.000Z')) LIMIT 13`
expectedQuery1 := `SELECT DISTINCT "client_name" FROM ` + testTableName + ` WHERE ("epoch_time">=toDateTime(1709036700000) AND "epoch_time"<=toDateTime(1709037659999)) LIMIT 13`
expectedQuery2 := `SELECT DISTINCT "client_name" FROM ` + testTableName + ` WHERE ("epoch_time">=toDateTime(1709036700000) AND "epoch_time"<=toDateTime(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
30 changes: 12 additions & 18 deletions quesma/quesma/search_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -356,35 +356,29 @@ 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">=parseDateTime64BestEffort('2024-01-29T15:36:36.491Z')
AND "timestamp64"<=parseDateTime64BestEffort('2024-01-29T18:11:36.491Z')) AND
("timestamp">=parseDateTimeBestEffort('2024-01-29T15:36:36.491Z') AND
"timestamp"<=parseDateTimeBestEffort('2024-01-29T18:11:36.491Z'))) AND NOT ((
"@timestamp">=parseDateTime64BestEffort('2024-01-29T15:36:36.491Z') AND
"@timestamp"<=parseDateTime64BestEffort('2024-01-29T18:11:36.491Z'))))
WHERE ((("timestamp64">=toDateTime(1706542596491) AND "timestamp64"<=toDateTime(
1706551896491)) AND ("timestamp">=toDateTime(1706542596491) AND "timestamp"<=
toDateTime(1706551896491))) AND NOT (("@timestamp">=toDateTime(1706542596491)
AND "@timestamp"<=toDateTime(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">=parseDateTime64BestEffort('2024-01-29T15:36:36.491Z')
AND "timestamp64"<=parseDateTime64BestEffort('2024-01-29T18:11:36.491Z')) AND
("timestamp">=parseDateTimeBestEffort('2024-01-29T15:36:36.491Z') AND
"timestamp"<=parseDateTimeBestEffort('2024-01-29T18:11:36.491Z'))) AND NOT ((
"@timestamp">=parseDateTime64BestEffort('2024-01-29T15:36:36.491Z') AND
"@timestamp"<=parseDateTime64BestEffort('2024-01-29T18:11:36.491Z'))))
WHERE ((("timestamp64">=toDateTime(1706542596491) AND "timestamp64"<=toDateTime(
1706551896491)) AND ("timestamp">=toDateTime(1706542596491) AND "timestamp"<=
toDateTime(1706551896491))) AND NOT (("@timestamp">=toDateTime(1706542596491)
AND "@timestamp"<=toDateTime(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">=parseDateTime64BestEffort('2024-01-29T15:36:36.491Z')
AND "timestamp64"<=parseDateTime64BestEffort('2024-01-29T18:11:36.491Z')) AND
("timestamp">=parseDateTimeBestEffort('2024-01-29T15:36:36.491Z') AND
"timestamp"<=parseDateTimeBestEffort('2024-01-29T18:11:36.491Z'))) AND NOT ((
"@timestamp">=parseDateTime64BestEffort('2024-01-29T15:36:36.491Z') AND
"@timestamp"<=parseDateTime64BestEffort('2024-01-29T18:11:36.491Z'))))
WHERE ((("timestamp64">=toDateTime(1706542596491) AND "timestamp64"<=toDateTime(
1706551896491)) AND ("timestamp">=toDateTime(1706542596491) AND "timestamp"<=
toDateTime(1706551896491))) AND NOT (("@timestamp">=toDateTime(1706542596491)
AND "@timestamp"<=toDateTime(1706551896491))))
GROUP BY toInt64(toUnixTimestamp64Milli("@timestamp") / 60000) AS
"aggr__0__key_0"
ORDER BY "aggr__0__key_0" ASC`,
Expand Down
Loading

0 comments on commit 4e70fbe

Please sign in to comment.