WRITE_PANDAS雪花连接器函数无法在表上操作

问题描述

我正在使用一个python脚本,该脚本旨在处理一些数据,如果不存在则创建表,并在插入刷新的数据集之前截断该表。我使用的角色具有USAGE、READ、WRITE、CREATE TABLE权限,以及如下设置的STAGE权限:

grant usage, read, write on future stages in schema <schema> to role <role>

我通过雪花连接器在Python中使用write_pandas函数。文档说明此函数使用PUT和COPY INTO命令:

To write the data to the table, the function saves the data to Parquet files, uses the PUT command to upload these files to a temporary stage, and uses the COPY INTO <table> command to copy the data from the files to the table. You can use some of the function parameters to control how the PUT and COPY INTO <table> statements are executed.

我仍然收到错误消息,即我无法对架构进行操作,并且我不确定还需要添加什么。是否有人拥有运行WRITE_PANDAS命令所需的权限列表?


解决方案

write_pandas()不会自动创建表。如果事先不存在该表,则需要您自己创建该表。对于您每次运行write_pandas(),它只会将数据帧追加到您指定的表中。

另一方面,如果您使用df.to_sql(..., method=pd_writer)将 pandas 数据帧写入雪花,它会自动为您创建表,如果表已经存在,您可以使用to_sql()中的if_exists指定不同的行为-追加、替换或失败。

相关文章