Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
Signed-off-by: chagelo <[email protected]>
  • Loading branch information
chagelo committed Nov 22, 2024
1 parent 9526a27 commit f981424
Show file tree
Hide file tree
Showing 8 changed files with 196 additions and 198 deletions.
11 changes: 11 additions & 0 deletions e2e_test/batch/functions/at_time_zone.slt.part
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,14 @@ select local AT TIME ZONE tz from t order by 1;

statement ok
drop table t;

# timezone function
query T
select timezone('Europe/Moscow', '2014-10-25 22:00:00 UTC'::timestamptz);
----
2014-10-26 01:00:00

query T
select timezone('Europe/Moscow', '2011-03-26 23:00:00 UTC'::timestamptz);
----
2011-03-27 03:00:00
1 change: 0 additions & 1 deletion proto/expr.proto
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ message ExprNode {
ADD_WITH_TIME_ZONE = 109;
SUBTRACT_WITH_TIME_ZONE = 110;
MAKE_TIMESTAMPTZ = 112;
Timezone = 116;
// other functions
CAST = 201;
SUBSTR = 202;
Expand Down
16 changes: 0 additions & 16 deletions src/expr/impl/src/scalar/timestamptz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,16 +80,6 @@ pub fn timestamp_at_time_zone(input: Timestamp, time_zone: &str) -> Result<Times
Ok(Timestamptz::from_micros(usec))
}

#[function("timezone(varchar, timestamp) -> timestamptz")]
pub fn timezone_timestamp_at_time_zone(time_zone: &str, input: Timestamp) -> Result<Timestamptz> {
timestamp_at_time_zone(input, time_zone)
}

#[function("timezone(varchar, timestamptz) -> timestamp")]
pub fn timezone_timestamptz_at_time_zone(time_zone: &str, input: Timestamptz) -> Result<Timestamp> {
timestamptz_at_time_zone(input, time_zone)
}

#[function("cast_with_time_zone(timestamptz, varchar) -> varchar")]
pub fn timestamptz_to_string(
elem: Timestamptz,
Expand Down Expand Up @@ -238,12 +228,6 @@ mod tests {
.for_each(|(local, zone)| {
let local = local.parse().unwrap();

let actual = timezone_timestamptz_at_time_zone(zone, usecs).unwrap();
assert_eq!(local, actual);

let actual = timezone_timestamp_at_time_zone(zone, local).unwrap();
assert_eq!(Timestamp::from(usecs.to_datetime_utc().naive_utc()), actual);

let actual = timestamptz_at_time_zone(usecs, zone).unwrap();
assert_eq!(local, actual);

Expand Down
9 changes: 8 additions & 1 deletion src/frontend/src/binder/expr/function/builtin_scalar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,14 @@ impl Binder {
("make_time", raw_call(ExprType::MakeTime)),
("make_timestamp", raw_call(ExprType::MakeTimestamp)),
("make_timestamptz", raw_call(ExprType::MakeTimestamptz)),
("timezone", raw_call(ExprType::Timezone)),
("timezone", rewrite(ExprType::AtTimeZone, |mut inputs|{
if inputs.len() == 2 {
inputs.swap(0, 1);
Ok(inputs)
} else {
Err(ErrorCode::ExprError("unexpected arguments number".into()).into())
}
})),
("to_date", raw_call(ExprType::CharToDate)),
// string
("substr", raw_call(ExprType::Substr)),
Expand Down
1 change: 0 additions & 1 deletion src/frontend/src/expr/pure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ impl ExprVisitor for ImpureAnalyzer {
| Type::CastWithTimeZone
| Type::AddWithTimeZone
| Type::SubtractWithTimeZone
| Type::Timezone
| Type::Cast
| Type::Substr
| Type::Length
Expand Down
1 change: 0 additions & 1 deletion src/frontend/src/optimizer/plan_expr_visitor/strong.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,6 @@ impl Strong {
| ExprType::CastWithTimeZone
| ExprType::SubtractWithTimeZone
| ExprType::MakeTimestamptz
| ExprType::Timezone
| ExprType::Substr
| ExprType::Length
| ExprType::ILike
Expand Down
Loading

0 comments on commit f981424

Please sign in to comment.