โ03-10-2023 12:32 AM
Does Spark support multi statement writes to Snowflake in a single session? To elaborate, I have a requirement where I need to do
I want to wrap these both into a single transaction so that I could get Consistency here. I can't use overwrite mode as it will overwrite my entire table in Snowflake. I have seen runQuery of sfutils support multiStatements but it is more to handle data within Snowflake and not from Databricks to Snowflake.
Thanks,
Vignesh
โ03-21-2023 05:16 AM
In my analysis, I got the below understanding
โ03-10-2023 02:53 AM
are you looking for something like a merge (upsert) or a replaceWhere?
โ03-10-2023 04:16 AM
Yes. It's kind of replace where. My input tables are in Databricks layer. So I join them and write to a dataframe. Then I want to write this dataframe to Snowflake table by selectively deleting certain data as I have separate pipeline for different regions. So my overwrite on Snowflake table should only be for that region.
โ03-10-2023 04:40 AM
The only way this can be done in a single command is if snowflake has something like a replaceWhere. I did some searching but did not find anything.
โ03-10-2023 04:45 AM
Yes. I have tried the DELETE command using sfutils runQuery and then my data insertion using df.write method. They are captured in different sessions with two different session id in Snowflake. I basically want to wrap these two statements as a single transaction
โ03-10-2023 05:15 AM
if snowflake does not have the possibility, it is not possible in spark either.
โ03-10-2023 04:40 AM
Hi @Vigneshraja Palanirajโ , Could you please check the below document if this meets your use case
https://docs.databricks.com/sql/language-manual/delta-merge-into.html
โ03-10-2023 04:42 AM
Hi @Lakshay Goelโ . Thanks for your response. This option is more about when you want to update your delta table that is existing in Databricks layer itself. But I'm looking for the option when I want to write to Snowflake with dataframe write API using Spark snowflake connector
โ03-21-2023 05:16 AM
In my analysis, I got the below understanding
Join a Regional User Group to connect with local Databricks users. Events will be happening in your city, and you wonโt want to miss the chance to attend and share knowledge.
If there isnโt a group near you, start one and help create a community that brings people together.
Request a New Group