From 5f7b17eaa9ddaf8476087a1c675456e8704523bb Mon Sep 17 00:00:00 2001 From: Runji Wang Date: Tue, 12 Sep 2023 01:01:41 +0800 Subject: [PATCH] fix unit tests Signed-off-by: Runji Wang --- src/common/src/types/mod.rs | 4 +- src/expr/src/sig/mod.rs | 40 +++++++++++--------- src/frontend/src/expr/type_inference/func.rs | 2 +- 3 files changed, 26 insertions(+), 20 deletions(-) diff --git a/src/common/src/types/mod.rs b/src/common/src/types/mod.rs index 2943b7ff18bb9..2aca754b400f0 100644 --- a/src/common/src/types/mod.rs +++ b/src/common/src/types/mod.rs @@ -124,10 +124,10 @@ pub enum DataType { #[display("varchar")] #[from_str(regex = "(?i)^varchar$")] Varchar, - #[display("time without time zone")] + #[display("time")] #[from_str(regex = "(?i)^time$|^time without time zone$")] Time, - #[display("timestamp without time zone")] + #[display("timestamp")] #[from_str(regex = "(?i)^timestamp$|^timestamp without time zone$")] Timestamp, #[display("timestamp with time zone")] diff --git a/src/expr/src/sig/mod.rs b/src/expr/src/sig/mod.rs index f007943d991b0..40f935a87b3da 100644 --- a/src/expr/src/sig/mod.rs +++ b/src/expr/src/sig/mod.rs @@ -130,7 +130,15 @@ impl fmt::Debug for FuncSign { "{}({}{}) -> {}{}{}", self.name.as_str_name().to_ascii_lowercase(), self.inputs_type.iter().format(", "), - if self.variadic { " ..." } else { "" }, + if self.variadic { + if self.inputs_type.is_empty() { + "..." + } else { + ", ..." + } + } else { + "" + }, if self.name.is_table() { "setof " } else { "" }, self.ret_type, if self.deprecated { " [deprecated]" } else { "" }, @@ -319,7 +327,7 @@ impl SigDataType { pub fn as_exact(&self) -> &DataType { match self { Self::Exact(ty) => ty, - _ => panic!("Expected an exact type"), + t => panic!("expected data type, but got: {t}"), } } @@ -416,24 +424,22 @@ mod tests { // handle them specially without relying on FuncSigMap. let expected = expect_test::expect![[r#" [ - "to_timestamp1(varchar, varchar) -> timestamp/timestamptz", - "cast(boolean) -> int32/varchar", - "cast(int16) -> int256/decimal/float64/float32/int64/int32/varchar", - "cast(int32) -> int256/int16/decimal/float64/float32/int64/boolean/varchar", - "cast(int64) -> int256/int32/int16/decimal/float64/float32/varchar", - "cast(float32) -> decimal/int64/int32/int16/float64/varchar", - "cast(float64) -> decimal/float32/int64/int32/int16/varchar", - "cast(decimal) -> float64/float32/int64/int32/int16/varchar", + "cast(anyarray) -> varchar/anyarray", + "cast(bigint) -> rw_int256/integer/smallint/numeric/double precision/real/varchar", + "cast(boolean) -> integer/varchar", "cast(date) -> timestamp/varchar", - "cast(varchar) -> date/time/timestamp/jsonb/interval/int256/float32/float64/decimal/int16/int32/int64/varchar/boolean/bytea/list", + "cast(double precision) -> numeric/real/bigint/integer/smallint/varchar", + "cast(integer) -> rw_int256/smallint/numeric/double precision/real/bigint/boolean/varchar", + "cast(interval) -> time/varchar", + "cast(jsonb) -> boolean/double precision/real/numeric/bigint/integer/smallint/varchar", + "cast(numeric) -> double precision/real/bigint/integer/smallint/varchar", + "cast(real) -> numeric/bigint/integer/smallint/double precision/varchar", + "cast(rw_int256) -> double precision/varchar", + "cast(smallint) -> rw_int256/numeric/double precision/real/bigint/integer/varchar", "cast(time) -> interval/varchar", "cast(timestamp) -> date/time/varchar", - "cast(interval) -> time/varchar", - "cast(list) -> varchar/list", - "cast(jsonb) -> boolean/float64/float32/decimal/int64/int32/int16/varchar", - "cast(int256) -> float64/varchar", - "array_access(list, int32) -> boolean/int16/int32/int64/int256/float32/float64/decimal/serial/date/time/timestamp/timestamptz/interval/varchar/bytea/jsonb/list/struct", - "array_min(list) -> bytea/varchar/timestamptz/timestamp/time/date/int256/serial/decimal/float32/float64/int16/int32/int64", + "cast(varchar) -> date/time/timestamp/jsonb/interval/rw_int256/real/double precision/numeric/smallint/integer/bigint/varchar/boolean/bytea/anyarray", + "sum(bigint) -> numeric/bigint", ] "#]]; expected.assert_debug_eq(&duplicated); diff --git a/src/frontend/src/expr/type_inference/func.rs b/src/frontend/src/expr/type_inference/func.rs index e78963f79d343..637d34e0f1568 100644 --- a/src/frontend/src/expr/type_inference/func.rs +++ b/src/frontend/src/expr/type_inference/func.rs @@ -637,7 +637,7 @@ fn is_preferred(t: &SigDataType) -> bool { /// accept an actual argument. So we introduced `eq_ok` to control this behavior. fn implicit_ok(source: &DataType, target: &SigDataType, eq_ok: bool) -> bool { eq_ok && target.matches(source) - || cast_ok_base(source, target.as_exact(), CastContext::Implicit) + || target.is_exact() && cast_ok_base(source, target.as_exact(), CastContext::Implicit) } /// Find the top `candidates` that match `inputs` on most non-null positions. This covers Rule 2,