You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@spark.apache.org by "Sai Krishna Chaitanya Chaganti (Jira)" <ji...@apache.org> on 2020/04/19 09:36:00 UTC
[jira] [Comment Edited] (SPARK-31375) Overwriting into dynamic
partitions is appending data in pyspark
[ https://issues.apache.org/jira/browse/SPARK-31375?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17086877#comment-17086877 ]
Sai Krishna Chaitanya Chaganti edited comment on SPARK-31375 at 4/19/20, 9:35 AM:
----------------------------------------------------------------------------------
[~hyukjin.kwon] Hope the below helps to reproduce, let me know if it is still not clear.
_spark.conf.set('spark.sql.sources.partitionOverwriteMode', 'dynamic')_
_df - computed/source df._
_database.target_table_ _-> has some records already -> count = 200._
_df.count() ==> 200._
_step 1 - df.write.mode('overwrite').format('parquet').insertInto("__database.target_table__") ==> this should result in 200 records right?_
_## after step 1 count the number of records in table._
_spark.table("__database.target_table__").count() ==> 400 ( Records are being appended here, instead of overwrite)_
_###if step-1 is modified to below_
_df.write.mode('overwrite').format('parquet').insertInto("__database.target_table__",overwrite=True)_
_spark.table(__"__database.target_table__").count() ==> 200 (Overwrite is happening after explicitly mentioning the parameter.)_
_"__database.target_table__"_ _is an external table and data is stored in s3._
_I could've included code, but I found this behaviour in client environment. So I have my limitations._
Step 1 should help you to reproduce..
was (Author: chaitanya chaganti):
[~hyukjin.kwon] Hope the below helps to reproduce, let me know if it is still not clear.
_spark.conf.set('spark.sql.sources.partitionOverwriteMode', 'dynamic')_
_df - computed/source df._
_database.target_table_ _-> has some records already -> count = 200._
_df.count() ==> 200._
_step 1 - df.write.mode('overwrite').format('parquet').insertInto("__database.target_table__") ==> this should result in 200 records right?_
_## after step 1 count the number of records in table._
_spark.table("__database.target_table__").count() ==> 400 ( Records are being appended here, instead of overwrite)_
_###if step-1 is modified to below_
_df.write.mode('overwrite').format('parquet').insertInto("__database.target_table__",overwrite=True)_
_spark.table(__"__database.target_table__").count() ==> 200 (Overwrite is happening after explicitly mentioning the parameter.)_
_"__database.target_table__"_ _is an external table and data is stored in s3._
_I could've included code, but I found this behaviour in client environment. So I have my limitations._
> Overwriting into dynamic partitions is appending data in pyspark
> ----------------------------------------------------------------
>
> Key: SPARK-31375
> URL: https://issues.apache.org/jira/browse/SPARK-31375
> Project: Spark
> Issue Type: Bug
> Components: PySpark, SQL
> Affects Versions: 2.4.3
> Environment: databricks, s3, EMR, PySpark.
> Reporter: Sai Krishna Chaitanya Chaganti
> Priority: Major
>
> While overwriting data in specific partitions using insertInto , spark is appending data to specific partitions though the mode is overwrite. Below property is set in config to ensure that we don't overwrite all partitions. If the below property is set to static it is truncating and inserting the data.
> _spark.conf.set('spark.sql.sources.partitionOverwriteMode', 'dynamic')_
> _df.write.mode('overwrite').format('parquet').insertInto(<db>.<tbl>)_
> However if the above statement is changed to
> _df.write.mode('overwrite').format('parquet').insertInto(<db>.<tbl>,overwrite=True)_
> It starts behaving correct, I mean overwrites the data into specific partition.
> It seems though the save mode has been mentioned earlier, precedence is given to the parameter set in insertInto method call. +_*insertInto(<db>.<tbl>,overwrite=True)*_+
> It is happening in pyspark
--
This message was sent by Atlassian Jira
(v8.3.4#803005)
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@spark.apache.org
For additional commands, e-mail: issues-help@spark.apache.org