From 4383a698763c482a36a5878b2f0e7b3cb76bcb03 Mon Sep 17 00:00:00 2001 From: WU Jingdi Date: Mon, 18 Dec 2023 15:48:49 +0800 Subject: [PATCH] fix!: remove range calendar as `To` option (#2940) fix: remove range calendar as `To` option --- src/query/src/range_select/plan_rewrite.rs | 19 +++++++------------ tests/cases/standalone/common/range/to.result | 11 ----------- tests/cases/standalone/common/range/to.sql | 2 -- 3 files changed, 7 insertions(+), 25 deletions(-) diff --git a/src/query/src/range_select/plan_rewrite.rs b/src/query/src/range_select/plan_rewrite.rs index 980de4c3579e..0030faca8e38 100644 --- a/src/query/src/range_select/plan_rewrite.rs +++ b/src/query/src/range_select/plan_rewrite.rs @@ -132,14 +132,15 @@ fn parse_duration_expr(args: &[Expr], i: usize) -> DFResult { /// Parse the `align to` clause and return a UTC timestamp with unit of millisecond, /// which is used as the basis for dividing time slot during the align operation. /// 1. NOW: align to current execute time -/// 2. CALENDAR (as Default Option): align to timestamp `0` /// 2. Timestamp string: align to specific timestamp +/// 3. leave empty (as Default Option): align to unix epoch 0 fn parse_align_to(args: &[Expr], i: usize) -> DFResult { let s = parse_str_expr(args, i)?; let upper = s.to_uppercase(); match upper.as_str() { "NOW" => return Ok(Timestamp::current_millis().value()), - "CALENDAR" | "" => return Ok(0), + // default align to unix epoch 0 + "" => return Ok(0), _ => (), } Timestamp::from_str(s) @@ -748,16 +749,10 @@ mod test { let args = vec![Expr::Literal(ScalarValue::Utf8(Some("NOW".into())))]; let epsinon = parse_align_to(&args, 0).unwrap() - Timestamp::current_millis().value(); assert!(epsinon.abs() < 100); - // test CALENDAR - let args = vec![ - Expr::Literal(ScalarValue::Utf8(Some("".into()))), - Expr::Literal(ScalarValue::Utf8(Some("CALENDAR".into()))), - ]; - assert!( - parse_align_to(&args, 0).unwrap() == parse_align_to(&args, 1).unwrap() - && parse_align_to(&args, 0).unwrap() == 0 - ); - // test CALENDAR + // test default + let args = vec![Expr::Literal(ScalarValue::Utf8(Some("".into())))]; + assert!(parse_align_to(&args, 0).unwrap() == 0); + // test Timestamp let args = vec![Expr::Literal(ScalarValue::Utf8(Some( "1970-01-01T00:00:00+08:00".into(), )))]; diff --git a/tests/cases/standalone/common/range/to.result b/tests/cases/standalone/common/range/to.result index 2666cfe45085..9568a23e7af7 100644 --- a/tests/cases/standalone/common/range/to.result +++ b/tests/cases/standalone/common/range/to.result @@ -29,17 +29,6 @@ SELECT ts, host, min(val) RANGE '1d' FROM host ALIGN '1d' ORDER BY host, ts; | 1970-01-03T00:00:00 | host2 | 6 | +---------------------+-------+----------------------------------+ -SELECT ts, host, min(val) RANGE '1d' FROM host ALIGN '1d' TO CALENDAR ORDER BY host, ts; - -+---------------------+-------+----------------------------------+ -| ts | host | MIN(host.val) RANGE 1d FILL NULL | -+---------------------+-------+----------------------------------+ -| 1970-01-02T00:00:00 | host1 | 0 | -| 1970-01-03T00:00:00 | host1 | 2 | -| 1970-01-02T00:00:00 | host2 | 4 | -| 1970-01-03T00:00:00 | host2 | 6 | -+---------------------+-------+----------------------------------+ - SELECT ts, host, min(val) RANGE '1d' FROM host ALIGN '1d' TO UNKNOWN ORDER BY host, ts; Error: 3000(PlanQuery), DataFusion error: Error during planning: Illegal `align to` argument `UNKNOWN` in range select query, can't be parse as NOW/CALENDAR/Timestamp, error: Failed to parse a string into Timestamp, raw string: UNKNOWN diff --git a/tests/cases/standalone/common/range/to.sql b/tests/cases/standalone/common/range/to.sql index 2ec32e3c2e26..ba4a001a48ca 100644 --- a/tests/cases/standalone/common/range/to.sql +++ b/tests/cases/standalone/common/range/to.sql @@ -16,8 +16,6 @@ INSERT INTO TABLE host VALUES SELECT ts, host, min(val) RANGE '1d' FROM host ALIGN '1d' ORDER BY host, ts; -SELECT ts, host, min(val) RANGE '1d' FROM host ALIGN '1d' TO CALENDAR ORDER BY host, ts; - SELECT ts, host, min(val) RANGE '1d' FROM host ALIGN '1d' TO UNKNOWN ORDER BY host, ts; SELECT ts, host, min(val) RANGE '1d' FROM host ALIGN '1d' TO '1900-01-01T00:00:00+01:00' ORDER BY host, ts;