From 870e830400fa3ef13418a56d1cf0220c3aefac85 Mon Sep 17 00:00:00 2001 From: Tishj Date: Mon, 27 May 2024 14:44:34 +0200 Subject: [PATCH] set nulls correctly in the child list --- expected/array_type_support.out | 8 ++++---- sql/array_type_support.sql | 2 +- src/quack_types.cpp | 6 +++--- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/expected/array_type_support.out b/expected/array_type_support.out index 6b4d5e2f..f3ef045b 100644 --- a/expected/array_type_support.out +++ b/expected/array_type_support.out @@ -4,15 +4,15 @@ create extension quack; CREATE TABLE int_array_1d(a INT[]); INSERT INTO int_array_1d SELECT CAST(a as INT[]) FROM (VALUES ('{1, 2, 3}'), - ('{4, 5, 6, 7}'), + ('{4, 5, NULL, 7}'), (NULL), ('{}') ) t(a); SELECT * FROM int_array_1d; - a ------------ + a +-------------- {1,2,3} - {4,5,6,7} + {4,5,NULL,7} {} (4 rows) diff --git a/sql/array_type_support.sql b/sql/array_type_support.sql index 20ef6df4..d06fddcd 100644 --- a/sql/array_type_support.sql +++ b/sql/array_type_support.sql @@ -5,7 +5,7 @@ create extension quack; CREATE TABLE int_array_1d(a INT[]); INSERT INTO int_array_1d SELECT CAST(a as INT[]) FROM (VALUES ('{1, 2, 3}'), - ('{4, 5, 6, 7}'), + ('{4, 5, NULL, 7}'), (NULL), ('{}') ) t(a); diff --git a/src/quack_types.cpp b/src/quack_types.cpp index 17861bce..c1c8d2d0 100644 --- a/src/quack_types.cpp +++ b/src/quack_types.cpp @@ -534,7 +534,6 @@ ConvertPostgresToDuckValue(Datum value, duckdb::Vector &result, idx_t offset) { case duckdb::LogicalTypeId::LIST: { auto &child = duckdb::ListVector::GetEntry(result); - // Convert Datum to ArrayType auto array = DatumGetArrayTypeP(value); @@ -565,12 +564,13 @@ ConvertPostgresToDuckValue(Datum value, duckdb::Vector &result, idx_t offset) { switch (child_id) { case duckdb::LogicalType::INTEGER: { for (int i = 0; i < nelems; i++) { + idx_t dest_idx = child_offset + i; if (nulls[i]) { auto &array_mask = duckdb::FlatVector::Validity(child); - array_mask.SetInvalid(i); + array_mask.SetInvalid(dest_idx); continue; } - ConvertPostgresToDuckValue(elems[i], child, child_offset + i); + ConvertPostgresToDuckValue(elems[i], child, dest_idx); } break; }