You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Context: https://iceberg.apache.org/#spark-writes/#merge-into I see that merge into is the recommended writing pattern instead of Insert Overwrite. But there's no Dataframe/ DataSet Scala API equivalent and we have to resort to using SQL via Spark Sql.
It would be great to have it exposed like append, overwrite.
@huaxingao thanks for chiming in. Could you point me to the Dataframe/ DataSource API where the mergeInto is exposed? I was under the impression that only Delta has this implemented. CC @kbendick if I missed something.
@nssalian There isn't a mergeInto Dataframe/ DataSet API in Spark. The SQL syntax merge into is supported in Spark, though. I am just trying to figure out what exactly needs to be done in Spark to make this work. I might be able to implement that.
That's right. The request is the mergeInto Dataframe/ DataSet API in Spark, so that Iceberg could take advantage of it in the API rather than SQL. Not a blocker but would be great to have along side append, overwrite.
Reacted by Jinli Liang, myermakov and InJung Hwang
If this functionality is still required and Spark side is still pending, I might try to implement it (as a Scala developer I would really like to have the merge API).
I just need to have a chat with someone who knows the Scala code base to clarify some missing pieces in my analysis.
I see two possible implementations, both following the implicit approach.
Option 1:
implicits that extends DataSet[T] with a new method mergeTo(table,condition)
implicits that extends DataFrameWriterV2[T] with the following method:
The difference between the two approaches is in the syntax of the API: on the first one we generate a new 'mergeTo' method, on the other we refer to the already existing 'writeTo'.
Looking at the actual code base I see that a MergeInto operation has already been resolved in a Spark LogicalPlan, probably we could reuse this logic and just call the executePlan on the final merge call
I do think changing this in Spark is probably the best approach for adding the api to DataframeWriter but I also would be glad to see some code in the Iceberg repo giving us functionality until then. Because we expect this function may be deprecated when the Spark API becomes available, I think it makes sense to keep this as just a public static method rather than an implicit. This should make it a lot clearer when we deprecate and remove it for a Spark native alternative.
@RussellSpitzer
If the plan is to deprecate it in the near future in favour of the Spark native solution I completely understand the point of not creating a true Scala DSL.
Hello folks, Our data science community using DataFrame APIs quite heavily. Missing this merge functionality using Spark's DataFrame API is pushing back on adopting Iceberg against Delta. Is there any way we can move this up in priority list? Please help.
In future releases, there also has been an agreement to ship this natively in Spark. That said, nothing prevents us from having a temp solution inside Iceberg for now.
Hi @aokolnychyi
I will complete the MR with other test cases then let me know if you want to merge it or not. That's not an issue.
Anyway It was really fun for me to try to implement it.
Reacted by Vincent Chee Jia Hong, Manu Zhang, Robin Saini, Duo Xu, Jinli Liang, Jack O'Hara, ritaylor-r7, Michal Sitko, rwagenmaker, Anil Sadineni and 5 more
This issue has been automatically marked as stale because it has been open for 180 days with no activity. It will be closed in next 14 days if no further activity occurs. To permanently prevent this issue from being considered stale, add the label 'not-stale', but commenting on the issue is preferred when possible.
Activity
huaxingao commentedon Dec 8, 2021
@nssalian Just for my understanding. Spark has this Merge into table support. Anything else that needs to be implemented on OSS Spark side?
nssalian commentedon Dec 8, 2021
@huaxingao thanks for chiming in. Could you point me to the Dataframe/ DataSource API where the mergeInto is exposed? I was under the impression that only Delta has this implemented. CC @kbendick if I missed something.
huaxingao commentedon Dec 8, 2021
@nssalian There isn't a mergeInto Dataframe/ DataSet API in Spark. The SQL syntax merge into is supported in Spark, though. I am just trying to figure out what exactly needs to be done in Spark to make this work. I might be able to implement that.
nssalian commentedon Dec 8, 2021
That's right. The request is the mergeInto Dataframe/ DataSet API in Spark, so that Iceberg could take advantage of it in the API rather than SQL. Not a blocker but would be great to have along side append, overwrite.
nssalian commentedon Jan 5, 2022
@huaxingao , following up on this. Any update if this might be on the roadmap for Spark to add it part of the Dataframe,etc API?
RussellSpitzer commentedon Jan 5, 2022
I think we could add some implicits in Iceberg's Scala Modules outside of Spark as well. That might be a good path forward
huaxingao commentedon Jan 5, 2022
Sorry I didn't have a chance to check with the Spark SQL folks yet. Will do and get back to you this week.
huaxingao commentedon Jan 6, 2022
Yes, it is possible to add the
MergeAPI intoDataFrameWriterV2.kpe commentedon Aug 11, 2022
@huaxingao - wow, having a
Mergein theDataFrameWriterV2would be great - is this already tracked by the Spark folks, jira or issue we can monitor?manuzhang commentedon Nov 1, 2022
@huaxingao any update from Spark side?
giucris commentedon Mar 5, 2023
Hi @RussellSpitzer @huaxingao
If this functionality is still required and Spark side is still pending, I might try to implement it (as a Scala developer I would really like to have the merge API).
I just need to have a chat with someone who knows the Scala code base to clarify some missing pieces in my analysis.
I see two possible implementations, both following the implicit approach.
Option 1:
Option 2:
The difference between the two approaches is in the syntax of the API: on the first one we generate a new 'mergeTo' method, on the other we refer to the already existing 'writeTo'.
Looking at the actual code base I see that a MergeInto operation has already been resolved in a Spark LogicalPlan, probably we could reuse this logic and just call the executePlan on the final merge call
huaxingao commentedon Mar 6, 2023
Sorry I didn't have a chance to work on this yet.
I think it's probably better to support this in Spark directly. What do you think @RussellSpitzer?
RussellSpitzer commentedon Mar 6, 2023
I do think changing this in Spark is probably the best approach for adding the api to DataframeWriter but I also would be glad to see some code in the Iceberg repo giving us functionality until then. Because we expect this function may be deprecated when the Spark API becomes available, I think it makes sense to keep this as just a public static method rather than an implicit. This should make it a lot clearer when we deprecate and remove it for a Spark native alternative.
Maybe something like
IcebergMergeInto(Table).from(source).when(.....)
Let's also try to keep this api Java friendly.
giucris commentedon Mar 6, 2023
@RussellSpitzer
If the plan is to deprecate it in the near future in favour of the Spark native solution I completely understand the point of not creating a true Scala DSL.
If you want I can try to write something down.
RussellSpitzer commentedon Mar 6, 2023
I would really appreciate that, I think it's great to have it ASAP.
adarsh112 commentedon Mar 10, 2023
Waiting for Dataframe api for merge into. This is pretty basic not sure why is it not yet available.
abhinavofficial commentedon Apr 6, 2023
Hello folks, Our data science community using DataFrame APIs quite heavily. Missing this merge functionality using Spark's DataFrame API is pushing back on adopting Iceberg against Delta. Is there any way we can move this up in priority list? Please help.
RussellSpitzer commentedon Apr 6, 2023
The best way to get this done is to write a pull request. This is an oss project and everyone here is basically a volunteer.
aokolnychyi commentedon May 16, 2023
In future releases, there also has been an agreement to ship this natively in Spark. That said, nothing prevents us from having a temp solution inside Iceberg for now.
giucris commentedon May 17, 2023
Hi @aokolnychyi
I will complete the MR with other test cases then let me know if you want to merge it or not. That's not an issue.
Anyway It was really fun for me to try to implement it.
rdblue commentedon Sep 22, 2023
@aokolnychyi, is it possible to get the DataFrame API in Spark updated now that 3.5 has implementations for these plans?
huaxingao commentedon Dec 21, 2023
Spark
mergeIntoAPI is merged in 4.0.0.Example usage:
github-actions commentedon Aug 6, 2024
This issue has been automatically marked as stale because it has been open for 180 days with no activity. It will be closed in next 14 days if no further activity occurs. To permanently prevent this issue from being considered stale, add the label 'not-stale', but commenting on the issue is preferred when possible.
github-actions commentedon Aug 22, 2024
This issue has been closed because it has not received any activity in the last 14 days since being marked as 'stale'