python-3.x 保存Snowpark DataFrame作为Snowflake Stage中的文本文件

icomxhvb  于 8个月前  发布在  Python
关注(0)|答案(1)|浏览(67)

我的要求是在Snowflake中获取表格数据,并将其作为CSV文件保存到Snowflake External Stage,其中数据具有页眉和页脚。
使用Snowpark(Python)是否可行?结果应该如下所示,其中col1,col2,col3是Snowflake表中的列

Australia Sales as at 2023-8-31. Version is 2021.01
        Output_Format, CSV
        NUMLINES,      6781
        ---------------------------------
        col1, col2, col3
        xxx,yyy,zzz
        .....
        xxx,yyy,zzz
        ---------------------------------
        ##END##
        ##COLOR####ENDCOLOR##
        ##FORMULA####ENDFORMULA##

字符串

cbeh67ev

cbeh67ev1#

这可以通过Snowpark Python API DataFrameWriter.copy_into_location实现,如here文档所示
下面是一个示例:

df = session.create_dataframe(
            [["John", "Berry"], ["Rick", "Berry"], ["Anthony", "Davis"]],
            schema=["FIRST_NAME", "LAST_NAME"],
        )
df.write.copy_into_location(
            ext_stage,
            partition_by=partition_by,
            file_format_type="csv",
            format_type_options={"COMPRESSION": "GZIP"},
            header=True,
            overwrite=False,
        )

字符串

相关问题