File tree Expand file tree Collapse file tree 2 files changed +53
-2
lines changed
rust/cubesql/cubesql/src/compile Expand file tree Collapse file tree 2 files changed +53
-2
lines changed Original file line number Diff line number Diff line change @@ -1419,11 +1419,22 @@ pub fn create_str_to_date_udf() -> ScalarUDF {
14191419
14201420 let format = postgres_datetime_format_to_iso ( format. clone ( ) ) ;
14211421
1422- let res = NaiveDateTime :: parse_from_str ( timestamp, & format) . map_err ( |e| {
1422+ let mut res = NaiveDateTime :: parse_from_str ( timestamp, & format) . map_err ( |e| {
14231423 DataFusionError :: Execution ( format ! (
14241424 "Error evaluating str_to_date('{timestamp}', '{format}'): {e}"
14251425 ) )
1426- } ) ?;
1426+ } ) ;
1427+
1428+ // Try parsing with date format if parsing with datetime format fails
1429+ if res. is_err ( ) {
1430+ if let Ok ( dt) = NaiveDate :: parse_from_str ( timestamp, & format) . map ( |d| {
1431+ d. and_hms_opt ( 0 , 0 , 0 )
1432+ . expect ( "Unable to add zero time to naive date" )
1433+ } ) {
1434+ res = Ok ( dt) ;
1435+ }
1436+ }
1437+ let res = res?;
14271438
14281439 Ok ( ColumnarValue :: Scalar ( ScalarValue :: TimestampNanosecond (
14291440 Some ( res. and_utc ( ) . timestamp_nanos_opt ( ) . unwrap ( ) ) ,
Original file line number Diff line number Diff line change @@ -18413,4 +18413,44 @@ LIMIT {{ limit }}{% endif %}"#.to_string(),
1841318413 displayable(physical_plan.as_ref()).indent()
1841418414 );
1841518415 }
18416+
18417+ #[tokio::test]
18418+ async fn test_to_timestamp_date_only() {
18419+ if !Rewriter::sql_push_down_enabled() {
18420+ return;
18421+ }
18422+ init_testing_logger();
18423+
18424+ let logical_plan = convert_select_to_query_plan(
18425+ r#"
18426+ SELECT customer_gender
18427+ FROM KibanaSampleDataEcommerce
18428+ WHERE order_date >= TO_TIMESTAMP('2025-01-01', 'YYYY-MM-DD')
18429+ GROUP BY 1
18430+ "#
18431+ .to_string(),
18432+ DatabaseProtocol::PostgreSQL,
18433+ )
18434+ .await
18435+ .as_logical_plan();
18436+
18437+ assert_eq!(
18438+ logical_plan.find_cube_scan().request,
18439+ V1LoadRequestQuery {
18440+ measures: Some(vec![]),
18441+ dimensions: Some(vec![
18442+ "KibanaSampleDataEcommerce.customer_gender".to_string(),
18443+ ]),
18444+ segments: Some(vec![]),
18445+ order: Some(vec![]),
18446+ filters: Some(vec![V1LoadRequestQueryFilterItem {
18447+ member: Some("KibanaSampleDataEcommerce.order_date".to_string()),
18448+ operator: Some("afterOrOnDate".to_string()),
18449+ values: Some(vec!["2025-01-01T00:00:00.000Z".to_string()]),
18450+ ..Default::default()
18451+ }]),
18452+ ..Default::default()
18453+ }
18454+ )
18455+ }
1841618456}
You can’t perform that action at this time.
0 commit comments