Skip to content

Commit

Permalink
feat(expr): allow explicit cast serial to bigint
Browse files Browse the repository at this point in the history
Signed-off-by: TennyZhuang <[email protected]>
  • Loading branch information
TennyZhuang committed Feb 21, 2024
1 parent 4197ad5 commit bf6cd7c
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 16 deletions.
6 changes: 6 additions & 0 deletions src/common/src/types/serial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ use crate::util::row_id::RowId;
#[derive(Debug, Copy, Clone, PartialEq, Eq, Ord, PartialOrd, Default, Hash)]
pub struct Serial(i64);

impl From<Serial> for i64 {
fn from(value: Serial) -> i64 {
value.0
}
}

impl From<i64> for Serial {
fn from(value: i64) -> Self {
Self(value)
Expand Down
1 change: 1 addition & 0 deletions src/expr/impl/src/scalar/cast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ pub fn jsonb_to_number<T: TryFrom<F64>>(v: JsonbRef<'_>) -> Result<T> {
#[function("cast(int4) -> int2")]
#[function("cast(int8) -> int2")]
#[function("cast(int8) -> int4")]
#[function("cast(serial) -> int8")]
#[function("cast(float4) -> int2")]
#[function("cast(float8) -> int2")]
#[function("cast(float4) -> int4")]
Expand Down
33 changes: 17 additions & 16 deletions src/frontend/src/expr/type_inference/cast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,22 +216,23 @@ pub static CAST_MAP: LazyLock<CastMap> = LazyLock::new(|| {
use DataTypeName::*;
const CAST_TABLE: &[(&str, DataTypeName)] = &[
// 123456789ABCDEF
(". e a", Boolean), // 0
(" .iiiiii a", Int16), // 1
("ea.iiiii a", Int32), // 2
(" aa.iiii a", Int64), // 3
(" aaa.ii a", Decimal), // 4
(" aaaa.i a", Float32), // 5
(" aaaaa. a", Float64), // 6
(" e. a", Int256), // 7
(" .ii a", Date), // 8
(" a.ia a", Timestamp), // 9
(" aa.a a", Timestamptz), // A
(" .i a", Time), // B
(" a. a", Interval), // C
("eeeeeee . a", Jsonb), // D
(" .a", Bytea), // E
("eeeeeeeeeeeeeee.", Varchar), // F
(". e a ", Boolean), // 0
(" .iiiiii a ", Int16), // 1
("ea.iiiii a ", Int32), // 2
(" aa.iiii a ", Int64), // 3
(" aaa.ii a ", Decimal), // 4
(" aaaa.i a ", Float32), // 5
(" aaaaa. a ", Float64), // 6
(" e. a ", Int256), // 7
(" .ii a ", Date), // 8
(" a.ia a ", Timestamp), // 9
(" aa.a a ", Timestamptz), // A
(" .i a ", Time), // B
(" a. a ", Interval), // C
("eeeeeee . a ", Jsonb), // D
(" .a ", Bytea), // E
("eeeeeeeeeeeeeee. ", Varchar), // F
(" e .", Serial),
];
let mut map = BTreeMap::new();
for (row, source) in CAST_TABLE {
Expand Down

0 comments on commit bf6cd7c

Please sign in to comment.