Skip to content

Commit 61191c2

Browse files
authored
feat(common): Add support for DataType::Serial (risingwavelabs#8392)
1 parent f907452 commit 61191c2

File tree

14 files changed

+53
-3
lines changed

14 files changed

+53
-3
lines changed

dashboard/proto/gen/data.ts

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

proto/data.proto

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ message DataType {
5050
LIST = 16;
5151
BYTEA = 17;
5252
JSONB = 18;
53+
SERIAL = 19;
5354
}
5455
TypeName type_name = 1;
5556
// Data length for char.

src/common/src/hash/dispatcher.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
// limitations under the License.
1414

1515
use super::HashKey;
16+
use crate::array::serial_array::Serial;
1617
use crate::hash;
1718
use crate::types::DataType;
1819

@@ -90,6 +91,7 @@ fn hash_key_size(data_type: &DataType) -> HashKeySize {
9091
DataType::Int16 => HashKeySize::Fixed(size_of::<i16>()),
9192
DataType::Int32 => HashKeySize::Fixed(size_of::<i32>()),
9293
DataType::Int64 => HashKeySize::Fixed(size_of::<i64>()),
94+
DataType::Serial => HashKeySize::Fixed(size_of::<Serial>()),
9395
DataType::Float32 => HashKeySize::Fixed(size_of::<OrderedF32>()),
9496
DataType::Float64 => HashKeySize::Fixed(size_of::<OrderedF64>()),
9597
DataType::Decimal => HashKeySize::Fixed(size_of::<Decimal>()),

src/common/src/types/mod.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,9 @@ pub enum DataType {
131131
#[display("jsonb")]
132132
#[from_str(regex = "(?i)^jsonb$")]
133133
Jsonb,
134+
#[display("serial")]
135+
#[from_str(regex = "(?i)^serial$")]
136+
Serial,
134137
}
135138

136139
impl std::str::FromStr for Box<DataType> {
@@ -148,6 +151,7 @@ impl DataTypeName {
148151
| DataTypeName::Int16
149152
| DataTypeName::Int32
150153
| DataTypeName::Int64
154+
| DataTypeName::Serial
151155
| DataTypeName::Decimal
152156
| DataTypeName::Float32
153157
| DataTypeName::Float64
@@ -170,6 +174,7 @@ impl DataTypeName {
170174
DataTypeName::Int16 => DataType::Int16,
171175
DataTypeName::Int32 => DataType::Int32,
172176
DataTypeName::Int64 => DataType::Int64,
177+
DataTypeName::Serial => DataType::Serial,
173178
DataTypeName::Decimal => DataType::Decimal,
174179
DataTypeName::Float32 => DataType::Float32,
175180
DataTypeName::Float64 => DataType::Float64,
@@ -208,6 +213,7 @@ impl From<&ProstDataType> for DataType {
208213
TypeName::Int16 => DataType::Int16,
209214
TypeName::Int32 => DataType::Int32,
210215
TypeName::Int64 => DataType::Int64,
216+
TypeName::Serial => DataType::Serial,
211217
TypeName::Float => DataType::Float32,
212218
TypeName::Double => DataType::Float64,
213219
TypeName::Boolean => DataType::Boolean,
@@ -242,6 +248,7 @@ impl DataType {
242248
DataType::Int16 => PrimitiveArrayBuilder::<i16>::new(capacity).into(),
243249
DataType::Int32 => PrimitiveArrayBuilder::<i32>::new(capacity).into(),
244250
DataType::Int64 => PrimitiveArrayBuilder::<i64>::new(capacity).into(),
251+
DataType::Serial => PrimitiveArrayBuilder::<Serial>::new(capacity).into(),
245252
DataType::Float32 => PrimitiveArrayBuilder::<OrderedF32>::new(capacity).into(),
246253
DataType::Float64 => PrimitiveArrayBuilder::<OrderedF64>::new(capacity).into(),
247254
DataType::Decimal => DecimalArrayBuilder::new(capacity).into(),
@@ -271,6 +278,7 @@ impl DataType {
271278
DataType::Int16 => TypeName::Int16,
272279
DataType::Int32 => TypeName::Int32,
273280
DataType::Int64 => TypeName::Int64,
281+
DataType::Serial => TypeName::Serial,
274282
DataType::Float32 => TypeName::Float,
275283
DataType::Float64 => TypeName::Double,
276284
DataType::Boolean => TypeName::Boolean,
@@ -313,6 +321,7 @@ impl DataType {
313321
DataType::Int16
314322
| DataType::Int32
315323
| DataType::Int64
324+
| DataType::Serial
316325
| DataType::Float32
317326
| DataType::Float64
318327
| DataType::Decimal
@@ -353,6 +362,7 @@ impl DataType {
353362
DataType::Int16 => ScalarImpl::Int16(i16::MIN),
354363
DataType::Int32 => ScalarImpl::Int32(i32::MIN),
355364
DataType::Int64 => ScalarImpl::Int64(i64::MIN),
365+
DataType::Serial => ScalarImpl::Serial(Serial::from(i64::MIN)),
356366
DataType::Float32 => ScalarImpl::Float32(OrderedF32::neg_infinity()),
357367
DataType::Float64 => ScalarImpl::Float64(OrderedF64::neg_infinity()),
358368
DataType::Boolean => ScalarImpl::Bool(false),
@@ -780,6 +790,10 @@ impl ScalarImpl {
780790
i64::from_sql(&Type::INT8, bytes)
781791
.map_err(|err| ErrorCode::InvalidInputSyntax(err.to_string()))?,
782792
),
793+
DataType::Serial => Self::Serial(Serial::from(
794+
i64::from_sql(&Type::INT8, bytes)
795+
.map_err(|err| ErrorCode::InvalidInputSyntax(err.to_string()))?,
796+
)),
783797
DataType::Float32 => Self::Float32(
784798
f32::from_sql(&Type::FLOAT4, bytes)
785799
.map_err(|err| ErrorCode::InvalidInputSyntax(err.to_string()))?
@@ -862,6 +876,9 @@ impl ScalarImpl {
862876
DataType::Int64 => Self::Int64(i64::from_str(str).map_err(|_| {
863877
ErrorCode::InvalidInputSyntax(format!("Invalid param string: {}", str))
864878
})?),
879+
DataType::Serial => Self::Serial(Serial::from(i64::from_str(str).map_err(|_| {
880+
ErrorCode::InvalidInputSyntax(format!("Invalid param string: {}", str))
881+
})?)),
865882
DataType::Float32 => Self::Float32(
866883
f32::from_str(str)
867884
.map_err(|_| {
@@ -1050,6 +1067,7 @@ impl ScalarImpl {
10501067
Ty::Int16 => Self::Int16(i16::deserialize(de)?),
10511068
Ty::Int32 => Self::Int32(i32::deserialize(de)?),
10521069
Ty::Int64 => Self::Int64(i64::deserialize(de)?),
1070+
Ty::Serial => Self::Serial(Serial::from(i64::deserialize(de)?)),
10531071
Ty::Float32 => Self::Float32(f32::deserialize(de)?.into()),
10541072
Ty::Float64 => Self::Float64(f64::deserialize(de)?.into()),
10551073
Ty::Varchar => Self::Utf8(Box::<str>::deserialize(de)?),
@@ -1100,6 +1118,7 @@ impl ScalarImpl {
11001118
DataType::Int16 => size_of::<i16>(),
11011119
DataType::Int32 => size_of::<i32>(),
11021120
DataType::Int64 => size_of::<i64>(),
1121+
DataType::Serial => size_of::<Serial>(),
11031122
DataType::Float32 => size_of::<OrderedF32>(),
11041123
DataType::Float64 => size_of::<OrderedF64>(),
11051124
DataType::Date => size_of::<NaiveDateWrapper>(),
@@ -1174,6 +1193,7 @@ macro_rules! for_all_type_pairs {
11741193
{ Interval, Interval },
11751194
{ Decimal, Decimal },
11761195
{ Jsonb, Jsonb },
1196+
{ Serial, Serial },
11771197
{ List, List },
11781198
{ Struct, Struct }
11791199
}
@@ -1360,6 +1380,7 @@ mod tests {
13601380
DataTypeName::Int16 => (ScalarImpl::Int16(233), DataType::Int16),
13611381
DataTypeName::Int32 => (ScalarImpl::Int32(233333), DataType::Int32),
13621382
DataTypeName::Int64 => (ScalarImpl::Int64(233333333333), DataType::Int64),
1383+
DataTypeName::Serial => (ScalarImpl::Serial(233333333333.into()), DataType::Serial),
13631384
DataTypeName::Float32 => (ScalarImpl::Float32(23.33.into()), DataType::Float32),
13641385
DataTypeName::Float64 => (
13651386
ScalarImpl::Float64(23.333333333333.into()),

src/common/src/types/postgres_type.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ impl DataType {
2323
DataType::Int16 => 2,
2424
DataType::Int32 | DataType::Float32 | DataType::Date => 4,
2525
DataType::Int64
26+
| DataType::Serial
2627
| DataType::Float64
2728
| DataType::Timestamp
2829
| DataType::Timestamptz
@@ -114,6 +115,7 @@ impl DataType {
114115
DataType::Int16 => 21,
115116
DataType::Int32 => 23,
116117
DataType::Int64 => 20,
118+
DataType::Serial => 20,
117119
DataType::Float32 => 700,
118120
DataType::Float64 => 701,
119121
DataType::Decimal => 1700,
@@ -133,6 +135,7 @@ impl DataType {
133135
DataType::Int16 => 1005,
134136
DataType::Int32 => 1007,
135137
DataType::Int64 => 1016,
138+
DataType::Serial => 1016,
136139
DataType::Float32 => 1021,
137140
DataType::Float64 => 1022,
138141
DataType::Decimal => 1231,

src/common/src/util/value_encoding/mod.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use either::{for_both, Either};
2424
use enum_as_inner::EnumAsInner;
2525
use itertools::Itertools;
2626

27-
use crate::array::{JsonbVal, ListRef, ListValue, StructRef, StructValue};
27+
use crate::array::{serial_array, JsonbVal, ListRef, ListValue, StructRef, StructValue};
2828
use crate::catalog::ColumnId;
2929
use crate::row::{Row, RowDeserializer as BasicDeserializer};
3030
use crate::types::struct_type::StructType;
@@ -35,6 +35,7 @@ use crate::types::{
3535

3636
pub mod error;
3737
use error::ValueEncodingError;
38+
use serial_array::Serial;
3839

3940
use self::column_aware_row_encoding::ColumnAwareSerde;
4041
pub mod column_aware_row_encoding;
@@ -280,6 +281,7 @@ fn deserialize_value(ty: &DataType, data: &mut impl Buf) -> Result<ScalarImpl> {
280281
DataType::Int16 => ScalarImpl::Int16(data.get_i16_le()),
281282
DataType::Int32 => ScalarImpl::Int32(data.get_i32_le()),
282283
DataType::Int64 => ScalarImpl::Int64(data.get_i64_le()),
284+
DataType::Serial => ScalarImpl::Serial(Serial::from(data.get_i64_le())),
283285
DataType::Float32 => ScalarImpl::Float32(OrderedF32::from(data.get_f32_le())),
284286
DataType::Float64 => ScalarImpl::Float64(OrderedF64::from(data.get_f64_le())),
285287
DataType::Varchar => ScalarImpl::Utf8(deserialize_str(data)?),

src/connector/src/parser/common.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ fn do_parse_simd_json_value(dtype: &DataType, v: &BorrowedValue<'_>) -> Result<S
4343
DataType::Int16 => ensure_i16!(v, i16).into(),
4444
DataType::Int32 => ensure_i32!(v, i32).into(),
4545
DataType::Int64 => ensure_i64!(v, i64).into(),
46+
DataType::Serial => anyhow::bail!("serial should not be parsed"),
4647
// when f32 overflows, the value is converted to `inf` which is inappropriate
4748
DataType::Float32 => {
4849
let scalar_val = ScalarImpl::Float32((simd_json_ensure_float!(v, f32) as f32).into());

src/expr/src/expr/expr_binary_nullable.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
1717
use std::sync::Arc;
1818

19+
use risingwave_common::array::serial_array::SerialArray;
1920
use risingwave_common::array::*;
2021
use risingwave_common::buffer::Bitmap;
2122
use risingwave_common::row::OwnedRow;
@@ -201,6 +202,7 @@ fn build_array_access_expr(
201202
DataType::Int16 => array_access_expression!(I16Array),
202203
DataType::Int32 => array_access_expression!(I32Array),
203204
DataType::Int64 => array_access_expression!(I64Array),
205+
DataType::Serial => array_access_expression!(SerialArray),
204206
DataType::Float32 => array_access_expression!(F32Array),
205207
DataType::Float64 => array_access_expression!(F64Array),
206208
DataType::Decimal => array_access_expression!(DecimalArray),

src/expr/src/vector_op/cast.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,7 @@ pub fn literal_parsing(
449449
DataType::Int16 => str_parse::<i16>(s)?.into(),
450450
DataType::Int32 => str_parse::<i32>(s)?.into(),
451451
DataType::Int64 => str_parse::<i64>(s)?.into(),
452+
DataType::Serial => return Err(None),
452453
DataType::Decimal => str_parse::<Decimal>(s)?.into(),
453454
DataType::Float32 => str_parse::<OrderedF32>(s)?.into(),
454455
DataType::Float64 => str_parse::<OrderedF64>(s)?.into(),

src/frontend/src/binder/expr/mod.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,13 @@ pub fn bind_data_type(data_type: &AstDataType) -> Result<DataType> {
517517
"float8" => DataType::Float64,
518518
"timestamptz" => DataType::Timestamptz,
519519
"jsonb" => DataType::Jsonb,
520+
"serial" => {
521+
return Err(ErrorCode::NotSupported(
522+
"Column type SERIAL is not supported".into(),
523+
"Please remove the SERIAL column".into(),
524+
)
525+
.into())
526+
}
520527
_ => return Err(new_err().into()),
521528
}
522529
}

src/frontend/src/expr/literal.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ impl std::fmt::Debug for Literal {
4242
DataType::Int16
4343
| DataType::Int32
4444
| DataType::Int64
45+
| DataType::Serial
4546
| DataType::Decimal
4647
| DataType::Float32
4748
| DataType::Float64 => write!(f, "{}", v.as_scalar_ref_impl().to_text()),

src/frontend/src/optimizer/rule/index_selection_rule.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ use std::collections::{BTreeMap, HashMap, HashSet};
5252
use std::rc::Rc;
5353

5454
use itertools::Itertools;
55+
use risingwave_common::array::serial_array::Serial;
5556
use risingwave_common::catalog::Schema;
5657
use risingwave_common::types::{
5758
DataType, Decimal, IntervalUnit, NaiveDateTimeWrapper, NaiveDateWrapper, NaiveTimeWrapper,
@@ -704,6 +705,7 @@ impl<'a> TableScanIoEstimator<'a> {
704705
DataType::Int16 => size_of::<i16>(),
705706
DataType::Int32 => size_of::<i32>(),
706707
DataType::Int64 => size_of::<i64>(),
708+
DataType::Serial => size_of::<Serial>(),
707709
DataType::Float32 => size_of::<f32>(),
708710
DataType::Float64 => size_of::<f64>(),
709711
DataType::Decimal => size_of::<Decimal>(),

src/tests/sqlsmith/src/sql_gen/types.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ pub(super) fn data_type_to_ast_data_type(data_type: &DataType) -> AstDataType {
3333
DataType::Int16 => AstDataType::SmallInt,
3434
DataType::Int32 => AstDataType::Int,
3535
DataType::Int64 => AstDataType::BigInt,
36+
DataType::Serial => unreachable!("serial should not be generated"),
3637
DataType::Decimal => AstDataType::Decimal(None, None),
3738
DataType::Float32 => AstDataType::Real,
3839
DataType::Float64 => AstDataType::Double,

src/utils/pgwire/src/pg_extended.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,7 @@ impl PreparedStatement {
521521
};
522522
format!("'{}'::JSONB", tmp)
523523
}
524-
DataType::Struct(_) | DataType::List { .. } => {
524+
DataType::Serial | DataType::Struct(_) | DataType::List { .. } => {
525525
return Err(PsqlError::Internal(anyhow!(
526526
"Unsupported param type {:?}",
527527
type_oid
@@ -557,7 +557,7 @@ impl PreparedStatement {
557557
}
558558
DataType::Interval => params.push("'2 months ago'::interval".to_string()),
559559
DataType::Jsonb => params.push("'null'::JSONB".to_string()),
560-
DataType::Struct(_) | DataType::List { .. } => {
560+
DataType::Serial | DataType::Struct(_) | DataType::List { .. } => {
561561
return Err(PsqlError::Internal(anyhow!(
562562
"Unsupported param type {:?}",
563563
oid

0 commit comments

Comments
 (0)