Skip to content

Commit

Permalink
write a 0-length list_entry_t for the empty list, add DataChunk.Verif…
Browse files Browse the repository at this point in the history
…y to catch this earlier, add test
  • Loading branch information
Tishj committed Jun 18, 2024
1 parent f1e1a5f commit fb971c9
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/quack_types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -799,6 +799,12 @@ ConvertPostgresToDuckValue(Datum value, duckdb::Vector &result, idx_t offset) {
}
if (ndims == 0) {
D_ASSERT(nelems == 0);
auto child_offset = duckdb::ListVector::GetListSize(*vec);
auto list_data = duckdb::FlatVector::GetData<duckdb::list_entry_t>(*vec);
list_data[write_offset] = duckdb::list_entry_t(
child_offset,
0
);
vec = &duckdb::ListVector::GetEntry(*vec);
}

Expand Down Expand Up @@ -961,6 +967,8 @@ InsertTupleIntoChunk(duckdb::DataChunk &output, PostgresHeapSeqScanThreadInfo &t
if (validTuple) {
threadScanInfo.m_output_vector_size++;
}
output.SetCardinality(threadScanInfo.m_output_vector_size);
output.Verify();

parallelScanState.m_total_row_count++;

Expand Down
12 changes: 12 additions & 0 deletions test/regression/expected/array_type_support.out
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
drop extension if exists quack;
create extension quack;
-- INT4 (zero dimension)
CREATE TABLE int_array_0d(a INT[]);
INSERT INTO int_array_0d SELECT CAST(a as INT[]) FROM (VALUES
('{}')
) t(a);
SELECT * FROM int_array_0d;
a
----
{}
(1 row)

-- INT4 (single dimension)
CREATE TABLE int_array_1d(a INT[]);
INSERT INTO int_array_1d SELECT CAST(a as INT[]) FROM (VALUES
Expand Down Expand Up @@ -87,6 +98,7 @@ SELECT * FROM bool_array_1d;
{}
(4 rows)

DROP TABLE int_array_0d;
DROP TABLE int_array_1d;
DROP TABLE int_array_2d;
DROP TABLE bigint_array_1d;
Expand Down
8 changes: 8 additions & 0 deletions test/regression/sql/array_type_support.sql
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
drop extension if exists quack;
create extension quack;

-- INT4 (zero dimension)
CREATE TABLE int_array_0d(a INT[]);
INSERT INTO int_array_0d SELECT CAST(a as INT[]) FROM (VALUES
('{}')
) t(a);
SELECT * FROM int_array_0d;

-- INT4 (single dimension)
CREATE TABLE int_array_1d(a INT[]);
INSERT INTO int_array_1d SELECT CAST(a as INT[]) FROM (VALUES
Expand Down Expand Up @@ -60,6 +67,7 @@ INSERT INTO bool_array_1d SELECT CAST(a as BOOL[]) FROM (VALUES
) t(a);
SELECT * FROM bool_array_1d;

DROP TABLE int_array_0d;
DROP TABLE int_array_1d;
DROP TABLE int_array_2d;
DROP TABLE bigint_array_1d;
Expand Down

0 comments on commit fb971c9

Please sign in to comment.