Skip to content

Commit

Permalink
fix!: remove range calendar as To option (#2940)
Browse files Browse the repository at this point in the history
fix: remove range calendar as `To` option
  • Loading branch information
Taylor-lagrange authored Dec 18, 2023
1 parent 033a065 commit 4383a69
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 25 deletions.
19 changes: 7 additions & 12 deletions src/query/src/range_select/plan_rewrite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,14 +132,15 @@ fn parse_duration_expr(args: &[Expr], i: usize) -> DFResult<Duration> {
/// 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<i64> {
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)
Expand Down Expand Up @@ -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(),
)))];
Expand Down
11 changes: 0 additions & 11 deletions tests/cases/standalone/common/range/to.result
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions tests/cases/standalone/common/range/to.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 4383a69

Please sign in to comment.