From c55f636a6af5c3717e6779687d1c48493b560a21 Mon Sep 17 00:00:00 2001 From: xxhZs <1060434431@qq.com> Date: Wed, 25 Oct 2023 18:21:27 +0800 Subject: [PATCH] fix comment fix --- e2e_test/batch/catalog/issue_10177.slt.part | 1 + e2e_test/batch/catalog/pg_type.slt.part | 1 + src/common/src/types/postgres_type.rs | 38 +++++++++---------- .../system_catalog/pg_catalog/pg_type.rs | 2 +- .../system_catalog/rw_catalog/rw_types.rs | 31 ++++++--------- 5 files changed, 33 insertions(+), 40 deletions(-) diff --git a/e2e_test/batch/catalog/issue_10177.slt.part b/e2e_test/batch/catalog/issue_10177.slt.part index bafa8cb43e409..8f8c40aa75c19 100644 --- a/e2e_test/batch/catalog/issue_10177.slt.part +++ b/e2e_test/batch/catalog/issue_10177.slt.part @@ -46,6 +46,7 @@ END; pg_catalog 1000 _bool b f NULL pg_catalog 1001 _bytea b f NULL pg_catalog 1005 _int2 b f NULL +pg_catalog 1007 _int4 b f NULL pg_catalog 1015 _varchar b f NULL pg_catalog 1016 _int8 b f NULL pg_catalog 1021 _float4 b f NULL diff --git a/e2e_test/batch/catalog/pg_type.slt.part b/e2e_test/batch/catalog/pg_type.slt.part index 04e7a52cb10f2..1612f4787acf4 100644 --- a/e2e_test/batch/catalog/pg_type.slt.part +++ b/e2e_test/batch/catalog/pg_type.slt.part @@ -12,6 +12,7 @@ SELECT oid, typname, typelem, typnotnull, typtype, typinput FROM pg_catalog.pg_t 1000 _bool 16 f b array_in 1001 _bytea 17 f b array_in 1005 _int2 21 f b array_in +1007 _int4 23 f b array_in 1015 _varchar 1043 f b array_in 1016 _int8 20 f b array_in 1021 _float4 700 f b array_in diff --git a/src/common/src/types/postgres_type.rs b/src/common/src/types/postgres_type.rs index 9db65931c3e0c..6187d3b9e6063 100644 --- a/src/common/src/types/postgres_type.rs +++ b/src/common/src/types/postgres_type.rs @@ -30,21 +30,21 @@ macro_rules! for_all_base_types { ($macro:ident $(, $x:tt)*) => { $macro! { $($x, )* - { Boolean | 16 | 1000 | bool | boolin | 1 | 0 } - { Bytea | 17 | 1001 | bytea | byteain | -1 | 0 } - { Int64 | 20 | 1016 | int8 | int8in | 8 | 0 } - { Int16 | 21 | 1005 | int2 | int2in | 2 | 0 } - { Int32 | 23 | 1007 | int4 | int4in | 4 | 0 } - { Float32 | 700 | 1021 | float4 | float4in | 4 | 0 } - { Float64 | 701 | 1022 | float8 | float8in | 8 | 0 } - { Varchar | 1043 | 1015 | varchar | varcharin | -1 | 0 } - { Date | 1082 | 1182 | date | date_in | 4 | 0 } - { Time | 1083 | 1183 | time | time_in | 8 | 0 } - { Timestamp | 1114 | 1115 | timestamp | timestamp_in | 8 | 0 } - { Timestamptz | 1184 | 1185 | timestamptz | timestamptz_in | 8 | 0 } - { Interval | 1186 | 1187 | interval | interval_in | 16 | 0 } - { Decimal | 1700 | 1231 | numeric | numeric_in | -1 | 0 } - { Jsonb | 3802 | 3807 | jsonb | jsonb_in | -1 | 0 } + { Boolean | 16 | 1000 | bool | boolin | 1 } + { Bytea | 17 | 1001 | bytea | byteain | -1 } + { Int64 | 20 | 1016 | int8 | int8in | 8 } + { Int16 | 21 | 1005 | int2 | int2in | 2 } + { Int32 | 23 | 1007 | int4 | int4in | 4 } + { Float32 | 700 | 1021 | float4 | float4in | 4 } + { Float64 | 701 | 1022 | float8 | float8in | 8 } + { Varchar | 1043 | 1015 | varchar | varcharin | -1 } + { Date | 1082 | 1182 | date | date_in | 4 } + { Time | 1083 | 1183 | time | time_in | 8 } + { Timestamp | 1114 | 1115 | timestamp | timestamp_in | 8 } + { Timestamptz | 1184 | 1185 | timestamptz | timestamptz_in | 8 } + { Interval | 1186 | 1187 | interval | interval_in | 16 } + { Decimal | 1700 | 1231 | numeric | numeric_in | -1 } + { Jsonb | 3802 | 3807 | jsonb | jsonb_in | -1 } } }; } @@ -53,7 +53,7 @@ macro_rules! for_all_base_types { impl DataType { pub fn type_len(&self) -> i16 { macro_rules! impl_type_len { - ($( { $enum:ident | $oid:literal | $oid_array:literal | $name:ident | $input:ident | $len:literal | $elem:literal} )*) => { + ($( { $enum:ident | $oid:literal | $oid_array:literal | $name:ident | $input:ident | $len:literal} )*) => { match self { $( DataType::$enum => $len, @@ -75,7 +75,7 @@ impl DataType { // For Numeric(aka Decimal): oid = 1700, array_type_oid = 1231 pub fn from_oid(oid: i32) -> crate::error::Result { macro_rules! impl_from_oid { - ($( { $enum:ident | $oid:literal | $oid_array:literal | $name:ident | $input:ident | $len:literal | $elem:literal} )*) => { + ($( { $enum:ident | $oid:literal | $oid_array:literal | $name:ident | $input:ident | $len:literal} )*) => { match oid { $( $oid => Ok(DataType::$enum), @@ -95,7 +95,7 @@ impl DataType { pub fn to_oid(&self) -> i32 { macro_rules! impl_to_oid { - ($( { $enum:ident | $oid:literal | $oid_array:literal | $name:ident | $input:ident | $len:literal | $elem:literal} )*) => { + ($( { $enum:ident | $oid:literal | $oid_array:literal | $name:ident | $input:ident | $len:literal} )*) => { match self { $( DataType::$enum => $oid, @@ -121,7 +121,7 @@ impl DataType { pub fn pg_name(&self) -> &'static str { macro_rules! impl_pg_name { - ($( { $enum:ident | $oid:literal | $oid_array:literal | $name:ident | $input:ident | $len:literal | $elem:literal} )*) => { + ($( { $enum:ident | $oid:literal | $oid_array:literal | $name:ident | $input:ident | $len:literal} )*) => { match self { $( DataType::$enum => stringify!($name), diff --git a/src/frontend/src/catalog/system_catalog/pg_catalog/pg_type.rs b/src/frontend/src/catalog/system_catalog/pg_catalog/pg_type.rs index 27b42d0a77868..61670d265dca9 100644 --- a/src/frontend/src/catalog/system_catalog/pg_catalog/pg_type.rs +++ b/src/frontend/src/catalog/system_catalog/pg_catalog/pg_type.rs @@ -59,7 +59,7 @@ pub static PG_TYPE: LazyLock = LazyLock::new(|| BuiltinView { sql: "SELECT t.id AS oid, \ t.name AS typname, \ t.elem AS typelem, \ - 0 AS typarray, \ + t.array AS typarray, \ t.input_oid AS typinput, \ false AS typnotnull, \ 0 AS typbasetype, \ diff --git a/src/frontend/src/catalog/system_catalog/rw_catalog/rw_types.rs b/src/frontend/src/catalog/system_catalog/rw_catalog/rw_types.rs index f20f2eb409758..35f6e860b711a 100644 --- a/src/frontend/src/catalog/system_catalog/rw_catalog/rw_types.rs +++ b/src/frontend/src/catalog/system_catalog/rw_catalog/rw_types.rs @@ -24,34 +24,23 @@ use risingwave_common::types::{DataType, ScalarImpl}; use crate::catalog::system_catalog::{BuiltinTable, SysCatalogReaderImpl}; macro_rules! impl_pg_type_data { - ($( { $enum:ident | $oid:literal | $oid_array:literal | $name:ident | $input:ident | $len:literal | $elem:literal} )*) => { + ($( { $enum:ident | $oid:literal | $oid_array:literal | $name:ident | $input:ident | $len:literal } )*) => { &[ $( - ($oid, stringify!($name), stringify!($input),$elem), + ($oid, stringify!($name), stringify!($input), 0, $oid_array), )* // Note: rw doesn't support `text` type, returning it is just a workaround to be compatible // with PostgreSQL. - (25, "text", "textin",0), - (1301, "rw_int256", "rw_int256_in",0), + (25, "text", "textin",0,1009), + (1301, "rw_int256", "rw_int256_in",0,0), // Note: Here is only to avoid some components of psql from not being able to find relevant results, causing errors. We will not use it in the RW. - (1000, "_bool", "array_in",16), - (1001, "_bytea", "array_in",17), - (1016, "_int8", "array_in",20), - (1005, "_int2", "array_in",21), - (1021, "_float4", "array_in",700), - (1022, "_float8", "array_in",701), - (1015, "_varchar", "array_in",1043), - (1182, "_date", "array_in",1082), - (1183, "_time", "array_in",2083), - (1115, "_timestamp", "array_in",1114), - (1185, "_timestamptz", "array_in",1184), - (1187, "_interval", "array_in",1186), - (1231, "_numeric", "array_in",1700), - (3807, "_jsonb", "array_in",3802), + $( + ($oid_array, concat!("_", stringify!($name)), "array_in", $oid, 0), + )* ] } } -pub const RW_TYPE_DATA: &[(i32, &str, &str, i32)] = for_all_base_types! { impl_pg_type_data }; +pub const RW_TYPE_DATA: &[(i32, &str, &str, i32, i32)] = for_all_base_types! { impl_pg_type_data }; /// `rw_types` stores all supported types in the database. pub static RW_TYPES: LazyLock = LazyLock::new(|| BuiltinTable { @@ -62,6 +51,7 @@ pub static RW_TYPES: LazyLock = LazyLock::new(|| BuiltinTable { (DataType::Varchar, "name"), (DataType::Varchar, "input_oid"), (DataType::Int32, "elem"), + (DataType::Int32, "array"), ], pk: &[0], }); @@ -70,12 +60,13 @@ impl SysCatalogReaderImpl { pub fn read_rw_types(&self) -> Result> { Ok(RW_TYPE_DATA .iter() - .map(|(id, name, input, elem)| { + .map(|(id, name, input, elem, array)| { OwnedRow::new(vec![ Some(ScalarImpl::Int32(*id)), Some(ScalarImpl::Utf8(name.to_string().into())), Some(ScalarImpl::Utf8(input.to_string().into())), Some(ScalarImpl::Int32(*elem)), + Some(ScalarImpl::Int32(*array)), ]) }) .collect_vec())