Skip to content

Commit 253aba6

Browse files
authored
fix: Block::to_record_batch fail when a column is array of NULLs. (#18989)
1 parent 82f7c9e commit 253aba6

File tree

2 files changed

+51
-18
lines changed
  • src/query/expression/src/converts/arrow
  • tests/sqllogictests/suites/stage

2 files changed

+51
-18
lines changed

โ€Žsrc/query/expression/src/converts/arrow/to.rsโ€Ž

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ impl From<&TableField> for Field {
234234
}
235235
};
236236

237-
Field::new(f.name(), ty, f.is_nullable()).with_metadata(metadata)
237+
Field::new(f.name(), ty, f.is_nullable_or_null()).with_metadata(metadata)
238238
}
239239
}
240240

@@ -428,3 +428,25 @@ impl Column {
428428
(&self).into()
429429
}
430430
}
431+
432+
#[cfg(test)]
433+
mod tests {
434+
use databend_common_column::buffer::Buffer;
435+
436+
use super::*;
437+
use crate::types::AnyType;
438+
use crate::types::ArrayColumn;
439+
440+
#[test]
441+
fn test_to_record_batch_with_null_array() {
442+
let array =
443+
ArrayColumn::<AnyType>::new(Column::Null { len: 3 }, Buffer::from(vec![0_u64, 3]));
444+
let block = DataBlock::new_from_columns(vec![Column::Array(Box::new(array))]);
445+
let schema = DataSchema::new(vec![DataField::new(
446+
"arr",
447+
DataType::Array(Box::new(DataType::Null)),
448+
)]);
449+
450+
assert!(block.to_record_batch_with_dataschema(&schema).is_ok());
451+
}
452+
}

โ€Žtests/sqllogictests/suites/stage/unload.testโ€Ž

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -34,18 +34,18 @@ create file format if not exists csv_zip type=csv compression=zip;
3434

3535

3636
# test csv
37-
query
37+
query
3838
copy into @unload from ii file_format=(type=csv);
3939
-----
4040
----
4141
3 12 12
4242

43-
query
43+
query
4444
select right(name, 4), size from list_stage(location=>'@unload');
4545
----
4646
.csv 12
4747

48-
query
48+
query
4949
select $1, $2 from @unload(file_format=>'csv');
5050
----
5151
1 2
@@ -56,46 +56,46 @@ select $1, $2 from @unload(file_format=>'csv');
5656
statement ok
5757
remove @unload;
5858

59-
query
59+
query
6060
copy into @unload from ii file_format=(format_name='csv_gzip');
6161
----
6262
3 12 32
6363

6464
statement error
6565
copy into @unload from ii file_format=(format_name='csv_snappy');
6666

67-
query
67+
query
6868
copy into @unload from ii file_format=(format_name='csv_none');
6969
----
7070
3 12 12
7171

72-
query
72+
query
7373
copy into @unload from ii file_format=(format_name='csv_zip');
7474
----
7575
3 12 136
7676

77-
query
77+
query
7878
select right(name, 7), size from list_stage(location=>'@unload');
7979
----
8080
.csv.gz 32
8181
000.csv 12
8282
csv.zip 136
8383

84-
query
84+
query
8585
select $1, $2 from @unload(file_format => 'csv_gzip' pattern => '.*.gz');
8686
----
8787
1 2
8888
3 4
8989
5 6
9090

91-
query
91+
query
9292
select $1, $2 from @unload(file_format => 'csv_none' pattern => '.*.csv');
9393
----
9494
1 2
9595
3 4
9696
5 6
9797

98-
query
98+
query
9999
select $1, $2 from @unload(file_format => 'csv_zip' pattern => '.*.zip');
100100
----
101101
1 2
@@ -106,37 +106,48 @@ select $1, $2 from @unload(file_format => 'csv_zip' pattern => '.*.zip');
106106
statement ok
107107
remove @unload;
108108

109-
query
109+
query
110110
copy into @unload from ii file_format=(format_name='tsv');
111111
----
112112
3 12 12
113113

114-
query
114+
query
115115
select right(name, 4), size from list_stage(location=>'@unload');
116116
----
117117
.tsv 12
118118

119-
query
119+
query
120120
select $1, $2 from @unload(file_format => 'tsv');
121121
----
122122
1 2
123123
3 4
124124
5 6
125125

126-
query
126+
query
127127
copy into @unload/a_raw_path.csv from (select 1,2) file_format=(type=csv) single=true include_query_id=false use_raw_path=true detailed_output=true overwrite=true;
128128
----
129129
a_raw_path.csv 4 1
130130

131-
query
131+
query
132132
copy into @unload/a_raw_path.csv from (select 3,4) file_format=(type=csv) single=true include_query_id=false use_raw_path=true detailed_output=true overwrite=true;
133133
----
134134
a_raw_path.csv 4 1
135135

136-
query
136+
query
137137
select $1, $2 from @unload/a_raw_path.csv (file_format => 'csv');
138138
----
139139
3 4
140140

141141
statement error 1006.*file already exists
142-
copy into @unload/a_raw_path.csv from (select 3,4) file_format=(type=csv) single=true include_query_id=false use_raw_path=true detailed_output=false overwrite=false;
142+
copy into @unload/a_raw_path.csv from (select 3,4) file_format=(type=csv) single=true include_query_id=false use_raw_path=true detailed_output=false overwrite=false;
143+
144+
145+
query
146+
copy into @unload/array_of_nulls from (select [NULL, NULL]);
147+
----
148+
1 8 548
149+
150+
query
151+
select * from @unload/array_of_nulls;
152+
----
153+
[NULL,NULL]

0 commit comments

Comments
ย (0)