diff --git a/src/frontend/src/binder/relation/table_function.rs b/src/frontend/src/binder/relation/table_function.rs index efb4de3c5551..1a609f87670f 100644 --- a/src/frontend/src/binder/relation/table_function.rs +++ b/src/frontend/src/binder/relation/table_function.rs @@ -16,18 +16,13 @@ use std::str::FromStr; use itertools::Itertools; use risingwave_common::bail_not_implemented; -use risingwave_common::catalog::{ - Field, Schema, PG_CATALOG_SCHEMA_NAME, RW_INTERNAL_TABLE_FUNCTION_NAME, -}; +use risingwave_common::catalog::{Field, Schema, RW_INTERNAL_TABLE_FUNCTION_NAME}; use risingwave_common::types::DataType; use risingwave_sqlparser::ast::{Function, FunctionArg, ObjectName, TableAlias}; use super::watermark::is_watermark_func; use super::{Binder, Relation, Result, WindowTableFunctionKind}; use crate::binder::bind_context::Clause; -use crate::catalog::system_catalog::pg_catalog::{ - PG_GET_KEYWORDS_FUNC_NAME, PG_KEYWORDS_TABLE_NAME, -}; use crate::error::ErrorCode; use crate::expr::{Expr, ExprImpl}; @@ -57,24 +52,6 @@ impl Binder { } return self.bind_internal_table(args, alias); } - if func_name.eq_ignore_ascii_case(PG_GET_KEYWORDS_FUNC_NAME) - || name.real_value().eq_ignore_ascii_case( - format!("{}.{}", PG_CATALOG_SCHEMA_NAME, PG_GET_KEYWORDS_FUNC_NAME).as_str(), - ) - { - if with_ordinality { - bail_not_implemented!( - "WITH ORDINALITY for internal/system table function {}", - func_name - ); - } - return self.bind_relation_by_name_inner( - Some(PG_CATALOG_SCHEMA_NAME), - PG_KEYWORDS_TABLE_NAME, - alias, - None, - ); - } } // window table functions (tumble/hop) if let Ok(kind) = WindowTableFunctionKind::from_str(func_name) { diff --git a/src/frontend/src/catalog/system_catalog/pg_catalog/mod.rs b/src/frontend/src/catalog/system_catalog/pg_catalog/mod.rs index 202646b55a60..de1fe4924642 100644 --- a/src/frontend/src/catalog/system_catalog/pg_catalog/mod.rs +++ b/src/frontend/src/catalog/system_catalog/pg_catalog/mod.rs @@ -52,5 +52,3 @@ mod pg_trigger; mod pg_type; mod pg_user; mod pg_views; - -pub use pg_keywords::*; diff --git a/src/frontend/src/catalog/system_catalog/pg_catalog/pg_keywords.rs b/src/frontend/src/catalog/system_catalog/pg_catalog/pg_keywords.rs index c3bb43ef0a84..a859527afa6d 100644 --- a/src/frontend/src/catalog/system_catalog/pg_catalog/pg_keywords.rs +++ b/src/frontend/src/catalog/system_catalog/pg_catalog/pg_keywords.rs @@ -12,19 +12,60 @@ // See the License for the specific language governing permissions and // limitations under the License. +// The code is same as `expr/impl/src/table_function/pg_get_keywords.rs`. + use risingwave_common::types::Fields; use risingwave_frontend_macro::system_catalog; +use risingwave_sqlparser::keywords::{ + ALL_KEYWORDS_INDEX, RESERVED_FOR_COLUMN_ALIAS, RESERVED_FOR_COLUMN_OR_TABLE_NAME, +}; -pub const PG_KEYWORDS_TABLE_NAME: &str = "pg_keywords"; -pub const PG_GET_KEYWORDS_FUNC_NAME: &str = "pg_get_keywords"; +use crate::catalog::system_catalog::SysCatalogReaderImpl; /// The catalog `pg_keywords` stores keywords. `pg_get_keywords` returns the content of this table. /// Ref: [`https://www.postgresql.org/docs/15/functions-info.html`] -// TODO: change to read reserved keywords here -#[system_catalog(view, "pg_catalog.pg_keywords")] +/// +/// # Example +/// +/// ```slt +/// query TTT +/// select * from pg_keywords where word = 'add'; +/// ---- +/// add U unreserved +/// ``` #[derive(Fields)] struct PgKeywords { + #[primary_key] word: String, - catcode: String, - catdesc: String, + catcode: char, + catdesc: &'static str, +} + +#[system_catalog(table, "pg_catalog.pg_keywords")] +fn read_pg_keywords(_reader: &SysCatalogReaderImpl) -> Vec { + ALL_KEYWORDS_INDEX + .iter() + .map(|keyword| { + // FIXME: The current category is not correct. Many are different from the PostgreSQL. + let catcode = if !RESERVED_FOR_COLUMN_OR_TABLE_NAME.contains(keyword) { + 'U' + } else if !RESERVED_FOR_COLUMN_ALIAS.contains(keyword) { + 'C' + } else { + 'R' + }; + let catdesc = match catcode { + 'U' => "unreserved", + 'C' => "unreserved (cannot be function or type name)", + 'T' => "reserved (can be function or type name)", + 'R' => "reserved", + _ => unreachable!(), + }; + PgKeywords { + word: keyword.to_string().to_lowercase(), + catcode, + catdesc, + } + }) + .collect() }