@@ -851,6 +851,7 @@ def unload_to_files(
851851 aws_secret_access_key : Optional [str ] = None ,
852852 aws_session_token : Optional [str ] = None ,
853853 region : Optional [str ] = None ,
854+ unload_format : Optional [str ] = None ,
854855 max_file_size : Optional [float ] = None ,
855856 kms_key_id : Optional [str ] = None ,
856857 manifest : bool = False ,
@@ -890,6 +891,9 @@ def unload_to_files(
890891 same AWS Region as the Amazon Redshift cluster. By default, UNLOAD
891892 assumes that the target Amazon S3 bucket is located in the same AWS
892893 Region as the Amazon Redshift cluster.
894+ unload_format: str, optional
895+ Format of the unloaded S3 objects from the query.
896+ Valid values: "CSV", "PARQUET". Case sensitive. Defaults to PARQUET.
893897 max_file_size : float, optional
894898 Specifies the maximum size (MB) of files that UNLOAD creates in Amazon S3.
895899 Specify a decimal value between 5.0 MB and 6200.0 MB. If None, the default
@@ -925,9 +929,12 @@ def unload_to_files(
925929
926930
927931 """
932+ if unload_format not in [None , "CSV" , "PARQUET" ]:
933+ raise exceptions .InvalidArgumentValue ("<unload_format> argument must be 'CSV' or 'PARQUET'" )
928934 session : boto3 .Session = _utils .ensure_session (session = boto3_session )
929935 s3 .delete_objects (path = path , use_threads = use_threads , boto3_session = session )
930936 with con .cursor () as cursor :
937+ format_str : str = unload_format or "PARQUET"
931938 partition_str : str = f"\n PARTITION BY ({ ',' .join (partition_cols )} )" if partition_cols else ""
932939 manifest_str : str = "\n manifest" if manifest is True else ""
933940 region_str : str = f"\n REGION AS '{ region } '" if region is not None else ""
@@ -948,7 +955,7 @@ def unload_to_files(
948955 f"{ auth_str } "
949956 "ALLOWOVERWRITE\n "
950957 "PARALLEL ON\n "
951- "FORMAT PARQUET \n "
958+ f "FORMAT { format_str } \n "
952959 "ENCRYPTED"
953960 f"{ kms_key_id_str } "
954961 f"{ partition_str } "
0 commit comments