@@ -170,3 +170,46 @@ def test_append(self, pd):
170170 ("shinji" , 123.0 , "a" ),
171171 ]
172172 assert result .execute ().fetchall () == expected
173+
174+ @pytest .mark .parametrize ("pd" , [NumpyPandas (), ArrowPandas ()])
175+ def test_filename_pattern_with_index (self , pd ):
176+ temp_file_name = os .path .join (tempfile .mkdtemp (), next (tempfile ._get_candidate_names ())) # noqa: PTH118
177+ df = pd .DataFrame (
178+ {
179+ "name" : ["rei" , "shinji" , "asuka" , "kaworu" ],
180+ "float" : [321.0 , 123.0 , 23.0 , 340.0 ],
181+ "category" : ["a" , "a" , "b" , "c" ],
182+ }
183+ )
184+ rel = duckdb .from_df (df )
185+ rel .to_parquet (temp_file_name , partition_by = ["category" ], filename_pattern = "orders_{i}" )
186+ # Check that files follow the pattern with {i}
187+ files_a = os .listdir (f"{ temp_file_name } /category=a" )
188+ files_b = os .listdir (f"{ temp_file_name } /category=b" )
189+ files_c = os .listdir (f"{ temp_file_name } /category=c" )
190+ assert all ("orders_" in f and f .endswith (".parquet" ) for f in files_a )
191+ assert all ("orders_" in f and f .endswith (".parquet" ) for f in files_b )
192+ assert all ("orders_" in f and f .endswith (".parquet" ) for f in files_c )
193+ # Verify data integrity
194+ result = duckdb .sql (f"FROM read_parquet('{ temp_file_name } /*/*.parquet', hive_partitioning=TRUE)" )
195+ expected = [("rei" , 321.0 , "a" ), ("shinji" , 123.0 , "a" ), ("asuka" , 23.0 , "b" ), ("kaworu" , 340.0 , "c" )]
196+ assert result .execute ().fetchall () == expected
197+
198+ @pytest .mark .parametrize ("pd" , [NumpyPandas (), ArrowPandas ()])
199+ def test_filename_pattern_with_uuid (self , pd ):
200+ temp_file_name = os .path .join (tempfile .mkdtemp (), next (tempfile ._get_candidate_names ())) # noqa: PTH118
201+ df = pd .DataFrame (
202+ {
203+ "name" : ["rei" , "shinji" , "asuka" , "kaworu" ],
204+ "float" : [321.0 , 123.0 , 23.0 , 340.0 ],
205+ }
206+ )
207+ rel = duckdb .from_df (df )
208+ rel .to_parquet (temp_file_name , filename_pattern = "file_{uuid}" )
209+ # Check that files follow the pattern with {uuid}
210+ files = [f for f in os .listdir (temp_file_name ) if f .endswith (".parquet" )]
211+ assert len (files ) > 0
212+ assert all (f .startswith ("file_" ) and f .endswith (".parquet" ) for f in files )
213+ # Verify data integrity
214+ result = duckdb .read_parquet (f"{ temp_file_name } /*.parquet" )
215+ assert rel .execute ().fetchall () == result .execute ().fetchall ()
0 commit comments