基本上,我想做的是使用信息模式生成一个drop命令的数据帧,然后我想迭代并执行这些命令。
将雪花.snowpark导入为snowpark
def-main(会话:snowpark.session):
drop_commands = session.sql(""" SELECT 'DROP ' || table_type || ' if exists <database>.' || table_schema || '.' || table_name || ';' as drop_command
FROM <database>.INFORMATION_SCHEMA.TABLES
WHERE table_catalog = '<database>'
and table_schema in '<schema>'""").collect()
for iter,row in df:
session.sql(row['drop_command']).collect()
# drop_commands.show()
# Return value will appear in the Results tab.
return drop_commands
我预计drop_commands对象将作为数据帧返回,然后循环将遍历我使用查询告诉它的每个drop命令和drop snowflake对象。当我注释掉循环并去掉drop_commands定义末尾的.collect()时,我可以在结果中看到返回的数据帧。。。然而,这与Snowflake现有的文档(*.collect()执行sql*)相矛盾。我也尝试了不同版本的循环,因为我读到了雪上乐园和熊猫数据帧之间的差异,但都无济于事。
请注意,无论是否有更简单的方法来清除某些表/架构/数据库,我都希望解决这些雪公园问题——然而,如果有人知道如何通过编程来做到这一点,那也会是很好的反馈。