Skip to content

Commit

Permalink
feat: ignore varchar with length
Browse files Browse the repository at this point in the history
  • Loading branch information
fuyufjh committed May 31, 2024
1 parent cab8403 commit 467e253
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 9 deletions.
11 changes: 10 additions & 1 deletion src/frontend/src/binder/expr/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ use crate::binder::Binder;
use crate::error::{ErrorCode, Result, RwError};
use crate::expr::{Expr as _, ExprImpl, ExprType, FunctionCall, InputRef, Parameter, SubqueryKind};
use crate::handler::create_sql_function::SQL_UDF_PATTERN;
use crate::session::current;

mod binary_op;
mod column;
Expand Down Expand Up @@ -985,7 +986,15 @@ pub fn bind_data_type(data_type: &AstDataType) -> Result<DataType> {
AstDataType::Double | AstDataType::Float(Some(25..=53) | None) => DataType::Float64,
AstDataType::Float(Some(0 | 54..)) => unreachable!(),
AstDataType::Decimal(None, None) => DataType::Decimal,
AstDataType::Varchar | AstDataType::Text => DataType::Varchar,
AstDataType::Varchar(size) => {
if size.is_some() {
current::notice_to_user(
"CHARACTER VARYING with length is not supported. The length is ignored.",
);
}
DataType::Varchar
}
AstDataType::Text => DataType::Varchar,
AstDataType::Date => DataType::Date,
AstDataType::Time(false) => DataType::Time,
AstDataType::Timestamp(false) => DataType::Timestamp,
Expand Down
2 changes: 1 addition & 1 deletion src/frontend/src/binder/select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -679,7 +679,7 @@ fn derive_alias(expr: &Expr) -> Option<String> {
fn data_type_to_alias(data_type: &AstDataType) -> Option<String> {
let alias = match data_type {
AstDataType::Char(_) => "bpchar".to_string(),
AstDataType::Varchar => "varchar".to_string(),
AstDataType::Varchar(_) => "varchar".to_string(),
AstDataType::Uuid => "uuid".to_string(),
AstDataType::Decimal(_, _) => "numeric".to_string(),
AstDataType::Real | AstDataType::Float(Some(1..=24)) => "float4".to_string(),
Expand Down
2 changes: 1 addition & 1 deletion src/frontend/src/handler/create_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ pub fn bind_sql_columns(column_defs: &[ColumnDef]) -> Result<Vec<ColumnCatalog>>
}

match data_type {
AstDataType::Text | AstDataType::Varchar | AstDataType::Char(_) => {}
AstDataType::Text | AstDataType::Varchar(_) | AstDataType::Char(_) => {}
_ => {
return Err(ErrorCode::NotSupported(
format!("{} is not a collatable data type", data_type),
Expand Down
8 changes: 5 additions & 3 deletions src/sqlparser/src/ast/data_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ pub enum DataType {
/// Fixed-length character type e.g. CHAR(10)
Char(Option<u64>),
/// Variable-length character type.
/// We diverge from postgres by disallowing Varchar(n).
Varchar,
/// The length is only for compatibility with PostgreSQL. RisingWave ignores it.
Varchar(Option<u64>),
/// Uuid type
Uuid,
/// Decimal type with optional precision and scale e.g. DECIMAL(10,2)
Expand Down Expand Up @@ -76,7 +76,9 @@ impl fmt::Display for DataType {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
DataType::Char(size) => format_type_with_optional_length(f, "CHAR", size),
DataType::Varchar => write!(f, "CHARACTER VARYING"),
DataType::Varchar(size) => {
format_type_with_optional_length(f, "CHARACTER VARYING", size)
}
DataType::Uuid => write!(f, "UUID"),
DataType::Decimal(precision, scale) => {
if let Some(scale) = scale {
Expand Down
2 changes: 1 addition & 1 deletion src/sqlparser/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2665,7 +2665,7 @@ impl Parser<'_> {
self.next_token();
}
Keyword::VARCHAR => {
header_inner_expect_type = Some(DataType::Varchar);
header_inner_expect_type = Some(DataType::Varchar(None));
self.next_token();
}
_ => {
Expand Down
4 changes: 2 additions & 2 deletions src/sqlparser/src/parser_v2/data_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,9 @@ where
Keyword::SMALLINT => empty.value(DataType::SmallInt),
Keyword::INT | Keyword::INTEGER => empty.value(DataType::Int),
Keyword::BIGINT => empty.value(DataType::BigInt),
Keyword::STRING | Keyword::VARCHAR => empty.value(DataType::Varchar),
Keyword::STRING | Keyword::VARCHAR => opt(precision_in_range(..)).map(DataType::Varchar),
Keyword::CHAR | Keyword::CHARACTER => dispatch! {keyword;
Keyword::VARYING => empty.value(DataType::Varchar),
Keyword::VARYING => opt(precision_in_range(..)).map(DataType::Varchar),
_ => opt(precision_in_range(..)).map(DataType::Char),
},
Keyword::UUID => empty.value(DataType::Uuid),
Expand Down

0 comments on commit 467e253

Please sign in to comment.