Skip to content

Commit

Permalink
fix comment
Browse files Browse the repository at this point in the history
fix
  • Loading branch information
xxhZs committed Oct 25, 2023
1 parent 02e125c commit c55f636
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 40 deletions.
1 change: 1 addition & 0 deletions e2e_test/batch/catalog/issue_10177.slt.part
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions e2e_test/batch/catalog/pg_type.slt.part
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
38 changes: 19 additions & 19 deletions src/common/src/types/postgres_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
}
};
}
Expand All @@ -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,
Expand All @@ -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<Self> {
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),
Expand All @@ -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,
Expand All @@ -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),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ pub static PG_TYPE: LazyLock<BuiltinView> = 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, \
Expand Down
31 changes: 11 additions & 20 deletions src/frontend/src/catalog/system_catalog/rw_catalog/rw_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<BuiltinTable> = LazyLock::new(|| BuiltinTable {
Expand All @@ -62,6 +51,7 @@ pub static RW_TYPES: LazyLock<BuiltinTable> = LazyLock::new(|| BuiltinTable {
(DataType::Varchar, "name"),
(DataType::Varchar, "input_oid"),
(DataType::Int32, "elem"),
(DataType::Int32, "array"),
],
pk: &[0],
});
Expand All @@ -70,12 +60,13 @@ impl SysCatalogReaderImpl {
pub fn read_rw_types(&self) -> Result<Vec<OwnedRow>> {
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())
Expand Down

0 comments on commit c55f636

Please sign in to comment.