Skip to content

Commit

Permalink
chore: fix generate_series to_timestamp step unit bug (#13917)
Browse files Browse the repository at this point in the history
* chore: fix generate_series to_timestamp step unit bug

* chore: fix generate_series to_timestamp step unit bug

* chore: fix generate_series to_timestamp step unit bug
  • Loading branch information
lichuang authored Dec 6, 2023
1 parent a2c8a80 commit 551a577
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
19 changes: 16 additions & 3 deletions src/query/service/src/table_functions/srf/range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,22 @@ impl RangeTable {

let start = table_args.positioned[0].clone();
let end = table_args.positioned[1].clone();
let mut step = Scalar::Number(NumberScalar::Int64(1));
if table_args.positioned.len() == 3 {
step = table_args.positioned[2].clone();

let mut step = if table_args.positioned.len() == 3 {
table_args.positioned[2].clone()
} else {
Scalar::Number(NumberScalar::Int64(1))
};
if let Scalar::Timestamp(_) = start {
// since `to_timestamp` return value in micro seconds, we need to to change step as the same unit
let step_i64 = get_i64_number(&step)?;
if step_i64 < 1000 {
// treat step as seconds
step = Scalar::Number(NumberScalar::Int64(step_i64 * 1000000));
} else if step_i64 < 1000000 {
// treat step as mills seconds
step = Scalar::Number(NumberScalar::Int64(step_i64 * 1000));
}
}

let table_info = TableInfo {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,17 @@ select * from generate_series('2021-03-26 00:00'::timestamp,'2021-03-27 12:00'::
2021-03-26 00:00:00.000000
2021-03-27 00:00:00.000000

query T
select * from generate_series('1970-01-01 00:00'::timestamp,to_timestamp(2),2000000);
----
1970-01-01 00:00:00.000000
1970-01-01 00:00:02.000000

query T
select * from generate_series(to_timestamp(1),to_timestamp(2),2);
----
1970-01-01 00:00:01.000000

query T
select * from generate_series('2021-03-26'::date,'2021-03-27'::date,1);
----
Expand Down

0 comments on commit 551a577

Please sign in to comment.