Skip to content

Commit

Permalink
Revert "feat(expr): add support for make_date/time/timestamp (#14827)"
Browse files Browse the repository at this point in the history
This reverts commit 82d1277.
  • Loading branch information
StrikeW committed Feb 4, 2024
1 parent 85fee60 commit a2255d4
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 246 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,20 @@ SELECT make_timestamptz(1973, 07, 15, 08, 15, 55.33);
query T
SELECT make_timestamptz(-1973, 07, 15, 08, 15, 55.33);
----
-1972-07-15 08:15:55.330+00:00
-1973-07-15 08:15:55.330+00:00

query error Invalid parameter year, month, day: invalid date: -3-2-29
SELECT make_timestamptz(-4, 02, 29, 08, 15, 55.33);

query T
SELECT make_timestamptz(-5, 02, 29, 08, 15, 55.33);
----
-0004-02-29 08:15:55.330+00:00

query error Invalid parameter sec: invalid sec: -55.33
query error Invalid parameter sec: invalid sec
SELECT make_timestamptz(1973, 07, 15, 08, 15, -55.33);

query error Invalid parameter hour, min, sec: invalid time: 8:-15:55.33
query error Invalid parameter hour, min, sec: invalid time
SELECT make_timestamptz(1973, 07, 15, 08, -15, 55.33);

query error Invalid parameter year, month, day: invalid date: 1973--7-15
query error Invalid parameter year, month, day: invalid date
SELECT make_timestamptz(1973, -07, 15, 08, 15, 55.33);

query error Invalid parameter year, month, day: invalid date: 1973-6-31
query error Invalid parameter year, month, day: invalid date
SELECT make_timestamptz(1973, 06, 31, 08, 15, 55.33);

query error Invalid parameter year, month, day: invalid date: 0-6-31
SELECT make_timestamptz(0, 06, 31, 08, 15, 55.33);

statement ok
set TimeZone to 'America/New_York';

Expand Down Expand Up @@ -99,62 +88,3 @@ SELECT make_timestamptz(2013, 7, 15, 8, 15, 23.5, 'America/New_York');

statement ok
set timezone to 'UTC';

query T
SELECT make_date(2024, 1, 26);
----
2024-01-26

query T
SELECT make_date(-2024, 1, 26);
----
2024-01-26 BC

query error Invalid parameter year, month, day: invalid date: -3-2-29
SELECT make_date(-4, 2, 29);

query T
SELECT make_date(-5, 2, 29);
----
0005-02-29 BC

query error Invalid parameter year, month, day: invalid date: 0-7-15
select make_date(0, 7, 15);

query error Invalid parameter year, month, day: invalid date: 2013-2-30
select make_date(2013, 2, 30);

query error Invalid parameter year, month, day: invalid date: 2013-13-1
select make_date(2013, 13, 1);

query error Invalid parameter year, month, day: invalid date: 2013-11--1
select make_date(2013, 11, -1);

query error Invalid parameter hour, min, sec: invalid time: 10:55:100.1
select make_time(10, 55, 100.1);

query T
SELECT make_time(14, 20, 26);
----
14:20:26

query error Invalid parameter hour, min, sec: invalid time: 24:0:2.1
select make_time(24, 0, 2.1);

query T
SELECT make_timestamp(2024, 1, 26, 14, 20, 26);
----
2024-01-26 14:20:26

query T
SELECT make_timestamp(-1973, 07, 15, 08, 15, 55.33);
----
-1972-07-15 08:15:55.330

query error Invalid parameter year, month, day: invalid date: -3-2-29
SELECT make_timestamp(-4, 02, 29, 08, 15, 55.33);

