@@ -352,6 +352,36 @@ def test_unload_extras(bucket, path, redshift_table, redshift_con, databases_par
352352 assert len (df .columns ) == 2
353353
354354
355+ def test_unload_with_prefix (bucket , path , redshift_table , redshift_con , databases_parameters , kms_key_id ):
356+ test_prefix = "my_prefix"
357+ table = redshift_table
358+ schema = databases_parameters ["redshift" ]["schema" ]
359+ df = pd .DataFrame ({"id" : [1 , 2 ], "name" : ["foo" , "boo" ]})
360+ wr .redshift .to_sql (df = df , con = redshift_con , table = table , schema = schema , mode = "overwrite" , index = False )
361+
362+ args = {
363+ "sql" : f"SELECT * FROM { schema } .{ table } " ,
364+ "path" : f"{ path } { test_prefix } " ,
365+ "con" : redshift_con ,
366+ "iam_role" : databases_parameters ["redshift" ]["role" ],
367+ "region" : wr .s3 .get_bucket_region (bucket ),
368+ "max_file_size" : 5.0 ,
369+ "kms_key_id" : kms_key_id ,
370+ }
371+ # Adding a prefix to S3 output files
372+ wr .redshift .unload_to_files (** args )
373+ filename = wr .s3 .list_objects (path = path )[0 ].split ("/" )[- 1 ]
374+ assert filename .startswith (test_prefix )
375+
376+ # Prefix becomes part of path with partitioning
377+ wr .redshift .unload_to_files (
378+ ** args ,
379+ partition_cols = ["name" ],
380+ )
381+ object_prefix = wr .s3 .list_objects (path = path )[0 ].split ("/" )[- 3 ]
382+ assert object_prefix == test_prefix
383+
384+
355385def test_to_sql_cast (redshift_table , redshift_con ):
356386 table = redshift_table
357387 df = pd .DataFrame (
0 commit comments