From 9886566793a22aa752b3fa0eef900c0b3ee2534d Mon Sep 17 00:00:00 2001 From: Shanicky Chen Date: Tue, 7 Mar 2023 16:51:05 +0800 Subject: [PATCH 1/8] Add support for DataType Serial --- proto/data.proto | 1 + src/common/src/hash/dispatcher.rs | 2 ++ src/common/src/types/mod.rs | 14 ++++++++++++++ src/common/src/types/postgres_type.rs | 3 +++ src/common/src/util/value_encoding/mod.rs | 5 +++-- src/connector/src/parser/common.rs | 1 + src/expr/src/expr/expr_binary_nullable.rs | 2 ++ src/expr/src/vector_op/cast.rs | 1 + src/frontend/src/expr/literal.rs | 1 + .../src/optimizer/rule/index_selection_rule.rs | 2 ++ src/tests/sqlsmith/src/sql_gen/types.rs | 1 + src/utils/pgwire/src/pg_extended.rs | 2 ++ 12 files changed, 33 insertions(+), 2 deletions(-) diff --git a/proto/data.proto b/proto/data.proto index 1544130320211..e2f58a7b2e20f 100644 --- a/proto/data.proto +++ b/proto/data.proto @@ -50,6 +50,7 @@ message DataType { LIST = 16; BYTEA = 17; JSONB = 18; + SERIAL = 19; } TypeName type_name = 1; // Data length for char. diff --git a/src/common/src/hash/dispatcher.rs b/src/common/src/hash/dispatcher.rs index f4eaba71da1ca..d104fa1b3ce1e 100644 --- a/src/common/src/hash/dispatcher.rs +++ b/src/common/src/hash/dispatcher.rs @@ -13,6 +13,7 @@ // limitations under the License. use super::HashKey; +use crate::array::serial_array::Serial; use crate::hash; use crate::types::DataType; @@ -90,6 +91,7 @@ fn hash_key_size(data_type: &DataType) -> HashKeySize { DataType::Int16 => HashKeySize::Fixed(size_of::()), DataType::Int32 => HashKeySize::Fixed(size_of::()), DataType::Int64 => HashKeySize::Fixed(size_of::()), + DataType::Serial => HashKeySize::Fixed(size_of::()), DataType::Float32 => HashKeySize::Fixed(size_of::()), DataType::Float64 => HashKeySize::Fixed(size_of::()), DataType::Decimal => HashKeySize::Fixed(size_of::()), diff --git a/src/common/src/types/mod.rs b/src/common/src/types/mod.rs index 8ba856d20f3ec..4c248474b866a 100644 --- a/src/common/src/types/mod.rs +++ b/src/common/src/types/mod.rs @@ -131,6 +131,9 @@ pub enum DataType { #[display("jsonb")] #[from_str(regex = "(?i)^jsonb$")] Jsonb, + #[display("serial")] + #[from_str(regex = "(?i)^serial$")] + Serial, } impl std::str::FromStr for Box { @@ -148,6 +151,7 @@ impl DataTypeName { | DataTypeName::Int16 | DataTypeName::Int32 | DataTypeName::Int64 + | DataTypeName::Serial | DataTypeName::Decimal | DataTypeName::Float32 | DataTypeName::Float64 @@ -170,6 +174,7 @@ impl DataTypeName { DataTypeName::Int16 => DataType::Int16, DataTypeName::Int32 => DataType::Int32, DataTypeName::Int64 => DataType::Int64, + DataTypeName::Serial => DataType::Serial, DataTypeName::Decimal => DataType::Decimal, DataTypeName::Float32 => DataType::Float32, DataTypeName::Float64 => DataType::Float64, @@ -208,6 +213,7 @@ impl From<&ProstDataType> for DataType { TypeName::Int16 => DataType::Int16, TypeName::Int32 => DataType::Int32, TypeName::Int64 => DataType::Int64, + TypeName::Serial => DataType::Serial, TypeName::Float => DataType::Float32, TypeName::Double => DataType::Float64, TypeName::Boolean => DataType::Boolean, @@ -242,6 +248,7 @@ impl DataType { DataType::Int16 => PrimitiveArrayBuilder::::new(capacity).into(), DataType::Int32 => PrimitiveArrayBuilder::::new(capacity).into(), DataType::Int64 => PrimitiveArrayBuilder::::new(capacity).into(), + DataType::Serial => PrimitiveArrayBuilder::::new(capacity).into(), DataType::Float32 => PrimitiveArrayBuilder::::new(capacity).into(), DataType::Float64 => PrimitiveArrayBuilder::::new(capacity).into(), DataType::Decimal => DecimalArrayBuilder::new(capacity).into(), @@ -271,6 +278,7 @@ impl DataType { DataType::Int16 => TypeName::Int16, DataType::Int32 => TypeName::Int32, DataType::Int64 => TypeName::Int64, + DataType::Serial => TypeName::Serial, DataType::Float32 => TypeName::Float, DataType::Float64 => TypeName::Double, DataType::Boolean => TypeName::Boolean, @@ -313,6 +321,7 @@ impl DataType { DataType::Int16 | DataType::Int32 | DataType::Int64 + | DataType::Serial | DataType::Float32 | DataType::Float64 | DataType::Decimal @@ -353,6 +362,7 @@ impl DataType { DataType::Int16 => ScalarImpl::Int16(i16::MIN), DataType::Int32 => ScalarImpl::Int32(i32::MIN), DataType::Int64 => ScalarImpl::Int64(i64::MIN), + DataType::Serial => ScalarImpl::Serial(Serial::from(i64::MIN)), DataType::Float32 => ScalarImpl::Float32(OrderedF32::neg_infinity()), DataType::Float64 => ScalarImpl::Float64(OrderedF64::neg_infinity()), DataType::Boolean => ScalarImpl::Bool(false), @@ -1050,6 +1060,7 @@ impl ScalarImpl { Ty::Int16 => Self::Int16(i16::deserialize(de)?), Ty::Int32 => Self::Int32(i32::deserialize(de)?), Ty::Int64 => Self::Int64(i64::deserialize(de)?), + Ty::Serial => todo!("SERIAL"), Ty::Float32 => Self::Float32(f32::deserialize(de)?.into()), Ty::Float64 => Self::Float64(f64::deserialize(de)?.into()), Ty::Varchar => Self::Utf8(Box::::deserialize(de)?), @@ -1100,6 +1111,7 @@ impl ScalarImpl { DataType::Int16 => size_of::(), DataType::Int32 => size_of::(), DataType::Int64 => size_of::(), + DataType::Serial => size_of::(), DataType::Float32 => size_of::(), DataType::Float64 => size_of::(), DataType::Date => size_of::(), @@ -1174,6 +1186,7 @@ macro_rules! for_all_type_pairs { { Interval, Interval }, { Decimal, Decimal }, { Jsonb, Jsonb }, + { Serial, Serial }, { List, List }, { Struct, Struct } } @@ -1360,6 +1373,7 @@ mod tests { DataTypeName::Int16 => (ScalarImpl::Int16(233), DataType::Int16), DataTypeName::Int32 => (ScalarImpl::Int32(233333), DataType::Int32), DataTypeName::Int64 => (ScalarImpl::Int64(233333333333), DataType::Int64), + DataTypeName::Serial => (ScalarImpl::Serial(233333333333.into()), DataType::Serial), DataTypeName::Float32 => (ScalarImpl::Float32(23.33.into()), DataType::Float32), DataTypeName::Float64 => ( ScalarImpl::Float64(23.333333333333.into()), diff --git a/src/common/src/types/postgres_type.rs b/src/common/src/types/postgres_type.rs index c520260ca91f8..b0716098a56ea 100644 --- a/src/common/src/types/postgres_type.rs +++ b/src/common/src/types/postgres_type.rs @@ -22,6 +22,7 @@ impl DataType { DataType::Boolean => 1, DataType::Int16 => 2, DataType::Int32 | DataType::Float32 | DataType::Date => 4, + DataType::Serial => todo!(), DataType::Int64 | DataType::Float64 | DataType::Timestamp @@ -114,6 +115,7 @@ impl DataType { DataType::Int16 => 21, DataType::Int32 => 23, DataType::Int64 => 20, + DataType::Serial => todo!("SERIAL"), DataType::Float32 => 700, DataType::Float64 => 701, DataType::Decimal => 1700, @@ -133,6 +135,7 @@ impl DataType { DataType::Int16 => 1005, DataType::Int32 => 1007, DataType::Int64 => 1016, + DataType::Serial => todo!("SERIAL"), DataType::Float32 => 1021, DataType::Float64 => 1022, DataType::Decimal => 1231, diff --git a/src/common/src/util/value_encoding/mod.rs b/src/common/src/util/value_encoding/mod.rs index c5e72b0d43f8c..07ff432c928cb 100644 --- a/src/common/src/util/value_encoding/mod.rs +++ b/src/common/src/util/value_encoding/mod.rs @@ -24,7 +24,7 @@ use either::{for_both, Either}; use enum_as_inner::EnumAsInner; use itertools::Itertools; -use crate::array::{JsonbVal, ListRef, ListValue, StructRef, StructValue}; +use crate::array::{serial_array, JsonbVal, ListRef, ListValue, StructRef, StructValue}; use crate::catalog::ColumnId; use crate::row::{Row, RowDeserializer as BasicDeserializer}; use crate::types::struct_type::StructType; @@ -35,8 +35,8 @@ use crate::types::{ pub mod error; use error::ValueEncodingError; - use self::column_aware_row_encoding::ColumnAwareSerde; +use serial_array::Serial; pub mod column_aware_row_encoding; pub type Result = std::result::Result; @@ -280,6 +280,7 @@ fn deserialize_value(ty: &DataType, data: &mut impl Buf) -> Result { DataType::Int16 => ScalarImpl::Int16(data.get_i16_le()), DataType::Int32 => ScalarImpl::Int32(data.get_i32_le()), DataType::Int64 => ScalarImpl::Int64(data.get_i64_le()), + DataType::Serial => ScalarImpl::Serial(Serial::from(data.get_i64_le())), DataType::Float32 => ScalarImpl::Float32(OrderedF32::from(data.get_f32_le())), DataType::Float64 => ScalarImpl::Float64(OrderedF64::from(data.get_f64_le())), DataType::Varchar => ScalarImpl::Utf8(deserialize_str(data)?), diff --git a/src/connector/src/parser/common.rs b/src/connector/src/parser/common.rs index 30c710744c267..9982b63fff965 100644 --- a/src/connector/src/parser/common.rs +++ b/src/connector/src/parser/common.rs @@ -43,6 +43,7 @@ fn do_parse_simd_json_value(dtype: &DataType, v: &BorrowedValue<'_>) -> Result ensure_i16!(v, i16).into(), DataType::Int32 => ensure_i32!(v, i32).into(), DataType::Int64 => ensure_i64!(v, i64).into(), + DataType::Serial => ensure_i64!(v, i64).into(), // when f32 overflows, the value is converted to `inf` which is inappropriate DataType::Float32 => { let scalar_val = ScalarImpl::Float32((simd_json_ensure_float!(v, f32) as f32).into()); diff --git a/src/expr/src/expr/expr_binary_nullable.rs b/src/expr/src/expr/expr_binary_nullable.rs index 6e3748f2d1852..9a17cbf4d7736 100644 --- a/src/expr/src/expr/expr_binary_nullable.rs +++ b/src/expr/src/expr/expr_binary_nullable.rs @@ -16,6 +16,7 @@ use std::sync::Arc; +use risingwave_common::array::serial_array::SerialArray; use risingwave_common::array::*; use risingwave_common::buffer::Bitmap; use risingwave_common::row::OwnedRow; @@ -201,6 +202,7 @@ fn build_array_access_expr( DataType::Int16 => array_access_expression!(I16Array), DataType::Int32 => array_access_expression!(I32Array), DataType::Int64 => array_access_expression!(I64Array), + DataType::Serial => array_access_expression!(SerialArray), DataType::Float32 => array_access_expression!(F32Array), DataType::Float64 => array_access_expression!(F64Array), DataType::Decimal => array_access_expression!(DecimalArray), diff --git a/src/expr/src/vector_op/cast.rs b/src/expr/src/vector_op/cast.rs index 26f955773efae..811aea438095f 100644 --- a/src/expr/src/vector_op/cast.rs +++ b/src/expr/src/vector_op/cast.rs @@ -449,6 +449,7 @@ pub fn literal_parsing( DataType::Int16 => str_parse::(s)?.into(), DataType::Int32 => str_parse::(s)?.into(), DataType::Int64 => str_parse::(s)?.into(), + DataType::Serial => str_parse::(s)?.into(), DataType::Decimal => str_parse::(s)?.into(), DataType::Float32 => str_parse::(s)?.into(), DataType::Float64 => str_parse::(s)?.into(), diff --git a/src/frontend/src/expr/literal.rs b/src/frontend/src/expr/literal.rs index d695805ad8287..716b1d096fdc4 100644 --- a/src/frontend/src/expr/literal.rs +++ b/src/frontend/src/expr/literal.rs @@ -42,6 +42,7 @@ impl std::fmt::Debug for Literal { DataType::Int16 | DataType::Int32 | DataType::Int64 + | DataType::Serial | DataType::Decimal | DataType::Float32 | DataType::Float64 => write!(f, "{}", v.as_scalar_ref_impl().to_text()), diff --git a/src/frontend/src/optimizer/rule/index_selection_rule.rs b/src/frontend/src/optimizer/rule/index_selection_rule.rs index a351c19343184..1fab6fd6fcf11 100644 --- a/src/frontend/src/optimizer/rule/index_selection_rule.rs +++ b/src/frontend/src/optimizer/rule/index_selection_rule.rs @@ -52,6 +52,7 @@ use std::collections::{BTreeMap, HashMap, HashSet}; use std::rc::Rc; use itertools::Itertools; +use risingwave_common::array::serial_array::Serial; use risingwave_common::catalog::Schema; use risingwave_common::types::{ DataType, Decimal, IntervalUnit, NaiveDateTimeWrapper, NaiveDateWrapper, NaiveTimeWrapper, @@ -713,6 +714,7 @@ impl<'a> TableScanIoEstimator<'a> { DataType::Int16 => size_of::(), DataType::Int32 => size_of::(), DataType::Int64 => size_of::(), + DataType::Serial => size_of::(), DataType::Float32 => size_of::(), DataType::Float64 => size_of::(), DataType::Decimal => size_of::(), diff --git a/src/tests/sqlsmith/src/sql_gen/types.rs b/src/tests/sqlsmith/src/sql_gen/types.rs index 9e9535f99b546..d02894904be5d 100644 --- a/src/tests/sqlsmith/src/sql_gen/types.rs +++ b/src/tests/sqlsmith/src/sql_gen/types.rs @@ -33,6 +33,7 @@ pub(super) fn data_type_to_ast_data_type(data_type: &DataType) -> AstDataType { DataType::Int16 => AstDataType::SmallInt, DataType::Int32 => AstDataType::Int, DataType::Int64 => AstDataType::BigInt, + DataType::Serial => AstDataType::Custom(vec!["SERIAL".into()].into()), DataType::Decimal => AstDataType::Decimal(None, None), DataType::Float32 => AstDataType::Real, DataType::Float64 => AstDataType::Double, diff --git a/src/utils/pgwire/src/pg_extended.rs b/src/utils/pgwire/src/pg_extended.rs index 6fb6aa4b24e87..7912db43bbfcd 100644 --- a/src/utils/pgwire/src/pg_extended.rs +++ b/src/utils/pgwire/src/pg_extended.rs @@ -415,6 +415,7 @@ impl PreparedStatement { }; format!("{}::INT8", tmp) } + DataType::Serial => todo!("SERIAL"), DataType::Int16 => { let tmp = match param_format { Format::Binary => { @@ -542,6 +543,7 @@ impl PreparedStatement { match oid { DataType::Boolean => params.push("false".to_string()), DataType::Int64 => params.push("0::BIGINT".to_string()), + DataType::Serial => todo!("SERIAL"), DataType::Int16 => params.push("0::SMALLINT".to_string()), DataType::Int32 => params.push("0::INT".to_string()), DataType::Float32 => params.push("0::FLOAT4".to_string()), From 6c97f369ac382874d51bac848fa11bb68c98d2f3 Mon Sep 17 00:00:00 2001 From: Shanicky Chen Date: Tue, 7 Mar 2023 18:10:52 +0800 Subject: [PATCH 2/8] Add SERIAL data type to DataType_TypeName list and update supporting functions. --- dashboard/proto/gen/data.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/dashboard/proto/gen/data.ts b/dashboard/proto/gen/data.ts index f6d42c26fa32d..d24bf8a9de15a 100644 --- a/dashboard/proto/gen/data.ts +++ b/dashboard/proto/gen/data.ts @@ -342,6 +342,7 @@ export const DataType_TypeName = { LIST: "LIST", BYTEA: "BYTEA", JSONB: "JSONB", + SERIAL: "SERIAL", UNRECOGNIZED: "UNRECOGNIZED", } as const; @@ -403,6 +404,9 @@ export function dataType_TypeNameFromJSON(object: any): DataType_TypeName { case 18: case "JSONB": return DataType_TypeName.JSONB; + case 19: + case "SERIAL": + return DataType_TypeName.SERIAL; case -1: case "UNRECOGNIZED": default: @@ -448,6 +452,8 @@ export function dataType_TypeNameToJSON(object: DataType_TypeName): string { return "BYTEA"; case DataType_TypeName.JSONB: return "JSONB"; + case DataType_TypeName.SERIAL: + return "SERIAL"; case DataType_TypeName.UNRECOGNIZED: default: return "UNRECOGNIZED"; From f7da63d05ba6ceb14a17682a2edab1d7ed8b610c Mon Sep 17 00:00:00 2001 From: Shanicky Chen Date: Fri, 10 Mar 2023 17:25:02 +0800 Subject: [PATCH 3/8] Add `Serial` support to `ScalarImpl` and modify `from_sql` and `from_str`. --- src/common/src/types/mod.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/common/src/types/mod.rs b/src/common/src/types/mod.rs index 4c248474b866a..141c626c0a357 100644 --- a/src/common/src/types/mod.rs +++ b/src/common/src/types/mod.rs @@ -790,6 +790,10 @@ impl ScalarImpl { i64::from_sql(&Type::INT8, bytes) .map_err(|err| ErrorCode::InvalidInputSyntax(err.to_string()))?, ), + DataType::Serial => Self::Serial(Serial::from( + i64::from_sql(&Type::INT8, bytes) + .map_err(|err| ErrorCode::InvalidInputSyntax(err.to_string()))?, + )), DataType::Float32 => Self::Float32( f32::from_sql(&Type::FLOAT4, bytes) .map_err(|err| ErrorCode::InvalidInputSyntax(err.to_string()))? @@ -872,6 +876,9 @@ impl ScalarImpl { DataType::Int64 => Self::Int64(i64::from_str(str).map_err(|_| { ErrorCode::InvalidInputSyntax(format!("Invalid param string: {}", str)) })?), + DataType::Serial => Self::Serial(Serial::from(i64::from_str(str).map_err(|_| { + ErrorCode::InvalidInputSyntax(format!("Invalid param string: {}", str)) + })?)), DataType::Float32 => Self::Float32( f32::from_str(str) .map_err(|_| { From 5208e2de09fc42df81ac0ea69e5e61929b699c06 Mon Sep 17 00:00:00 2001 From: Shanicky Chen Date: Fri, 10 Mar 2023 17:32:27 +0800 Subject: [PATCH 4/8] Update postgres_type.rs for DataType enum --- src/common/src/types/postgres_type.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/common/src/types/postgres_type.rs b/src/common/src/types/postgres_type.rs index b0716098a56ea..661b7d1645d21 100644 --- a/src/common/src/types/postgres_type.rs +++ b/src/common/src/types/postgres_type.rs @@ -22,8 +22,8 @@ impl DataType { DataType::Boolean => 1, DataType::Int16 => 2, DataType::Int32 | DataType::Float32 | DataType::Date => 4, - DataType::Serial => todo!(), DataType::Int64 + | DataType::Serial | DataType::Float64 | DataType::Timestamp | DataType::Timestamptz @@ -115,7 +115,7 @@ impl DataType { DataType::Int16 => 21, DataType::Int32 => 23, DataType::Int64 => 20, - DataType::Serial => todo!("SERIAL"), + DataType::Serial => 20, DataType::Float32 => 700, DataType::Float64 => 701, DataType::Decimal => 1700, @@ -135,7 +135,7 @@ impl DataType { DataType::Int16 => 1005, DataType::Int32 => 1007, DataType::Int64 => 1016, - DataType::Serial => todo!("SERIAL"), + DataType::Serial => 1016, DataType::Float32 => 1021, DataType::Float64 => 1022, DataType::Decimal => 1231, From ff4e08076949bb8272c323dad71a783b24114b63 Mon Sep 17 00:00:00 2001 From: Shanicky Chen Date: Mon, 13 Mar 2023 15:02:39 +0800 Subject: [PATCH 5/8] Add implementation for Ty::Serial and update PreparedStatement. --- src/common/src/types/mod.rs | 2 +- src/utils/pgwire/src/pg_extended.rs | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/common/src/types/mod.rs b/src/common/src/types/mod.rs index 141c626c0a357..06aee7955bb3d 100644 --- a/src/common/src/types/mod.rs +++ b/src/common/src/types/mod.rs @@ -1067,7 +1067,7 @@ impl ScalarImpl { Ty::Int16 => Self::Int16(i16::deserialize(de)?), Ty::Int32 => Self::Int32(i32::deserialize(de)?), Ty::Int64 => Self::Int64(i64::deserialize(de)?), - Ty::Serial => todo!("SERIAL"), + Ty::Serial => Self::Serial(Serial::from(i64::deserialize(de)?)), Ty::Float32 => Self::Float32(f32::deserialize(de)?.into()), Ty::Float64 => Self::Float64(f64::deserialize(de)?.into()), Ty::Varchar => Self::Utf8(Box::::deserialize(de)?), diff --git a/src/utils/pgwire/src/pg_extended.rs b/src/utils/pgwire/src/pg_extended.rs index 7912db43bbfcd..0347d69a6d81c 100644 --- a/src/utils/pgwire/src/pg_extended.rs +++ b/src/utils/pgwire/src/pg_extended.rs @@ -406,7 +406,7 @@ impl PreparedStatement { .to_string(), Format::Text => cstr_to_str(raw_param).unwrap().to_string(), }, - DataType::Int64 => { + DataType::Int64 | DataType::Serial => { let tmp = match param_format { Format::Binary => { i64::from_sql(&place_hodler, raw_param).unwrap().to_string() @@ -415,7 +415,6 @@ impl PreparedStatement { }; format!("{}::INT8", tmp) } - DataType::Serial => todo!("SERIAL"), DataType::Int16 => { let tmp = match param_format { Format::Binary => { @@ -543,7 +542,7 @@ impl PreparedStatement { match oid { DataType::Boolean => params.push("false".to_string()), DataType::Int64 => params.push("0::BIGINT".to_string()), - DataType::Serial => todo!("SERIAL"), + DataType::Serial => params.push("0::BIGINT".to_string()), DataType::Int16 => params.push("0::SMALLINT".to_string()), DataType::Int32 => params.push("0::INT".to_string()), DataType::Float32 => params.push("0::FLOAT4".to_string()), From c06b9b0a8d5d34d0367e68b3a88536ca5947aab5 Mon Sep 17 00:00:00 2001 From: Shanicky Chen Date: Mon, 13 Mar 2023 15:08:27 +0800 Subject: [PATCH 6/8] Import serial module, reorder statements, modify Result type definition --- src/common/src/util/value_encoding/mod.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/common/src/util/value_encoding/mod.rs b/src/common/src/util/value_encoding/mod.rs index 07ff432c928cb..b5a0cdb8494eb 100644 --- a/src/common/src/util/value_encoding/mod.rs +++ b/src/common/src/util/value_encoding/mod.rs @@ -35,8 +35,9 @@ use crate::types::{ pub mod error; use error::ValueEncodingError; -use self::column_aware_row_encoding::ColumnAwareSerde; use serial_array::Serial; + +use self::column_aware_row_encoding::ColumnAwareSerde; pub mod column_aware_row_encoding; pub type Result = std::result::Result; From 09409ba5fa2b760723ac7f1895667c482db0c275 Mon Sep 17 00:00:00 2001 From: Shanicky Chen Date: Tue, 14 Mar 2023 14:24:12 +0800 Subject: [PATCH 7/8] Update handling of "serial" type: treat as error, don't generate, and produce error when used as param. --- src/connector/src/parser/common.rs | 2 +- src/expr/src/vector_op/cast.rs | 2 +- src/tests/sqlsmith/src/sql_gen/types.rs | 2 +- src/utils/pgwire/src/pg_extended.rs | 7 +++---- 4 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/connector/src/parser/common.rs b/src/connector/src/parser/common.rs index 9982b63fff965..4bf7d543aa6d7 100644 --- a/src/connector/src/parser/common.rs +++ b/src/connector/src/parser/common.rs @@ -43,7 +43,7 @@ fn do_parse_simd_json_value(dtype: &DataType, v: &BorrowedValue<'_>) -> Result ensure_i16!(v, i16).into(), DataType::Int32 => ensure_i32!(v, i32).into(), DataType::Int64 => ensure_i64!(v, i64).into(), - DataType::Serial => ensure_i64!(v, i64).into(), + DataType::Serial => anyhow::bail!("serial should not be parsed"), // when f32 overflows, the value is converted to `inf` which is inappropriate DataType::Float32 => { let scalar_val = ScalarImpl::Float32((simd_json_ensure_float!(v, f32) as f32).into()); diff --git a/src/expr/src/vector_op/cast.rs b/src/expr/src/vector_op/cast.rs index 811aea438095f..4681de4136f11 100644 --- a/src/expr/src/vector_op/cast.rs +++ b/src/expr/src/vector_op/cast.rs @@ -449,7 +449,7 @@ pub fn literal_parsing( DataType::Int16 => str_parse::(s)?.into(), DataType::Int32 => str_parse::(s)?.into(), DataType::Int64 => str_parse::(s)?.into(), - DataType::Serial => str_parse::(s)?.into(), + DataType::Serial => return Err(None), DataType::Decimal => str_parse::(s)?.into(), DataType::Float32 => str_parse::(s)?.into(), DataType::Float64 => str_parse::(s)?.into(), diff --git a/src/tests/sqlsmith/src/sql_gen/types.rs b/src/tests/sqlsmith/src/sql_gen/types.rs index d02894904be5d..561b38d5c26ae 100644 --- a/src/tests/sqlsmith/src/sql_gen/types.rs +++ b/src/tests/sqlsmith/src/sql_gen/types.rs @@ -33,7 +33,7 @@ pub(super) fn data_type_to_ast_data_type(data_type: &DataType) -> AstDataType { DataType::Int16 => AstDataType::SmallInt, DataType::Int32 => AstDataType::Int, DataType::Int64 => AstDataType::BigInt, - DataType::Serial => AstDataType::Custom(vec!["SERIAL".into()].into()), + DataType::Serial => unreachable!("serial should not be generated"), DataType::Decimal => AstDataType::Decimal(None, None), DataType::Float32 => AstDataType::Real, DataType::Float64 => AstDataType::Double, diff --git a/src/utils/pgwire/src/pg_extended.rs b/src/utils/pgwire/src/pg_extended.rs index 0347d69a6d81c..32471659ff9f4 100644 --- a/src/utils/pgwire/src/pg_extended.rs +++ b/src/utils/pgwire/src/pg_extended.rs @@ -406,7 +406,7 @@ impl PreparedStatement { .to_string(), Format::Text => cstr_to_str(raw_param).unwrap().to_string(), }, - DataType::Int64 | DataType::Serial => { + DataType::Int64 => { let tmp = match param_format { Format::Binary => { i64::from_sql(&place_hodler, raw_param).unwrap().to_string() @@ -521,7 +521,7 @@ impl PreparedStatement { }; format!("'{}'::JSONB", tmp) } - DataType::Struct(_) | DataType::List { .. } => { + DataType::Serial | DataType::Struct(_) | DataType::List { .. } => { return Err(PsqlError::Internal(anyhow!( "Unsupported param type {:?}", type_oid @@ -542,7 +542,6 @@ impl PreparedStatement { match oid { DataType::Boolean => params.push("false".to_string()), DataType::Int64 => params.push("0::BIGINT".to_string()), - DataType::Serial => params.push("0::BIGINT".to_string()), DataType::Int16 => params.push("0::SMALLINT".to_string()), DataType::Int32 => params.push("0::INT".to_string()), DataType::Float32 => params.push("0::FLOAT4".to_string()), @@ -558,7 +557,7 @@ impl PreparedStatement { } DataType::Interval => params.push("'2 months ago'::interval".to_string()), DataType::Jsonb => params.push("'null'::JSONB".to_string()), - DataType::Struct(_) | DataType::List { .. } => { + DataType::Serial | DataType::Struct(_) | DataType::List { .. } => { return Err(PsqlError::Internal(anyhow!( "Unsupported param type {:?}", oid From 052f06669f3ce656a5e8b839712434ee15661928 Mon Sep 17 00:00:00 2001 From: Shanicky Chen Date: Tue, 14 Mar 2023 14:55:22 +0800 Subject: [PATCH 8/8] Add error for unsupported serial column type. --- src/frontend/src/binder/expr/mod.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/frontend/src/binder/expr/mod.rs b/src/frontend/src/binder/expr/mod.rs index 2f315f6491673..8a3018d2c2b3c 100644 --- a/src/frontend/src/binder/expr/mod.rs +++ b/src/frontend/src/binder/expr/mod.rs @@ -512,6 +512,13 @@ pub fn bind_data_type(data_type: &AstDataType) -> Result { "float8" => DataType::Float64, "timestamptz" => DataType::Timestamptz, "jsonb" => DataType::Jsonb, + "serial" => { + return Err(ErrorCode::NotSupported( + "Column type SERIAL is not supported".into(), + "Please remove the SERIAL column".into(), + ) + .into()) + } _ => return Err(new_err().into()), } }