test: add tests using `to_timestamp()` as predicates in SQL (#2099)

* test: add tests using `to_timestamp()` as predicates in SQL

* fix: cleanup redundancy

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
pull/24376/head
Andrew Lamb 2021-07-22 17:06:52 -04:00 committed by GitHub
parent 67478066b0
commit 38261cc7ac
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 66 additions and 0 deletions

View File

@ -189,6 +189,23 @@ impl DbSetup for NoData {
}
}
/// a measurement with timestamps in 2021
#[derive(Debug)]
pub struct OneMeasurementRealisticTimes {}
#[async_trait]
impl DbSetup for OneMeasurementRealisticTimes {
async fn make(&self) -> Vec<DbScenario> {
let partition_key = "2021-07-20T19";
let lp_lines = vec![
"cpu,region=west user=23.2 1626809330000000000",
"cpu,region=west user=21.0 1626809430000000000",
];
make_one_chunk_scenarios(partition_key, &lp_lines.join("\n")).await
}
}
/// Two measurements data in a single mutable buffer chunk
#[derive(Debug)]
pub struct TwoMeasurementsMubScenario {}

View File

@ -51,6 +51,55 @@ async fn sql_select_from_cpu() {
run_sql_test_case!(TwoMeasurements {}, "SELECT * from cpu", &expected);
}
#[tokio::test]
async fn sql_select_from_cpu_2021() {
let expected = vec![
"+--------+----------------------+------+",
"| region | time | user |",
"+--------+----------------------+------+",
"| west | 2021-07-20T19:28:50Z | 23.2 |",
"| west | 2021-07-20T19:30:30Z | 21 |",
"+--------+----------------------+------+",
];
run_sql_test_case!(
OneMeasurementRealisticTimes {},
"SELECT * from cpu",
&expected
);
}
#[tokio::test]
async fn sql_select_from_cpu_with_timestamp_predicate_explicit_utc() {
let expected = vec![
"+--------+----------------------+------+",
"| region | time | user |",
"+--------+----------------------+------+",
"| west | 2021-07-20T19:30:30Z | 21 |",
"+--------+----------------------+------+",
];
run_sql_test_case!(
OneMeasurementRealisticTimes {},
"SELECT * FROM cpu WHERE time > to_timestamp('2021-07-20 19:28:50+00:00')",
&expected
);
// Use RCF3339 format
run_sql_test_case!(
OneMeasurementRealisticTimes {},
"SELECT * FROM cpu WHERE time > to_timestamp('2021-07-20T19:28:50Z')",
&expected
);
// use cast workaround
run_sql_test_case!(
OneMeasurementRealisticTimes {},
"SELECT * FROM cpu WHERE \
CAST(time AS BIGINT) > CAST(to_timestamp('2021-07-20T19:28:50Z') AS BIGINT)",
&expected
);
}
#[tokio::test]
async fn sql_select_from_cpu_with_projection() {
// expect that to get a subset of the columns and in the order specified