File tree Expand file tree Collapse file tree 2 files changed +38
-0
lines changed
packages/cubejs-schema-compiler/src/adapter
rust/cubesql/cubesql/src/compile Expand file tree Collapse file tree 2 files changed +38
-0
lines changed Original file line number Diff line number Diff line change @@ -138,6 +138,7 @@ export class PrestodbQuery extends BaseQuery {
138138 templates . functions . DATEPART = 'DATE_PART({{ args_concat }})' ;
139139 templates . functions . DATEDIFF = 'DATE_DIFF(\'{{ date_part }}\', {{ args[1] }}, {{ args[2] }})' ;
140140 templates . functions . CURRENTDATE = 'CURRENT_DATE' ;
141+ templates . functions . TRUNC = 'TRUNCATE({{ args_concat }})' ;
141142 delete templates . functions . PERCENTILECONT ;
142143 templates . statements . select = '{% if ctes %} WITH \n' +
143144 '{{ ctes | join(\',\n\') }}\n' +
Original file line number Diff line number Diff line change @@ -17618,4 +17618,41 @@ LIMIT {{ limit }}{% endif %}"#.to_string(),
1761817618 displayable(physical_plan.as_ref()).indent()
1761917619 );
1762017620 }
17621+
17622+ #[tokio::test]
17623+ async fn test_trino_truncate() {
17624+ if !Rewriter::sql_push_down_enabled() {
17625+ return;
17626+ }
17627+ init_testing_logger();
17628+
17629+ let query_plan = convert_select_to_query_plan_customized(
17630+ r#"
17631+ SELECT
17632+ CAST(TRUNC(EXTRACT(MONTH FROM "k"."order_date")) AS INTEGER) AS "mn:order_date:ok",
17633+ SUM("k"."sumPrice") AS "sum:sumPrice:ok",
17634+ DATE_TRUNC('YEAR', CAST("k"."order_date" AS TIMESTAMP)) AS "tyr:order_date:ok"
17635+ FROM "public"."KibanaSampleDataEcommerce" "k"
17636+ WHERE (CAST(TRUNC(EXTRACT(YEAR FROM "k"."order_date")) AS INTEGER) IN (2023, 2024))
17637+ GROUP BY 1, 3
17638+ "#
17639+ .to_string(),
17640+ DatabaseProtocol::PostgreSQL,
17641+ vec![(
17642+ "functions/TRUNC".to_string(),
17643+ "TRUNCATE({{ args_concat }})".to_string(),
17644+ )],
17645+ )
17646+ .await;
17647+
17648+ let physical_plan = query_plan.as_physical_plan().await.unwrap();
17649+ println!(
17650+ "Physical plan: {}",
17651+ displayable(physical_plan.as_ref()).indent()
17652+ );
17653+
17654+ let logical_plan = query_plan.as_logical_plan();
17655+ let sql = logical_plan.find_cube_scan_wrapped_sql().wrapped_sql.sql;
17656+ assert!(sql.contains("TRUNCATE(EXTRACT(month FROM "));
17657+ }
1762117658}
You can’t perform that action at this time.
0 commit comments