Snowpark表格创建失败,即使查询成功执行。

huangapple go评论53阅读模式
英文:

Snowpark table creation failing even query executed successfully

问题

我正在尝试在Snowpark中使用参数化值从另一个表创建表格

CREATE OR REPLACE PROCEDURE table_merge(DB varchar, SCHEMA varchar, TARGET_TABLE varchar, SRC_TABLE varchar)
  RETURNS STRING
  LANGUAGE PYTHON
  RUNTIME_VERSION = '3.8'
  PACKAGES = ('snowflake-snowpark-python')
  HANDLER = 'table_merge'
AS
$$
from snowflake.snowpark.functions import when_matched

def table_merge(session, DB, SCHEMA, TARGET_TABLE, SRC_TABLE):
  session.use_database(DB)
  session.use_schema(SCHEMA)
  session.sql(f"CREATE TABLE {DB}.{SCHEMA}.{TARGET_TABLE} LIKE {DB}.{SCHEMA}.{SRC_TABLE}")
  table_count = session.sql(f"SHOW TABLES LIKE {TARGET_TABLE}")
  return table_count.count()
$$;

表格未创建,并且结果返回0。当我单独运行查询时,甚至看不到表格。有解决方法吗?

英文:

I am trying to create a table from other table in snowpark using parameterized value

CREATE OR REPLACE PROCEDURE table_merge(DB varchar,SCHEMA varchar,TARGET_TABLE varchar, SRC_TABLE varchar)
  RETURNS STRING
  LANGUAGE PYTHON
  RUNTIME_VERSION = '3.8'
  PACKAGES = ('snowflake-snowpark-python')
  HANDLER = 'table_merge'
AS
$$
from snowflake.snowpark.functions import when_matched

def table_merge(session,DB,SCHEMA,TARGET_TABLE, SRC_TABLE ):
  session.use_database(DB)
  session.use_schema(SCHEMA)
  session.sql(f"CREATE TABLE {DB}.{SCHEMA}.{TARGET_TABLE} LIKE {DB}.{SCHEMA}.{SRC_TABLE}")
  table_count = session.sql(f"SHOW TABLES LIKE {TARGET_TABLE}")
  return table_count.count()
$$; 

The table is not creating and the result return 0. i even didn't see the table when i ran query alone

Any solution to this?

答案1

得分: 0

是的,我最终得到了使用Snowpark API创建永久表而不使用会话的答案。

source_table_df.write.mode("overwrite").save_as_table("my_new_table")
英文:

Yea i got the answer finally for creating a permanent table using snowpark API without using session

source_table_df.write.mode("overwrite").save_as_table("my_new_table")

答案2

得分: 0

source_table_df.write.mode("overwrite").save_as_table("my_new_table")

这种模式,overwrite,用于用新数据替换现有表的内容。如果表不存在,它将创建一个具有指定名称的新表。如果表已存在,则将表中的所有数据替换为新数据。

并没有明确指定必须是表的所有者,但根据我们的经验,似乎需要是表的所有者。

参考链接:https://medium.com/snowflake/snowpark-with-python-part-3-afef7071928d


<details>
<summary>英文:</summary>

source_table_df.write.mode("overwrite").save_as_table("my_new_table")

This mode, `overwrite`, is used to replace the contents of an existing table with the new data. If the table does not exist, it will create a new table with the given name. If the table exists, it replaces all the data in the table with the new data.

It does not specify anywhere I can find that you must be the table owner, but that is how we are experiencing it.

Reference: https://medium.com/snowflake/snowpark-with-python-part-3-afef7071928d

</details>



huangapple
  • 本文由 发表于 2023年6月1日 00:25:40
  • 转载请务必保留本文链接:https://go.coder-hub.com/76375570.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定