@@ -165,6 +165,66 @@ Dictionary(Int32, Utf8) Utf8View
165165statement ok
166166DROP TABLE thresholded_dict;
167167
168+ # The cap uses the sum of row-group NDVs as a conservative upper bound.
169+ # Each row group has two distinct values, but their summed NDV exceeds the cap.
170+ query I
171+ COPY (
172+ SELECT column1 AS category
173+ FROM (VALUES ('a'), ('b'), ('a'), ('b'))
174+ )
175+ TO 'test_files/scratch/parquet_rle_to_dictionary/threshold_multi_rg.parquet'
176+ STORED AS PARQUET
177+ OPTIONS (
178+ 'format.dictionary_enabled' true,
179+ 'format.max_row_group_size' 2
180+ );
181+ ----
182+ 4
183+
184+ statement ok
185+ CREATE EXTERNAL TABLE threshold_multi_rg
186+ STORED AS PARQUET
187+ LOCATION 'test_files/scratch/parquet_rle_to_dictionary/threshold_multi_rg.parquet';
188+
189+ query T
190+ SELECT DISTINCT arrow_typeof(category) FROM threshold_multi_rg;
191+ ----
192+ Utf8View
193+
194+ statement ok
195+ DROP TABLE threshold_multi_rg;
196+
197+ # A column remains dictionary encoded only when every file containing it
198+ # proves that its NDV is within the cap.
199+ query I
200+ COPY (SELECT column1 AS category FROM (VALUES ('a'), ('b')))
201+ TO 'test_files/scratch/parquet_rle_to_dictionary/threshold_mixed/low.parquet'
202+ STORED AS PARQUET
203+ OPTIONS ('format.dictionary_enabled' true);
204+ ----
205+ 2
206+
207+ query I
208+ COPY (SELECT column1 AS category FROM (VALUES ('a'), ('b'), ('c')))
209+ TO 'test_files/scratch/parquet_rle_to_dictionary/threshold_mixed/high.parquet'
210+ STORED AS PARQUET
211+ OPTIONS ('format.dictionary_enabled' true);
212+ ----
213+ 3
214+
215+ statement ok
216+ CREATE EXTERNAL TABLE threshold_mixed
217+ STORED AS PARQUET
218+ LOCATION 'test_files/scratch/parquet_rle_to_dictionary/threshold_mixed/';
219+
220+ query TI
221+ SELECT arrow_typeof(category), COUNT(*) FROM threshold_mixed GROUP BY arrow_typeof(category);
222+ ----
223+ Utf8View 5
224+
225+ statement ok
226+ DROP TABLE threshold_mixed;
227+
168228statement ok
169229reset datafusion.execution.parquet.write_row_group_number_distinct_values;
170230
0 commit comments