This is an automated email from the ASF dual-hosted git repository.

HyukjinKwon pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/spark-connect-rust.git


The following commit(s) were added to refs/heads/master by this push:
     new 964e849f [SPARK-61223][CONNECT][PYTHON] Set only the named options of 
DataFrameReader.parquet, as PySpark does
964e849f is described below

commit 964e849fb773037c89d71865a0fd94db29cdd4c3
Author: Hyukjin Kwon <[email protected]>
AuthorDate: Mon Nov 9 17:30:05 2026 +0900

    [SPARK-61223][CONNECT][PYTHON] Set only the named options of 
DataFrameReader.parquet, as PySpark does
    
    ### What changes were proposed in this pull request?
    
    [SPARK-61223](https://issues.apache.org/jira/browse/SPARK-61223): Make 
`DataFrameReader.parquet(*paths, **options)` apply only the seven options that 
PySpark applies.
    
    `DataFrameReader.parquet` set every keyword option on the reader. PySpark's 
`parquet` sets `mergeSchema`, `pathGlobFilter`, `recursiveFileLookup`, 
`modifiedBefore`, `modifiedAfter`, `datetimeRebaseMode` and `int96RebaseMode` 
(in that order) and ignores the others, so the other keys are not in the 
reader's `_options` afterwards either. The method now sets only these seven, as 
`orc` already follows its PySpark counterpart.
    
    The parameters (names, kinds, defaults) of the other reader and writer 
methods, and of the streaming reader and writer, were compared with official 
PySpark 4.3.0: no other format method takes a `**options` catch-all where 
PySpark takes named options only.
    
    ### Why are the changes needed?
    
    A keyword that PySpark ignores changed the result of a read here. With 
`ignoreCorruptFiles=True`, PySpark still fails on a corrupt Parquet footer 
(`FAILED_READ_FILE.CANNOT_READ_FILE_FOOTER`), but this client skipped the file 
and then failed with `UNABLE_TO_INFER_SCHEMA`. After `spark.read.parquet(path, 
ignoreCorruptFiles=True)`, the reader's `_options` is `{}` in PySpark and was 
`{'ignoreCorruptFiles': 'true'}` here.
    
    ### Does this PR introduce _any_ user-facing change?
    
    Yes. `parquet()` ignores the keyword options that PySpark ignores, and its 
reader keeps only the seven named options.
    
    ### How was this patch tested?
    
    - Added `test_parquet_sets_only_its_options_as_pyspark` to 
`test_dropin_offline.py`. It checks the reader's `_options` and `_format` after 
`parquet()` with named, unknown and None keywords, on a reader with a prior 
option. It fails without this change (the `_options` keep `header` and 
`ignoreCorruptFiles`) and passes with it. The same `_options` were checked 
against official PySpark 4.3.0 on a live Connect server.
    - Against official PySpark 4.3.0 on a live server, 
`ignoreCorruptFiles=True` on a corrupt Parquet file gives 
`FAILED_READ_FILE.CANNOT_READ_FILE_FOOTER` in both clients.
    - The lib tests of both crates (658 passed), the build of all tests, also 
with `wasm-udf`, the offline Python suites (2704 passed, 8 skipped), and the 
live drop-in and Arrow suites (224 passed) and live cases (12 passed) against a 
local Spark 4.3.0 server. Clippy reports no diagnostics in the changed lines.
    
    ### Was this patch authored or co-authored using generative AI tooling?
    
    Generated-by: Claude Opus 5.5
    
    This pull request and its description were written by Isaac.
    
    Closes #405 from HyukjinKwon/SPARK-61223-fu-p7.
    
    Authored-by: Hyukjin Kwon <[email protected]>
    Signed-off-by: Hyukjin Kwon <[email protected]>
---
 crates/pyspark-rs/src/readwriter.rs | 26 +++++++++++++++++---------
 python/tests/test_dropin_offline.py | 24 ++++++++++++++++++++++++
 2 files changed, 41 insertions(+), 9 deletions(-)

diff --git a/crates/pyspark-rs/src/readwriter.rs 
b/crates/pyspark-rs/src/readwriter.rs
index 8ffb1c3d..a61d1893 100644
--- a/crates/pyspark-rs/src/readwriter.rs
+++ b/crates/pyspark-rs/src/readwriter.rs
@@ -30,12 +30,6 @@ impl PyDataFrameReader {
         PyDataFrameReader { inner: reader }
     }
 
-    /// A copy of the current reader with per-call `**options` applied 
(skipping
-    /// None, lowercasing bools), for a format-specific read.
-    fn with_opts(&self, options: Option<&Bound<'_, PyDict>>) -> 
PyResult<DataFrameReader> {
-        apply_options(self.inner.clone(), options, false)
-    }
-
     /// Keep the options of a format-specific read on this reader, as PySpark 
does
     /// (its `json`/`csv`/... set the options and the format on `self`, then 
`load`).
     /// Called only after every argument was validated, so a failed call 
leaves the
@@ -482,15 +476,29 @@ impl PyDataFrameReader {
         self.read_or_parse(r, "json", spark_connect::plan::ParseFormat::Json, 
path)
     }
 
-    /// Read Parquet file(s).
+    /// Read Parquet file(s). As PySpark's `parquet(*paths, **options)`, only 
the options
+    /// `mergeSchema`, `pathGlobFilter`, `recursiveFileLookup`, 
`modifiedBefore`,
+    /// `modifiedAfter`, `datetimeRebaseMode` and `int96RebaseMode` of 
`options` are set, and
+    /// the others are ignored.
     #[pyo3(signature = (*paths, **options))]
     fn parquet(
         &mut self,
         paths: Vec<Bound<'_, PyAny>>,
         options: Option<&Bound<'_, PyDict>>,
     ) -> PyResult<PyDataFrame> {
-        // As PySpark's `parquet(*paths)`, of every path.
-        let r = self.with_opts(options)?;
+        let mut r = self.inner.clone();
+        for name in [
+            "mergeSchema",
+            "pathGlobFilter",
+            "recursiveFileLookup",
+            "modifiedBefore",
+            "modifiedAfter",
+            "datetimeRebaseMode",
+            "int96RebaseMode",
+        ] {
+            let value = options.map(|o| 
o.get_item(name)).transpose()?.flatten();
+            r = set_opt(r, name, value.as_ref())?;
+        }
         let paths = path_list(&paths)?;
         self.commit(&r, "parquet");
         Ok(PyDataFrame::new(r.format("parquet").load_paths(paths)))
diff --git a/python/tests/test_dropin_offline.py 
b/python/tests/test_dropin_offline.py
index 24aba59f..41c4f50a 100644
--- a/python/tests/test_dropin_offline.py
+++ b/python/tests/test_dropin_offline.py
@@ -1677,6 +1677,30 @@ def 
test_streaming_query_manager_wrapper_has_listener_api():
 
 # --------------------------------------------------------------------------- 
udf / udtf
 
+def test_parquet_sets_only_its_options_as_pyspark(mock_connect):
+    # As PySpark's DataFrameReader.parquet(*paths, **options): of the keyword 
options only
+    # mergeSchema, pathGlobFilter, recursiveFileLookup, modifiedBefore, 
modifiedAfter,
+    # datetimeRebaseMode and int96RebaseMode are set on the reader, and the 
others are ignored.
+    spark, _ = mock_connect
+    reader = spark.read
+    reader.option("keep", "1")
+    df = reader.parquet(
+        "/tmp/parquet",
+        mergeSchema=True,
+        ignoreCorruptFiles=True,
+        header=True,
+        datetimeRebaseMode="LEGACY",
+        pathGlobFilter=None,
+    )
+    assert df is not None
+    assert reader._format == "parquet"
+    assert reader._options == {"keep": "1", "mergeSchema": "true", 
"datetimeRebaseMode": "LEGACY"}
+
+    reader = spark.read
+    reader.parquet("/tmp/parquet", ignoreCorruptFiles=True)
+    assert reader._options == {}
+
+
 def test_udf_construction_and_call():
     from pyspark.sql import functions as F
     from pyspark.sql.udf import UserDefinedFunction


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

Reply via email to