diff --git a/datafusion/sqllogictest/test_files/dictionary.slt b/datafusion/sqllogictest/test_files/dictionary.slt index 105523ab5090..9932ed2c2e12 100644 --- a/datafusion/sqllogictest/test_files/dictionary.slt +++ b/datafusion/sqllogictest/test_files/dictionary.slt @@ -632,4 +632,61 @@ south 2 statement ok DROP TABLE dict_count_distinct; +# overlapping values with different key assignments across batches +query TI rowsort +WITH + first_batch AS ( + SELECT arrow_cast(column1, 'Dictionary(Int32, Utf8)') AS region + FROM (VALUES ('west'), ('east'), ('west'), (NULL)) AS t(column1) + ), + second_batch AS ( + SELECT arrow_cast(column1, 'Dictionary(Int16, LargeUtf8)') AS region + FROM (VALUES ('east'), ('west'), ('north'), (NULL)) AS t(column1) + ) +SELECT region, count(*) +FROM (SELECT region FROM first_batch UNION ALL SELECT region FROM second_batch) +GROUP BY region; +---- +NULL 2 +east 2 +north 1 +west 3 + +# different logical values must not merge even when their dictionary key numbers coincide +query TI rowsort +WITH + first_batch AS ( + SELECT arrow_cast(column1, 'Dictionary(Int8, LargeUtf8)') AS status + FROM (VALUES ('active'), ('inactive'), (NULL)) AS t(column1) + ), + second_batch AS ( + SELECT arrow_cast(column1, 'Dictionary(Int16, Utf8)') AS status + FROM (VALUES ('inactive'), ('active'), (NULL)) AS t(column1) + ) +SELECT status, count(*) +FROM (SELECT status FROM first_batch UNION ALL SELECT status FROM second_batch) +GROUP BY status; +---- +NULL 2 +active 2 +inactive 2 +# value present in one batch's dictionary but absent from the other +query TI rowsort +WITH + first_batch AS ( + SELECT arrow_cast(column1, 'Dictionary(Int32, Utf8)') AS sensor + FROM (VALUES ('temperature'), ('humidity'), ('temperature'), (NULL)) AS t(column1) + ), + second_batch AS ( + SELECT arrow_cast(column1, 'Dictionary(Int8, LargeUtf8)') AS sensor + FROM (VALUES ('temperature'), ('pressure'), (NULL)) AS t(column1) + ) +SELECT sensor, count(*) +FROM (SELECT sensor FROM first_batch UNION ALL SELECT sensor FROM second_batch) +GROUP BY sensor; +---- +NULL 2 +humidity 1 +pressure 1 +temperature 3