You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@spark.apache.org by gu...@apache.org on 2024/08/19 23:52:12 UTC
(spark) branch master updated: [SPARK-49263][CONNECT] Spark Connect python client: Consistently handle boolean Dataframe reader options
This is an automated email from the ASF dual-hosted git repository.
gurwls223 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/spark.git
The following commit(s) were added to refs/heads/master by this push:
new a6a62e564bed [SPARK-49263][CONNECT] Spark Connect python client: Consistently handle boolean Dataframe reader options
a6a62e564bed is described below
commit a6a62e564bed445ab0ad225e5a4c7074370d3970
Author: Hyukjin Kwon <gu...@apache.org>
AuthorDate: Tue Aug 20 08:51:59 2024 +0900
[SPARK-49263][CONNECT] Spark Connect python client: Consistently handle boolean Dataframe reader options
### What changes were proposed in this pull request?
Using `spark.read.option("Foo", True)` resulted in an uppercase `'True'` string in Python Spark Connect client, while in all other cases (scala with both Spark Connect and no Spark Connect, pyspark with no Spark Connect) it would be normalized to `'true'`. This is because `to_str` helper should be used instead of `str`.
### Why are the changes needed?
This is now inconsistent with other cases. Passing `"True"` as boolean options seems to be breaking Delta CDF reader (to be fixed separately, that it should be able to handle the literal case-insensitively)
### Does this PR introduce _any_ user-facing change?
No.
### How was this patch tested?
Unittest added
### Was this patch authored or co-authored using generative AI tooling?
No.
Closes #47790 from juliuszsompolski/SPARK-49263.
Lead-authored-by: Hyukjin Kwon <gu...@apache.org>
Co-authored-by: Hyukjin Kwon <gu...@gmail.com>
Co-authored-by: Julek Sompolski <Juliusz Sompolski>
Signed-off-by: Hyukjin Kwon <gu...@apache.org>
---
python/pyspark/sql/connect/plan.py | 8 ++++++--
python/pyspark/sql/connect/readwriter.py | 2 +-
python/pyspark/sql/tests/test_datasources.py | 1 +
3 files changed, 8 insertions(+), 3 deletions(-)
diff --git a/python/pyspark/sql/connect/plan.py b/python/pyspark/sql/connect/plan.py
index 25c6076c14fc..b9c60c04d0f0 100644
--- a/python/pyspark/sql/connect/plan.py
+++ b/python/pyspark/sql/connect/plan.py
@@ -281,9 +281,13 @@ class DataSource(LogicalPlan):
assert schema is None or isinstance(schema, str)
if options is not None:
+ new_options = {}
for k, v in options.items():
- assert isinstance(k, str)
- assert isinstance(v, str)
+ if v is not None:
+ assert isinstance(k, str)
+ assert isinstance(v, str)
+ new_options[k] = v
+ options = new_options
if paths is not None:
assert isinstance(paths, list)
diff --git a/python/pyspark/sql/connect/readwriter.py b/python/pyspark/sql/connect/readwriter.py
index 934399407e97..826cfdea8a9e 100644
--- a/python/pyspark/sql/connect/readwriter.py
+++ b/python/pyspark/sql/connect/readwriter.py
@@ -94,7 +94,7 @@ class DataFrameReader(OptionUtils):
schema.__doc__ = PySparkDataFrameReader.schema.__doc__
def option(self, key: str, value: "OptionalPrimitiveType") -> "DataFrameReader":
- self._options[key] = str(value)
+ self._options[key] = cast(str, to_str(value))
return self
option.__doc__ = PySparkDataFrameReader.option.__doc__
diff --git a/python/pyspark/sql/tests/test_datasources.py b/python/pyspark/sql/tests/test_datasources.py
index 9a4cf979f3a3..0d5d554a17be 100644
--- a/python/pyspark/sql/tests/test_datasources.py
+++ b/python/pyspark/sql/tests/test_datasources.py
@@ -212,6 +212,7 @@ class DataSourcesTestsMixin:
)
df = (
self.spark.read.option("header", "true")
+ .option("quote", None)
.schema(schema)
.csv(path, enforceSchema=False)
)
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@spark.apache.org
For additional commands, e-mail: commits-help@spark.apache.org