@@ -14659,6 +14659,7 @@ ORDER BY "source"."str0" ASC
1465914659 .contains("DATEADD(day, 7,"));
1466014660
1466114661 // BigQuery
14662+ let bq_templates = vec![("functions/DATE_ADD".to_string(), "{% if date_part|upper in ['YEAR', 'MONTH', 'QUARTER'] %}TIMESTAMP(DATETIME_ADD(DATETIME({{ args[2] }}), INTERVAL {{ interval }} {{ date_part }})){% else %}TIMESTAMP_ADD({{ args[2] }}, INTERVAL {{ interval }} {{ date_part }}){% endif %}".to_string())];
1466214663 let query_plan = convert_select_to_query_plan_customized(
1466314664 "
1466414665 SELECT DATEADD(DAY, 7, order_date) AS d
@@ -14668,9 +14669,7 @@ ORDER BY "source"."str0" ASC
1466814669 "
1466914670 .to_string(),
1467014671 DatabaseProtocol::PostgreSQL,
14671- vec![
14672- ("functions/DATEADD".to_string(), "DATETIME_ADD(CAST({{ args[2] }} AS DATETTIME), INTERVAL {{ interval }} {{ date_part }})".to_string()),
14673- ],
14672+ bq_templates.clone(),
1467414673 )
1467514674 .await;
1467614675
@@ -14682,9 +14681,35 @@ ORDER BY "source"."str0" ASC
1468214681
1468314682 let logical_plan = query_plan.as_logical_plan();
1468414683 let sql = logical_plan.find_cube_scan_wrapped_sql().wrapped_sql.sql;
14685- assert!(sql.contains("DATETIME_ADD(CAST("));
14684+ println!("{}", sql);
14685+ assert!(sql.contains("TIMESTAMP_ADD("));
1468614686 assert!(sql.contains("INTERVAL 7 day)"));
1468714687
14688+ let query_plan = convert_select_to_query_plan_customized(
14689+ "
14690+ SELECT DATEADD(MONTH, 7, order_date) AS d
14691+ FROM KibanaSampleDataEcommerce AS k
14692+ GROUP BY 1
14693+ ORDER BY 1 DESC
14694+ "
14695+ .to_string(),
14696+ DatabaseProtocol::PostgreSQL,
14697+ bq_templates,
14698+ )
14699+ .await;
14700+
14701+ let physical_plan = query_plan.as_physical_plan().await.unwrap();
14702+ println!(
14703+ "Physical plan: {}",
14704+ displayable(physical_plan.as_ref()).indent()
14705+ );
14706+
14707+ let logical_plan = query_plan.as_logical_plan();
14708+ let sql = logical_plan.find_cube_scan_wrapped_sql().wrapped_sql.sql;
14709+ println!("{}", sql);
14710+ assert!(sql.contains("TIMESTAMP(DATETIME_ADD(DATETIME("));
14711+ assert!(sql.contains("INTERVAL 7 MONTH)"));
14712+
1468814713 // Postgres
1468914714 let query_plan = convert_select_to_query_plan_customized(
1469014715 "
@@ -14696,7 +14721,7 @@ ORDER BY "source"."str0" ASC
1469614721 .to_string(),
1469714722 DatabaseProtocol::PostgreSQL,
1469814723 vec![(
14699- "functions/DATEADD ".to_string(),
14724+ "functions/DATE_ADD ".to_string(),
1470014725 "({{ args[2] }} + \'{{ interval }} {{ date_part }}\'::interval)".to_string(),
1470114726 )],
1470214727 )
0 commit comments