Skip to content

Commit

Permalink
feat(cubestore): Support quarter granularity for date_trunc fn (#4011)
Browse files Browse the repository at this point in the history
  • Loading branch information
ovr committed Feb 1, 2022
1 parent c46552b commit 404482d
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 1 deletion.
2 changes: 1 addition & 1 deletion rust/cubestore/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

51 changes: 51 additions & 0 deletions rust/cubestore/cubestore-sql-tests/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ pub fn sql_tests() -> Vec<(&'static str, TestFn)> {
t("case_column_escaping", case_column_escaping),
t("inner_column_escaping", inner_column_escaping),
t("convert_tz", convert_tz),
t("date_trunc", date_trunc),
t("coalesce", coalesce),
t("ilike", ilike),
t("count_distinct_crash", count_distinct_crash),
Expand Down Expand Up @@ -1145,6 +1146,56 @@ async fn convert_tz(service: Box<dyn SqlClient>) {
);
}

async fn date_trunc(service: Box<dyn SqlClient>) {
service.exec_query("CREATE SCHEMA foo").await.unwrap();

service
.exec_query("CREATE TABLE foo.timestamps (t timestamp)")
.await
.unwrap();

service
.exec_query(
"INSERT INTO foo.timestamps (t) VALUES \
('2020-01-01T00:00:00.000Z'), \
('2020-03-01T00:00:00.000Z'), \
('2020-04-01T00:00:00.000Z'), \
('2020-07-01T00:00:00.000Z'), \
('2020-09-01T00:00:00.000Z')",
)
.await
.unwrap();

let result = service
.exec_query(
"SELECT date_trunc('quarter', `t`) `quarter` \
FROM foo.timestamps `timestamp`",
)
.await
.unwrap();

assert_eq!(
result.get_rows(),
&vec![
Row::new(vec![TableValue::Timestamp(TimestampValue::new(
1577836800000000000
)),]),
Row::new(vec![TableValue::Timestamp(TimestampValue::new(
1577836800000000000
)),]),
Row::new(vec![TableValue::Timestamp(TimestampValue::new(
1585699200000000000
)),]),
Row::new(vec![TableValue::Timestamp(TimestampValue::new(
1593561600000000000
)),]),
Row::new(vec![TableValue::Timestamp(TimestampValue::new(
1593561600000000000
)),])
]
);
}

async fn ilike(service: Box<dyn SqlClient>) {
service.exec_query("CREATE SCHEMA s").await.unwrap();
service
Expand Down

0 comments on commit 404482d

Please sign in to comment.