简体   繁体   English

雪花 - 每次合并时会自动创建哪种类型的舞台表?

[英]Snowflake - which type of stage table is created automatically on each Merge into?

I want to write a Spark DataFrame into a Snowflake table.我想将 Spark DataFrame 写入雪花表。 I'm using a Snowflake connector for Spark and will pass a "query" option with the MERGE into statement like this:我正在为 Spark 使用Snowflake 连接器,并将通过 MERGE 将“查询”选项传递给如下语句:

merge_query =  "merge into target_table using stage_table 
        on target_table.id = stage_table.id
        when matched then 
        update set target_table.description = stage_table.description"

df.write
    .format(SNOWFLAKE_SOURCE_NAME)
    .options(sfOptions)
    .option("query", "merge_query")
    .mode(SaveMode.Overwrite)
    .save()

I don't have any external source table and want to find a way to overwrite stage data every time and then merge it to the target table.我没有任何外部源表,并且想找到一种方法来每次都覆盖阶段数据,然后将其合并到目标表中。 But I don't quite understand which type of stage should I use in this case.但我不太明白在这种情况下我应该使用哪种类型的舞台。 The documentation on Snowflake table stages doesn't specify what type is suitable when using MERGE INTO. Snowflake 表阶段的文档没有指定使用 MERGE INTO 时适合的类型。 I need something like a temporary stage table created automatically by Snowflake.我需要像 Snowflake 自动创建的临时舞台表之类的东西。

For the above example, will the stage_table be created automatically?对于上面的例子, stage_table会自动创建吗? And how should it be named if I don't want to create any stage table explicitly?如果我不想显式创建任何阶段表,它应该如何命名?

There is now way for automatically creating any table.现在有自动创建任何表的方法。 What you can do is in your program, create a temporary table, then load the data into that table and do the merge.您可以在程序中创建一个临时表,然后将数据加载到该表中并进行合并。 Temporary table are only available to the session and will be automatically deleted as soon as the session ends(which means as soon as your job ends).临时表仅对 session 可用,并且将在 session 结束时自动删除(这意味着一旦您的工作结束)。 Session tables are not visible to any other sessions. Session 表对任何其他会话不可见。 you can create temporary table as below您可以如下创建临时表

CREATE TEMPORARY TABLE <STG_TABLE_NAME>(FILED 1 VARCHAR, ...)

Hope this work for you.希望这对你有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM