Skip to content

Commit

Permalink
fix(query): fix create table as query with null type (#16041)
Browse files Browse the repository at this point in the history
* fix(query): fix create table as query have NULL type

* add tests

* fix
  • Loading branch information
b41sh authored Jul 13, 2024
1 parent ff95a2f commit f46bd8e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/query/expression/src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1197,7 +1197,7 @@ impl From<&TableDataType> for DataType {
impl TableDataType {
pub fn wrap_nullable(&self) -> Self {
match self {
TableDataType::Nullable(_) => self.clone(),
TableDataType::Null | TableDataType::Nullable(_) => self.clone(),
_ => Self::Nullable(Box::new(self.clone())),
}
}
Expand Down
7 changes: 7 additions & 0 deletions src/query/sql/src/planner/binder/ddl/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ use databend_common_expression::types::DataType;
use databend_common_expression::ComputedExpr;
use databend_common_expression::DataField;
use databend_common_expression::DataSchemaRefExt;
use databend_common_expression::TableDataType;
use databend_common_expression::TableField;
use databend_common_expression::TableSchema;
use databend_common_expression::TableSchemaRef;
Expand Down Expand Up @@ -1496,6 +1497,12 @@ impl Binder {
field.name()
)));
}
if field.data_type == TableDataType::Null {
return Err(ErrorCode::BadArguments(format!(
"Column `{}` have NULL type is not allowed",
field.name()
)));
}
}

Ok(())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,9 @@ create table t(a int, A int)
statement error Duplicated column name
create table t as select number, number from numbers(1)

statement error 1006
create table t as select 'a' as c1, null as c2;

statement error 4000
create table tb101 (id int ,c1 datetime) 's3://wubx/tb101' connection=(aws_key_id='minioadmin' aws_ssecret_key='minioadmin' endpoint_url='http://127.0.0.1:9900');

Expand Down

0 comments on commit f46bd8e

Please sign in to comment.