Skip to content

Commit 7532635

Browse files
committed
feat(query): null type should infer as String Null by default in create as statement
1 parent 2e5fec4 commit 7532635

File tree

2 files changed

+32
-4
lines changed

2 files changed

+32
-4
lines changed

src/query/sql/src/planner/binder/ddl/table.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -528,7 +528,7 @@ impl Binder {
528528
.map(|column_binding| {
529529
Ok(TableField::new(
530530
&column_binding.column_name,
531-
infer_schema_type(&column_binding.data_type)?,
531+
create_as_select_infer_schema_type(&column_binding.data_type)?,
532532
))
533533
})
534534
.collect::<Result<Vec<_>>>()?;
@@ -1766,3 +1766,12 @@ async fn verify_external_location_privileges(dal: Operator) -> Result<()> {
17661766
.await
17671767
.expect("join must succeed")
17681768
}
1769+
1770+
fn create_as_select_infer_schema_type(data_type: &DataType) -> Result<TableDataType> {
1771+
match data_type {
1772+
DataType::Null => Ok(TableDataType::Nullable(Box::new(TableDataType::String))),
1773+
_ => {
1774+
infer_schema_type(data_type)
1775+
}
1776+
}
1777+
}

tests/sqllogictests/suites/base/05_ddl/05_0000_ddl_create_tables.test

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -288,9 +288,6 @@ create table t(a int, A int)
288288
statement error Duplicated column name
289289
create table t as select number, number from numbers(1)
290290

291-
statement error 1006
292-
create table t as select 'a' as c1, null as c2;
293-
294291
statement error 4000
295292
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');
296293

@@ -598,3 +595,25 @@ statement ok
598595
alter table t_opt_retention set options(data_retention_period_in_hours = 2);
599596

600597

598+
#issue 16794
599+
statement ok
600+
create or replace table b as select 123 as col1, null as col2;
601+
602+
query T
603+
desc b;
604+
----
605+
col1 TINYINT UNSIGNED NO 0 (empty)
606+
col2 VARCHAR YES NULL (empty)
607+
608+
query T
609+
show create table b;
610+
----
611+
b CREATE TABLE b ( col1 TINYINT UNSIGNED NOT NULL, col2 VARCHAR NULL ) ENGINE=FUSE
612+
613+
query TT
614+
select * from b;
615+
----
616+
123 NULL
617+
618+
statement ok
619+
drop table if exists b;

0 commit comments

Comments
 (0)