Skip to content

Commit

Permalink
fix unit tests
Browse files Browse the repository at this point in the history
Signed-off-by: Runji Wang <[email protected]>
  • Loading branch information
wangrunji0408 committed Sep 11, 2023
1 parent ae58cd2 commit 5f7b17e
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 20 deletions.
4 changes: 2 additions & 2 deletions src/common/src/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down
40 changes: 23 additions & 17 deletions src/expr/src/sig/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 { "" },
Expand Down Expand Up @@ -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}"),
}
}

Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/frontend/src/expr/type_inference/func.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 5f7b17e

Please sign in to comment.