Skip to content

Commit

Permalink
refactor: rename TO_TIMESTAMP{,1} in expr.proto for clarity (#15143)
Browse files Browse the repository at this point in the history
  • Loading branch information
xiangjinwu authored Feb 20, 2024
1 parent 97698a0 commit 2cb8c97
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 19 deletions.
4 changes: 2 additions & 2 deletions proto/expr.proto
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,12 @@ message ExprNode {
MAKE_TIMESTAMP = 115;
// From f64 to timestamp.
// e.g. `select to_timestamp(1672044740.0)`
TO_TIMESTAMP = 104;
SEC_TO_TIMESTAMPTZ = 104;
AT_TIME_ZONE = 105;
DATE_TRUNC = 106;
// Parse text to timestamp by format string.
// e.g. `select to_timestamp('2022 08 21', 'YYYY MM DD')`
TO_TIMESTAMP1 = 107;
CHAR_TO_TIMESTAMPTZ = 107;
CHAR_TO_DATE = 111;
// Performs a cast with additional timezone information.
CAST_WITH_TIME_ZONE = 108;
Expand Down
8 changes: 4 additions & 4 deletions src/expr/impl/benches/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ fn bench_expr(c: &mut Criterion) {
}
if [
"date_trunc(character varying, timestamp with time zone) -> timestamp with time zone",
"to_timestamp1(character varying, character varying) -> timestamp with time zone",
"char_to_timestamptz(character varying, character varying) -> timestamp with time zone",
"to_char(timestamp with time zone, character varying) -> character varying",
]
.contains(&format!("{sig:?}").as_str())
Expand All @@ -321,12 +321,12 @@ fn bench_expr(c: &mut Criterion) {
for (i, t) in sig.inputs_type.iter().enumerate() {
use DataType::*;
let idx = match (sig.name.as_scalar(), i) {
(PbType::ToTimestamp1, 0) => TIMESTAMP_FORMATTED_STRING,
(PbType::ToChar | PbType::ToTimestamp1, 1) => {
(PbType::CharToTimestamptz, 0) => TIMESTAMP_FORMATTED_STRING,
(PbType::ToChar | PbType::CharToTimestamptz, 1) => {
children.push(string_literal("YYYY/MM/DD HH:MM:SS"));
continue;
}
(PbType::ToChar | PbType::ToTimestamp1, 2) => {
(PbType::ToChar | PbType::CharToTimestamptz, 2) => {
children.push(string_literal("Australia/Sydney"));
continue;
}
Expand Down
2 changes: 1 addition & 1 deletion src/expr/impl/src/scalar/timestamptz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub fn time_zone_err(inner_err: String) -> ExprError {
}
}

#[function("to_timestamp(float8) -> timestamptz")]
#[function("sec_to_timestamptz(float8) -> timestamptz")]
pub fn f64_sec_to_timestamptz(elem: F64) -> Result<Timestamptz> {
// TODO(#4515): handle +/- infinity
let micros = (elem.0 * 1e6)
Expand Down
6 changes: 3 additions & 3 deletions src/expr/impl/src/scalar/to_timestamp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ fn parse(s: &str, tmpl: &ChronoPattern) -> Result<Parsed> {
}

#[function(
"to_timestamp1(varchar, varchar) -> timestamp",
"char_to_timestamptz(varchar, varchar) -> timestamp",
prebuild = "ChronoPattern::compile($1)",
deprecated
)]
Expand All @@ -81,7 +81,7 @@ pub fn to_timestamp_legacy(s: &str, tmpl: &ChronoPattern) -> Result<Timestamp> {
}

#[function(
"to_timestamp1(varchar, varchar, varchar) -> timestamptz",
"char_to_timestamptz(varchar, varchar, varchar) -> timestamptz",
prebuild = "ChronoPattern::compile($1)"
)]
pub fn to_timestamp(s: &str, timezone: &str, tmpl: &ChronoPattern) -> Result<Timestamptz> {
Expand All @@ -93,7 +93,7 @@ pub fn to_timestamp(s: &str, timezone: &str, tmpl: &ChronoPattern) -> Result<Tim
})
}

#[function("to_timestamp1(varchar, varchar) -> timestamptz", rewritten)]
#[function("char_to_timestamptz(varchar, varchar) -> timestamptz", rewritten)]
fn _to_timestamp1() {}

#[function(
Expand Down
4 changes: 2 additions & 2 deletions src/frontend/src/binder/expr/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -959,8 +959,8 @@ impl Binder {
(
"to_timestamp",
dispatch_by_len(vec![
(1, raw_call(ExprType::ToTimestamp)),
(2, raw_call(ExprType::ToTimestamp1)),
(1, raw_call(ExprType::SecToTimestamptz)),
(2, raw_call(ExprType::CharToTimestamptz)),
]),
),
("date_trunc", raw_call(ExprType::DateTrunc)),
Expand Down
4 changes: 2 additions & 2 deletions src/frontend/src/expr/pure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,13 @@ impl ExprVisitor for ImpureAnalyzer {
| expr_node::Type::Extract
| expr_node::Type::DatePart
| expr_node::Type::TumbleStart
| expr_node::Type::ToTimestamp
| expr_node::Type::SecToTimestamptz
| 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::CharToTimestamptz
| expr_node::Type::CharToDate
| expr_node::Type::CastWithTimeZone
| expr_node::Type::AddWithTimeZone
Expand Down
6 changes: 3 additions & 3 deletions src/frontend/src/expr/session_timezone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,9 +216,9 @@ impl SessionTimezone {
new_inputs.push(ExprImpl::literal_varchar(self.timezone()));
Some(FunctionCall::new(func_type, new_inputs).unwrap().into())
}
// `to_timestamp1(input_string, format_string)`
// => `to_timestamp1(input_string, format_string, zone_string)`
ExprType::ToTimestamp1 => {
// `char_to_timestamptz(input_string, format_string)`
// => `char_to_timestamptz(input_string, format_string, zone_string)`
ExprType::CharToTimestamptz => {
if !(inputs.len() == 2
&& inputs[0].return_type() == DataType::Varchar
&& inputs[1].return_type() == DataType::Varchar)
Expand Down
4 changes: 2 additions & 2 deletions src/frontend/src/expr/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -577,8 +577,8 @@ impl WatermarkAnalyzer {
},
_ => unreachable!(),
},
ExprType::ToTimestamp => self.visit_unary_op(func_call.inputs()),
ExprType::ToTimestamp1 => WatermarkDerivation::None,
ExprType::SecToTimestamptz => self.visit_unary_op(func_call.inputs()),
ExprType::CharToTimestamptz => WatermarkDerivation::None,
ExprType::Cast => {
// TODO: need more derivation
WatermarkDerivation::None
Expand Down

0 comments on commit 2cb8c97

Please sign in to comment.