Skip to content

Commit 4383a69

Browse files
fix!: remove range calendar as To option (#2940)
fix: remove range calendar as `To` option
1 parent 033a065 commit 4383a69

3 files changed

Lines changed: 7 additions & 25 deletions

File tree

src/query/src/range_select/plan_rewrite.rs

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -132,14 +132,15 @@ fn parse_duration_expr(args: &[Expr], i: usize) -> DFResult<Duration> {
132132
/// Parse the `align to` clause and return a UTC timestamp with unit of millisecond,
133133
/// which is used as the basis for dividing time slot during the align operation.
134134
/// 1. NOW: align to current execute time
135-
/// 2. CALENDAR (as Default Option): align to timestamp `0`
136135
/// 2. Timestamp string: align to specific timestamp
136+
/// 3. leave empty (as Default Option): align to unix epoch 0
137137
fn parse_align_to(args: &[Expr], i: usize) -> DFResult<i64> {
138138
let s = parse_str_expr(args, i)?;
139139
let upper = s.to_uppercase();
140140
match upper.as_str() {
141141
"NOW" => return Ok(Timestamp::current_millis().value()),
142-
"CALENDAR" | "" => return Ok(0),
142+
// default align to unix epoch 0
143+
"" => return Ok(0),
143144
_ => (),
144145
}
145146
Timestamp::from_str(s)
@@ -748,16 +749,10 @@ mod test {
748749
let args = vec![Expr::Literal(ScalarValue::Utf8(Some("NOW".into())))];
749750
let epsinon = parse_align_to(&args, 0).unwrap() - Timestamp::current_millis().value();
750751
assert!(epsinon.abs() < 100);
751-
// test CALENDAR
752-
let args = vec![
753-
Expr::Literal(ScalarValue::Utf8(Some("".into()))),
754-
Expr::Literal(ScalarValue::Utf8(Some("CALENDAR".into()))),
755-
];
756-
assert!(
757-
parse_align_to(&args, 0).unwrap() == parse_align_to(&args, 1).unwrap()
758-
&& parse_align_to(&args, 0).unwrap() == 0
759-
);
760-
// test CALENDAR
752+
// test default
753+
let args = vec![Expr::Literal(ScalarValue::Utf8(Some("".into())))];
754+
assert!(parse_align_to(&args, 0).unwrap() == 0);
755+
// test Timestamp
761756
let args = vec![Expr::Literal(ScalarValue::Utf8(Some(
762757
"1970-01-01T00:00:00+08:00".into(),
763758
)))];

tests/cases/standalone/common/range/to.result

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,6 @@ SELECT ts, host, min(val) RANGE '1d' FROM host ALIGN '1d' ORDER BY host, ts;
2929
| 1970-01-03T00:00:00 | host2 | 6 |
3030
+---------------------+-------+----------------------------------+
3131

32-
SELECT ts, host, min(val) RANGE '1d' FROM host ALIGN '1d' TO CALENDAR ORDER BY host, ts;
33-
34-
+---------------------+-------+----------------------------------+
35-
| ts | host | MIN(host.val) RANGE 1d FILL NULL |
36-
+---------------------+-------+----------------------------------+
37-
| 1970-01-02T00:00:00 | host1 | 0 |
38-
| 1970-01-03T00:00:00 | host1 | 2 |
39-
| 1970-01-02T00:00:00 | host2 | 4 |
40-
| 1970-01-03T00:00:00 | host2 | 6 |
41-
+---------------------+-------+----------------------------------+
42-
4332
SELECT ts, host, min(val) RANGE '1d' FROM host ALIGN '1d' TO UNKNOWN ORDER BY host, ts;
4433

4534
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

tests/cases/standalone/common/range/to.sql

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ INSERT INTO TABLE host VALUES
1616

1717
SELECT ts, host, min(val) RANGE '1d' FROM host ALIGN '1d' ORDER BY host, ts;
1818

19-
SELECT ts, host, min(val) RANGE '1d' FROM host ALIGN '1d' TO CALENDAR ORDER BY host, ts;
20-
2119
SELECT ts, host, min(val) RANGE '1d' FROM host ALIGN '1d' TO UNKNOWN ORDER BY host, ts;
2220

2321
SELECT ts, host, min(val) RANGE '1d' FROM host ALIGN '1d' TO '1900-01-01T00:00:00+01:00' ORDER BY host, ts;

0 commit comments

Comments
 (0)