query T
SELECT make_timestamp(-5, 02, 29, 08, 15, 55.33);
----
-0004-02-29 08:15:55.330
5 changes: 1 addition & 4 deletions proto/expr.proto
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,10 @@ message ExprNode {
BITWISE_NOT = 34;
BITWISE_SHIFT_LEFT = 35;
BITWISE_SHIFT_RIGHT = 36;
// date/time functions
// date functions
EXTRACT = 101;
DATE_PART = 102;
TUMBLE_START = 103;
MAKE_DATE = 113;
MAKE_TIME = 114;
MAKE_TIMESTAMP = 115;
// From f64 to timestamp.
// e.g. `select to_timestamp(1672044740.0)`
TO_TIMESTAMP = 104;
Expand Down
160 changes: 0 additions & 160 deletions src/expr/impl/src/scalar/make_time.rs

This file was deleted.

82 changes: 82 additions & 0 deletions src/expr/impl/src/scalar/make_timestamptz.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
// Copyright 2024 RisingWave Labs
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

use chrono::{NaiveDate, NaiveDateTime, NaiveTime};
use risingwave_common::types::{FloatExt, Timestamp, Timestamptz, F64};
use risingwave_expr::expr_context::TIME_ZONE;
use risingwave_expr::{capture_context, function, ExprError, Result};

use crate::scalar::timestamptz::timestamp_at_time_zone;

// year int, month int, day int, hour int, min int, sec double precision
#[function("make_timestamptz(int4, int4, int4, int4, int4, float8) -> timestamptz")]
pub fn make_timestamptz(
year: i32,
month: i32,
day: i32,
hour: i32,
min: i32,
sec: F64,
) -> Result<Timestamptz> {
make_timestamptz_impl_captured(year, month, day, hour, min, sec)
}

// year int, month int, day int, hour int, min int, sec double precision, timezone text
#[function("make_timestamptz(int4, int4, int4, int4, int4, float8, varchar) -> timestamptz")]
pub fn make_timestamptz_with_time_zone(
year: i32,
month: i32,
day: i32,
hour: i32,
min: i32,
sec: F64,
time_zone: &str,
) -> Result<Timestamptz> {
make_timestamptz_impl(time_zone, year, month, day, hour, min, sec)
}

#[capture_context(TIME_ZONE)]
fn make_timestamptz_impl(
time_zone: &str,
year: i32,
month: i32,
day: i32,
hour: i32,
min: i32,
sec: F64,
) -> Result<Timestamptz> {
if !sec.is_finite() || sec.0.is_sign_negative() {
return Err(ExprError::InvalidParam {
name: "sec",
reason: "invalid sec".into(),
});
}
let sec_u32 = sec.0.trunc() as u32;
let microsecond_u32 = ((sec.0 - sec.0.trunc()) * 1_000_000.0).round_ties_even() as u32;
let naive_date_time = NaiveDateTime::new(
NaiveDate::from_ymd_opt(year, month as u32, day as u32).ok_or_else(|| {
ExprError::InvalidParam {
name: "year, month, day",
reason: "invalid date".into(),
}
})?,
NaiveTime::from_hms_micro_opt(hour as u32, min as u32, sec_u32, microsecond_u32)
.ok_or_else(|| ExprError::InvalidParam {
name: "hour, min, sec",
reason: "invalid time".into(),
})?,
);

timestamp_at_time_zone(Timestamp(naive_date_time), time_zone)
}
2 changes: 1 addition & 1 deletion src/expr/impl/src/scalar/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ mod jsonb_object;
mod jsonb_path;
mod length;
mod lower;
mod make_time;
mod make_timestamptz;
mod md5;
mod overlay;
mod position;
Expand Down
3 changes: 0 additions & 3 deletions src/frontend/src/binder/expr/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -820,9 +820,6 @@ impl Binder {
),
("date_trunc", raw_call(ExprType::DateTrunc)),
("date_part", raw_call(ExprType::DatePart)),
("make_date", raw_call(ExprType::MakeDate)),
("make_time", raw_call(ExprType::MakeTime)),
("make_timestamp", raw_call(ExprType::MakeTimestamp)),
("to_date", raw_call(ExprType::CharToDate)),
("make_timestamptz", raw_call(ExprType::MakeTimestamptz)),
// string
Expand Down
3 changes: 0 additions & 3 deletions src/frontend/src/expr/pure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,6 @@ impl ExprVisitor for ImpureAnalyzer {
| expr_node::Type::ToTimestamp
| expr_node::Type::AtTimeZone
| expr_node::Type::DateTrunc
| expr_node::Type::MakeDate
| expr_node::Type::MakeTime
| expr_node::Type::MakeTimestamp
| expr_node::Type::ToTimestamp1
| expr_node::Type::CharToDate
| expr_node::Type::CastWithTimeZone
Expand Down

0 comments on commit a2255d4

Please sign in to comment.