Skip to content

Commit 69aed08

Browse files
committed
feat(cubesql): Support TimestampNanosecond in CASE
1 parent 6b7aff6 commit 69aed08

File tree

5 files changed

+105
-14
lines changed

5 files changed

+105
-14
lines changed

packages/cubejs-backend-native/Cargo.lock

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rust/cubesql/Cargo.lock

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rust/cubesql/cubesql/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ homepage = "https://cube.dev"
1010

1111
[dependencies]
1212
arc-swap = "1"
13-
datafusion = { git = 'https://github.com/cube-js/arrow-datafusion.git', rev = "1abe9d5c7451e3d36c208801b0756fa9463f552e", default-features = false, features = ["regex_expressions", "unicode_expressions"] }
13+
datafusion = { git = 'https://github.com/cube-js/arrow-datafusion.git', rev = "824a1a3276939c27f20db55163259adb9c586bac", default-features = false, features = ["regex_expressions", "unicode_expressions"] }
1414
anyhow = "1.0"
1515
thiserror = "1.0.50"
1616
cubeclient = { path = "../cubeclient" }

rust/cubesql/cubesql/src/compile/engine/df/columar.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use datafusion::{
22
arrow::{
33
array::{self, *},
4-
datatypes::DataType,
4+
datatypes::{DataType, TimeUnit},
55
},
66
error::{DataFusionError, Result},
77
};
@@ -148,6 +148,13 @@ pub fn if_then_else(
148148
true_values,
149149
false_values
150150
),
151+
DataType::Timestamp(TimeUnit::Nanosecond, None) => if_then_else!(
152+
array::TimestampNanosecondBuilder,
153+
array::TimestampNanosecondArray,
154+
bools,
155+
true_values,
156+
false_values
157+
),
151158
other => Err(DataFusionError::Execution(format!(
152159
"CASE does not support '{:?}'",
153160
other

rust/cubesql/cubesql/src/compile/mod.rs

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20480,6 +20480,90 @@ limit
2048020480
);
2048120481
}
2048220482

20483+
#[tokio::test]
20484+
async fn test_case_timestamp_nanosecond() {
20485+
if !Rewriter::sql_push_down_enabled() {
20486+
return;
20487+
}
20488+
init_logger();
20489+
20490+
let query_plan = convert_select_to_query_plan(
20491+
r#"
20492+
select
20493+
"_"."order_date" as "c10"
20494+
from
20495+
(
20496+
select
20497+
"order_date",
20498+
"_"."t0_0" as "t0_0",
20499+
"_"."t1_0" as "t1_0"
20500+
from
20501+
(
20502+
select
20503+
"_"."order_date",
20504+
"_"."o0",
20505+
"_"."t0_0",
20506+
"_"."t1_0"
20507+
from
20508+
(
20509+
select
20510+
"_"."order_date" as "order_date",
20511+
"_"."o0" as "o0",
20512+
case
20513+
when "_"."o0" is not null then "_"."o0"
20514+
else timestamp '1899-12-28 00:00:00'
20515+
end as "t0_0",
20516+
case
20517+
when "_"."o0" is null then 0
20518+
else 1
20519+
end as "t1_0"
20520+
from
20521+
(
20522+
select
20523+
"rows"."order_date" as "order_date",
20524+
"rows"."o0" as "o0"
20525+
from
20526+
(
20527+
select
20528+
"order_date" as "order_date",
20529+
"order_date" as "o0"
20530+
from
20531+
"public"."KibanaSampleDataEcommerce" "$Table"
20532+
) "rows"
20533+
group by
20534+
"order_date",
20535+
"o0"
20536+
) "_"
20537+
) "_"
20538+
) "_"
20539+
) "_"
20540+
order by
20541+
"_"."t0_0",
20542+
"_"."t1_0"
20543+
limit
20544+
101
20545+
"#
20546+
.to_string(),
20547+
DatabaseProtocol::PostgreSQL,
20548+
)
20549+
.await;
20550+
20551+
assert_eq!(
20552+
query_plan.as_logical_plan().find_cube_scan().request,
20553+
V1LoadRequestQuery {
20554+
measures: Some(vec![]),
20555+
dimensions: Some(vec!["KibanaSampleDataEcommerce.order_date".to_string()]),
20556+
segments: Some(vec![]),
20557+
time_dimensions: None,
20558+
order: None,
20559+
limit: None,
20560+
offset: None,
20561+
filters: None,
20562+
ungrouped: None,
20563+
}
20564+
);
20565+
}
20566+
2048320567
#[tokio::test]
2048420568
async fn test_langchain_pgcatalog_schema() -> Result<(), CubeError> {
2048520569
insta::assert_snapshot!(

0 commit comments

Comments
 (0)