[ 
https://issues.apache.org/jira/browse/SPARK-62355?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

ASF GitHub Bot updated SPARK-62355:
-----------------------------------
    Labels: pull-request-available  (was: )

> Spark Connect Python client rejects DataFrameWriter.mode("errorifexists") and 
> mode("default")
> ---------------------------------------------------------------------------------------------
>
>                 Key: SPARK-62355
>                 URL: https://issues.apache.org/jira/browse/SPARK-62355
>             Project: Spark
>          Issue Type: Bug
>          Components: Connect, PySpark
>    Affects Versions: 4.3.0, 5.0.0
>            Reporter: Kohei Iwamasa
>            Priority: Minor
>              Labels: pull-request-available
>
> In the Spark Connect Python client, {{DataFrameWriter.mode("errorifexists")}} 
> and {{mode("default")}} fail at write time. Classic PySpark accepts both as 
> aliases of {{"error"}}.
> Reproduction ({{pyspark[connect]}} 4.3.0; also on master):
> {code:python}
> import tempfile, sys
> from pyspark.sql import SparkSession
> tmp = tempfile.mkdtemp()
> remote = len(sys.argv) > 1 and sys.argv[1] == "connect"
> b = SparkSession.builder.remote("local[1]") if remote else 
> SparkSession.builder.master("local[1]")
> spark = b.config("spark.ui.enabled", "false").getOrCreate()
> for mode in ("error", "errorifexists", "default"):
>     try:
>         spark.range(2).write.mode(mode).parquet(f"{tmp}/{mode}")
>         print(f"mode({mode!r}): ok")
>     except Exception as e:
>         print(f"mode({mode!r}): {type(e).__name__}: {e}")
> spark.stop()
> {code}
> Classic:
> {noformat}
> mode('error'): ok
> mode('errorifexists'): ok
> mode('default'): ok
> {noformat}
> Connect:
> {noformat}
> mode('error'): ok
> mode('errorifexists'): PySparkValueError: [UNSUPPORTED_OPERATION] 
> errorifexists is not supported.
> mode('default'): PySparkValueError: [UNSUPPORTED_OPERATION] default is not 
> supported.
> {noformat}
> Why it matters: the {{DataFrameWriter.mode}} docstring, which the Connect 
> client copies from classic PySpark, lists {{error}} or {{errorifexists}}. 
> Code that passes its tests on classic Spark fails on Spark Connect.
> Cause: {{WriteOperation.plan()}} in {{python/pyspark/sql/connect/plan.py}} 
> maps only {{"append"}}, {{"overwrite"}}, {{"error"}} and {{"ignore"}} to the 
> proto {{SaveMode}} and raises {{UNSUPPORTED_OPERATION}} otherwise. Classic 
> PySpark passes the string to Scala's {{DataFrameWriter.mode(String)}} 
> ({{sql/api}}), which the Scala Connect client also uses and which has:
> {code:scala}
> case "error" | "errorifexists" | "default" => mode(SaveMode.ErrorIfExists)
> {code}
> Proposal: map {{"errorifexists"}} and {{"default"}} to 
> {{SAVE_MODE_ERROR_IF_EXISTS}} as well, matching Scala. Other values still 
> raise {{UNSUPPORTED_OPERATION}}. The fix is a one-line change in {{plan.py}}; 
> I will open a PR with a test.
> Related (spark-connect-rust): SPARK-61101 notes that PySpark Connect raises 
> for {{"errorifexists"}}, and SPARK-61896 changed the Rust client to raise the 
> same way. Once this is fixed, the Rust client should accept 
> {{"errorifexists"}} again.



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to