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 1dc7d7dd [SPARK-61521][CONNECT][PYTHON] Keep the settings of a reader 
or writer whose path is not valid, as PySpark does
1dc7d7dd is described below

commit 1dc7d7ddb7d341d24a9cba8629506694768138ee
Author: Hyukjin Kwon <[email protected]>
AuthorDate: Thu Nov 12 19:50:21 2026 +0900

    [SPARK-61521][CONNECT][PYTHON] Keep the settings of a reader or writer 
whose path is not valid, as PySpark does
    
    ### What changes were proposed in this pull request?
    
    The batch readers and writers of the Python client, and 
`DataStreamWriter.start`, now set the settings of a call (the format, the 
options, the schema, the mode, `partitionBy`, the query name) before they check 
its path, as PySpark does. So a call whose path is not a str keeps them on the 
reader or writer.
    
    - Writers: `save` and `parquet`/`json`/`csv`/`orc`/`text`/`xml` of 
`DataFrameWriter` and `DataStreamWriter.start` take the path as any object, and 
check it after the settings are on the writer. A path that is not a str raises 
the `TypeError` that PySpark's default protobuf backend (upb) raises for it, 
"bad argument type for built-in operation".
    - Readers: `text`, `parquet`, `orc`, `load`, and the str or list branch of 
`json`/`csv`/`xml`, put the format and the options (and, for `load`, the 
schema) on the reader before the path is checked. `json` and `xml` keep their 
options when the path is of another type, and `xml` keeps its schema, as 
PySpark's do.
    
    ### Why are the changes needed?
    
    PySpark sets the settings first and fails at the path. The drop-in checked 
the path while it extracted the arguments, before any setting, so a call that 
failed kept none of them, and the next call of the same writer or reader 
differed:
    
    ```python
    w = spark.range(1).write.option("compression", "gzip")
    try:
        w.json(123)
    except TypeError:
        pass
    w.mode("overwrite").save(path)   # PySpark 4.3.0 writes json.gz; before 
this change: snappy Parquet
    
    q = spark.readStream.format("rate").load().writeStream
    try:
        q.start(123, format="memory", queryName="q")
    except TypeError:
        pass
    q.start()   # PySpark starts the memory query "q"; before: 
[_LEGACY_ERROR_TEMP_2047] 'path' is not specified
    
    r = spark.read.option("wholetext", True)
    try:
        r.text(123)
    except AssertionError:
        pass
    # PySpark: r._options == {'wholetext': 'false'}, r._format == 'text'; 
before: unchanged
    ```
    
    A path that UTF-8 cannot encode keeps raising the `UnicodeEncodeError` of 
upb, as PySpark does, and is not changed here. This is a follow-up of 
SPARK-61057 (#547), whose stream reader already keeps its settings. The writer 
side was found by another review.
    
    ### Does this PR introduce _any_ user-facing change?
    
    Yes. After a call whose path is not a str fails, the next call of the same 
reader or writer uses its settings, as in PySpark. The `TypeError` of a writer 
or stream `start` path that is not a str now has PySpark's (upb) message.
    
    ### How was this patch tested?
    
    - Four new offline tests in `python/tests/test_dropin_offline.py`, which 
fail without the change: the error of a path that is not a str (int, float, 
list) for every writer method and stream `start`, and the settings that the 
readers, the writers and the stream writer keep after such a call.
    - Probes of the reference client under upb and of this one: the same first 
error, class and message, for every writer method and stream `start` with an 
int, float, `pathlib.Path` or list path; the same result for a later 
`save`/`start` (json.gz, csv, snappy Parquet, zstd ORC, a memory query); the 
same reader state.
    - The offline suite (1906 passed) and `test_dropin_e2e.py` against a Spark 
4.3.0 server (271 passed) under upb, the Rust library tests, the `--no-run` 
builds (with and without `wasm-udf`), `cargo fmt --check`, 
`scripts/audit_no_stubs.sh` and the ruff gates.
    
    ### 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 #559 from HyukjinKwon/SPARK-61521-path-order.
    
    Authored-by: Hyukjin Kwon <[email protected]>
    Signed-off-by: Hyukjin Kwon <[email protected]>
---
 crates/pyspark-rs/src/dataframe.rs  |  38 ++++++++-----
 crates/pyspark-rs/src/readwriter.rs |  70 +++++++++++++++++-------
 crates/pyspark-rs/src/streaming.rs  |   6 ++-
 python/tests/test_dropin_offline.py | 104 ++++++++++++++++++++++++++++++++++++
 4 files changed, 184 insertions(+), 34 deletions(-)

diff --git a/crates/pyspark-rs/src/dataframe.rs 
b/crates/pyspark-rs/src/dataframe.rs
index 953498e7..155eb5b0 100644
--- a/crates/pyspark-rs/src/dataframe.rs
+++ b/crates/pyspark-rs/src/dataframe.rs
@@ -3715,15 +3715,17 @@ impl PyDataFrameWriter {
     fn save(
         &self,
         py: Python<'_>,
-        path: Option<String>,
+        path: Option<&Bound<'_, PyAny>>,
         format: Option<&str>,
         mode: Option<&str>,
         partitionBy: Option<&Bound<'_, PyAny>>,
         options: Option<&Bound<'_, PyDict>>,
     ) -> PyResult<()> {
         let w = apply_write_common(self.inner.get(), format, mode, 
partitionBy, options)?;
-        // PySpark sets the inline format/mode/partitionBy/options on the 
writer itself.
+        // PySpark sets the inline format/mode/partitionBy/options on the 
writer itself, before
+        // it checks the path.
         self.inner.set(w.clone());
+        let path = path.map(crate::readwriter::writer_path).transpose()?;
         interruptible(py, &w.spark_session(), || {
             w.save(path.as_deref()).map_err(Box::new)
         })
@@ -3774,7 +3776,7 @@ impl PyDataFrameWriter {
     fn parquet(
         &self,
         py: Python<'_>,
-        path: &str,
+        path: &Bound<'_, PyAny>,
         mode: Option<&Bound<'_, PyAny>>,
         partitionBy: Option<&Bound<'_, PyAny>>,
         compression: Option<&Bound<'_, PyAny>>,
@@ -3794,7 +3796,10 @@ impl PyDataFrameWriter {
         w = set_option_skip_none(w, "compression", compression)?;
         // PySpark sets the mode/options/format on the writer itself, then 
saves.
         self.inner.set(w.clone().format("parquet"));
-        interruptible(py, &w.spark_session(), || 
w.parquet(path).map_err(Box::new))
+        let path = crate::readwriter::writer_path(path)?;
+        interruptible(py, &w.spark_session(), || {
+            w.parquet(&path).map_err(Box::new)
+        })
     }
 
     /// Write as JSON - full pyspark signature; each named option is
@@ -3804,7 +3809,7 @@ impl PyDataFrameWriter {
     fn json(
         &self,
         py: Python<'_>,
-        path: &str,
+        path: &Bound<'_, PyAny>,
         mode: Option<&Bound<'_, PyAny>>,
         compression: Option<&Bound<'_, PyAny>>,
         dateFormat: Option<&Bound<'_, PyAny>>,
@@ -3830,7 +3835,8 @@ impl PyDataFrameWriter {
         )?;
         // PySpark sets the mode/options/format on the writer itself, then 
saves.
         self.inner.set(w.clone().format("json"));
-        interruptible(py, &w.spark_session(), || 
w.json(path).map_err(Box::new))
+        let path = crate::readwriter::writer_path(path)?;
+        interruptible(py, &w.spark_session(), || 
w.json(&path).map_err(Box::new))
     }
 
     /// Write as CSV - full pyspark signature; each named option is
@@ -3840,7 +3846,7 @@ impl PyDataFrameWriter {
     fn csv(
         &self,
         py: Python<'_>,
-        path: &str,
+        path: &Bound<'_, PyAny>,
         mode: Option<&Bound<'_, PyAny>>,
         compression: Option<&Bound<'_, PyAny>>,
         sep: Option<&Bound<'_, PyAny>>,
@@ -3886,7 +3892,8 @@ impl PyDataFrameWriter {
         )?;
         // PySpark sets the mode/options/format on the writer itself, then 
saves.
         self.inner.set(w.clone().format("csv"));
-        interruptible(py, &w.spark_session(), || w.csv(path).map_err(Box::new))
+        let path = crate::readwriter::writer_path(path)?;
+        interruptible(py, &w.spark_session(), || 
w.csv(&path).map_err(Box::new))
     }
 
     /// Write as ORC - full pyspark signature; each named option is
@@ -3896,7 +3903,7 @@ impl PyDataFrameWriter {
     fn orc(
         &self,
         py: Python<'_>,
-        path: &str,
+        path: &Bound<'_, PyAny>,
         mode: Option<&Bound<'_, PyAny>>,
         partitionBy: Option<&Bound<'_, PyAny>>,
         compression: Option<&Bound<'_, PyAny>>,
@@ -3916,7 +3923,8 @@ impl PyDataFrameWriter {
         w = set_option_skip_none(w, "compression", compression)?;
         // PySpark sets the mode/options/format on the writer itself, then 
saves.
         self.inner.set(w.clone().format("orc"));
-        interruptible(py, &w.spark_session(), || w.orc(path).map_err(Box::new))
+        let path = crate::readwriter::writer_path(path)?;
+        interruptible(py, &w.spark_session(), || 
w.orc(&path).map_err(Box::new))
     }
 
     /// Write as TEXT - full pyspark signature; each named option is
@@ -3926,7 +3934,7 @@ impl PyDataFrameWriter {
     fn text(
         &self,
         py: Python<'_>,
-        path: &str,
+        path: &Bound<'_, PyAny>,
         compression: Option<&Bound<'_, PyAny>>,
         lineSep: Option<&Bound<'_, PyAny>>,
     ) -> PyResult<()> {
@@ -3934,7 +3942,8 @@ impl PyDataFrameWriter {
         w = set_options_skip_none(w, &[("compression", compression), 
("lineSep", lineSep)])?;
         // PySpark sets the mode/options/format on the writer itself, then 
saves.
         self.inner.set(w.clone().format("text"));
-        interruptible(py, &w.spark_session(), || 
w.text(path).map_err(Box::new))
+        let path = crate::readwriter::writer_path(path)?;
+        interruptible(py, &w.spark_session(), || 
w.text(&path).map_err(Box::new))
     }
 
     /// Write as XML - full pyspark signature; each named option is
@@ -3944,7 +3953,7 @@ impl PyDataFrameWriter {
     fn xml(
         &self,
         py: Python<'_>,
-        path: &str,
+        path: &Bound<'_, PyAny>,
         rowTag: Option<&Bound<'_, PyAny>>,
         mode: Option<&Bound<'_, PyAny>>,
         attributePrefix: Option<&Bound<'_, PyAny>>,
@@ -3982,7 +3991,8 @@ impl PyDataFrameWriter {
         )?;
         // PySpark sets the mode/options/format on the writer itself, then 
saves.
         self.inner.set(w.clone().format("xml"));
-        interruptible(py, &w.spark_session(), || w.xml(path).map_err(Box::new))
+        let path = crate::readwriter::writer_path(path)?;
+        interruptible(py, &w.spark_session(), || 
w.xml(&path).map_err(Box::new))
     }
 }
 
diff --git a/crates/pyspark-rs/src/readwriter.rs 
b/crates/pyspark-rs/src/readwriter.rs
index 114c5a6a..16ac91bb 100644
--- a/crates/pyspark-rs/src/readwriter.rs
+++ b/crates/pyspark-rs/src/readwriter.rs
@@ -36,8 +36,7 @@ impl PyDataFrameReader {
 
     /// 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
-    /// reader unchanged.
+    /// Called before the path is checked, as PySpark's `load` sets the format 
first.
     fn commit(&mut self, r: &DataFrameReader, format: &str) {
         self.inner = r.clone().format(format);
     }
@@ -46,15 +45,18 @@ impl PyDataFrameReader {
     /// of `path`, as PySpark's: a DataFrame of strings, which it parses as 
`parse_format`,
     /// keeping the schema and the options on this reader but not the format, 
or else a path
     /// or a list of them, which it loads as `format`. `csv`, unlike the 
others, passes any
-    /// other `path` to `load`, which asserts it.
+    /// other `path` to `load`, which asserts it. The schema, if any, is set 
only on those two
+    /// paths, as PySpark's, so a path of another type keeps the options alone.
     fn read_or_parse(
         &mut self,
         r: DataFrameReader,
+        schema: Option<&Bound<'_, PyAny>>,
         format: &str,
         parse_format: spark_connect::plan::ParseFormat,
         path: &Bound<'_, PyAny>,
     ) -> PyResult<PyDataFrame> {
         if let Ok(df) = path.extract::<PyRef<'_, PyDataFrame>>() {
+            let r = apply_optional_schema(r, schema)?;
             let parsed = r
                 .clone()
                 .parse(parse_format, &df.dataframe)
@@ -67,10 +69,13 @@ impl PyDataFrameReader {
             || path.is_instance_of::<pyo3::types::PyList>()
             || parse_format == spark_connect::plan::ParseFormat::Csv
         {
-            let paths = paths_of(path)?;
+            let r = apply_optional_schema(r, schema)?;
             self.commit(&r, format);
+            let paths = paths_of(path)?;
             return Ok(PyDataFrame::new(r.format(format).load_paths(paths)));
         }
+        // PySpark's options are set before the path is checked, so they stay 
on this reader.
+        self.inner = r;
         Err(not_expected_type(path, "path", "str, list, or DataFrame"))
     }
 }
@@ -104,6 +109,17 @@ fn path_list(paths: &[Bound<'_, PyAny>]) -> 
PyResult<Vec<String>> {
         .collect()
 }
 
+/// The path of a writer, a str, as its protobuf field takes it. Another type 
raises the TypeError
+/// of protobuf, which the upb backend of PySpark raises with this message.
+pub(crate) fn writer_path(path: &Bound<'_, PyAny>) -> PyResult<String> {
+    if path.is_instance_of::<pyo3::types::PyString>() {
+        return path.extract();
+    }
+    Err(pyo3::exceptions::PyTypeError::new_err(
+        "bad argument type for built-in operation",
+    ))
+}
+
 /// The columns of `df.write.bucketBy(numBuckets, col, *cols)` and 
`sortBy(col, *cols)`, as
 /// PySpark's: column names, or a list or tuple of them alone.
 pub(crate) fn writer_columns(
@@ -207,6 +223,17 @@ fn apply_reader_schema(r: DataFrameReader, v: &Bound<'_, 
PyAny>) -> PyResult<Dat
     Ok(r.schema(reader_schema(v)?))
 }
 
+/// Apply the `schema` argument of a format method, if there is one.
+fn apply_optional_schema(
+    r: DataFrameReader,
+    schema: Option<&Bound<'_, PyAny>>,
+) -> PyResult<DataFrameReader> {
+    match schema {
+        Some(v) => apply_reader_schema(r, v),
+        None => Ok(r),
+    }
+}
+
 #[pymethods]
 impl PyDataFrameReader {
     /// Set the schema, if any, and the options of `options` that are not 
None, through its own
@@ -312,9 +339,10 @@ impl PyDataFrameReader {
         if let Some(s) = schema {
             r = apply_reader_schema(r, s)?;
         }
-        let paths = path.map(paths_of).transpose()?.unwrap_or_default();
-        // PySpark's one-shot load sets format/schema/options on the reader 
itself.
+        // PySpark's one-shot load sets format/schema/options on the reader 
itself, before it
+        // checks the path.
         self.inner = r.clone();
+        let paths = path.map(paths_of).transpose()?.unwrap_or_default();
         Ok(PyDataFrame::new(r.load_paths(paths)))
     }
 
@@ -367,9 +395,6 @@ impl PyDataFrameReader {
         useUnsafeRow: Option<&Bound<'_, PyAny>>,
     ) -> PyResult<PyDataFrame> {
         let mut r = self.inner.clone();
-        if let Some(v) = schema {
-            r = apply_reader_schema(r, v)?;
-        }
         r = set_options_skip_none(
             r,
             &[
@@ -402,7 +427,13 @@ impl PyDataFrameReader {
                 ("useUnsafeRow", useUnsafeRow),
             ],
         )?;
-        self.read_or_parse(r, "json", spark_connect::plan::ParseFormat::Json, 
path)
+        self.read_or_parse(
+            r,
+            schema,
+            "json",
+            spark_connect::plan::ParseFormat::Json,
+            path,
+        )
     }
 
     /// Read Parquet file(s). As PySpark's `parquet(*paths, **options)`, only 
the options
@@ -428,8 +459,8 @@ impl PyDataFrameReader {
             let value = options.map(|o| 
o.get_item(name)).transpose()?.flatten();
             r = set_option_skip_none(r, name, value.as_ref())?;
         }
-        let paths = path_list(&paths)?;
         self.commit(&r, "parquet");
+        let paths = path_list(&paths)?;
         Ok(PyDataFrame::new(r.format("parquet").load_paths(paths)))
     }
 
@@ -475,9 +506,6 @@ impl PyDataFrameReader {
         unescapedQuoteHandling: Option<&Bound<'_, PyAny>>,
     ) -> PyResult<PyDataFrame> {
         let mut r = self.inner.clone();
-        if let Some(v) = schema {
-            r = apply_reader_schema(r, v)?;
-        }
         r = set_options_skip_none(
             r,
             &[
@@ -515,7 +543,13 @@ impl PyDataFrameReader {
                 ("unescapedQuoteHandling", unescapedQuoteHandling),
             ],
         )?;
-        self.read_or_parse(r, "csv", spark_connect::plan::ParseFormat::Csv, 
path)
+        self.read_or_parse(
+            r,
+            schema,
+            "csv",
+            spark_connect::plan::ParseFormat::Csv,
+            path,
+        )
     }
 
     /// Read ORC file(s) - full pyspark signature; each named option is
@@ -542,8 +576,8 @@ impl PyDataFrameReader {
                 ("modifiedAfter", modifiedAfter),
             ],
         )?;
-        let paths = paths_of(path)?;
         self.commit(&r, "orc");
+        let paths = paths_of(path)?;
         Ok(PyDataFrame::new(r.format("orc").load_paths(paths)))
     }
 
@@ -579,8 +613,8 @@ impl PyDataFrameReader {
                 ("modifiedAfter", modifiedAfter),
             ],
         )?;
-        let paths = paths_of(paths)?;
         self.commit(&r, "text");
+        let paths = paths_of(paths)?;
         Ok(PyDataFrame::new(r.format("text").load_paths(paths)))
     }
 
@@ -638,7 +672,7 @@ impl PyDataFrameReader {
                 ("locale", locale),
             ],
         )?;
-        self.read_or_parse(r, "xml", spark_connect::plan::ParseFormat::Xml, 
path)
+        self.read_or_parse(r, None, "xml", 
spark_connect::plan::ParseFormat::Xml, path)
     }
 
     /// Read from a JDBC source. Mirrors `DataFrameReader.jdbc(url, table, 
column=None,
diff --git a/crates/pyspark-rs/src/streaming.rs 
b/crates/pyspark-rs/src/streaming.rs
index c2b5d953..953041dd 100644
--- a/crates/pyspark-rs/src/streaming.rs
+++ b/crates/pyspark-rs/src/streaming.rs
@@ -980,7 +980,7 @@ impl PyDataStreamWriter {
     fn start(
         &self,
         py: Python<'_>,
-        path: Option<&str>,
+        path: Option<&Bound<'_, PyAny>>,
         format: Option<&str>,
         outputMode: Option<&str>,
         partitionBy: Option<&Bound<'_, PyAny>>,
@@ -988,10 +988,12 @@ impl PyDataStreamWriter {
         options: Option<&Bound<'_, PyDict>>,
     ) -> PyResult<PyStreamingQuery> {
         let writer = self.apply_write_opts(format, outputMode, partitionBy, 
queryName, options)?;
+        // PySpark's start sets these on the writer before it checks the path.
+        let path = path.map(crate::readwriter::writer_path).transpose()?;
         // Memory/console/foreach sinks take no path; the core treats "" as 
unset.
         let query = interruptible(py, &writer.spark_session(), || {
             writer
-                .start_with_event_handler(path.unwrap_or(""), 
post_started_event)
+                .start_with_event_handler(path.as_deref().unwrap_or(""), 
post_started_event)
                 .map_err(Box::new)
         })?;
         Ok(PyStreamingQuery::new(query))
diff --git a/python/tests/test_dropin_offline.py 
b/python/tests/test_dropin_offline.py
index 4c0760ae..305d5b50 100644
--- a/python/tests/test_dropin_offline.py
+++ b/python/tests/test_dropin_offline.py
@@ -6961,6 +6961,110 @@ def 
test_strings_that_utf8_cannot_encode_raise_value_error_in_option_keys_conf_a
     assert service.execute_requests == []
 
 
+def 
test_writers_and_readers_reject_a_path_that_is_not_a_str_as_pyspark(mock_connect):
+    # As PySpark's upb protobuf backend, which raises a TypeError of this 
message for a path
+    # that is not a str, in every writer method and in DataStreamWriter.start.
+    spark, service = mock_connect
+    df = spark.range(1)
+    stream = spark.readStream.format("rate").load().writeStream
+    message = "bad argument type for built-in operation"
+    for path in [123, 1.5, ["a", 1]]:
+        for call in [
+            lambda: df.write.save(path),
+            lambda: df.write.json(path),
+            lambda: df.write.csv(path),
+            lambda: df.write.parquet(path),
+            lambda: df.write.orc(path),
+            lambda: df.write.text(path),
+            lambda: df.write.xml(path),
+            lambda: stream.start(path),
+        ]:
+            with pytest.raises(TypeError) as error:
+                call()
+            assert type(error.value) is TypeError and str(error.value) == 
message
+    assert service.execute_requests == []
+
+
+def 
test_readers_keep_their_settings_when_the_path_is_not_a_str_as_pyspark(mock_connect):
+    # As PySpark, whose format readers set the options and the format before 
they check the path,
+    # which is an AssertionError for a path that is not a str.
+    from pyspark.errors import PySparkTypeError
+
+    spark, _ = mock_connect
+    reader = spark.read.option("wholetext", True)
+    with pytest.raises(AssertionError):
+        reader.text(123)
+    assert reader._format == "text" and reader._options == {"wholetext": 
"false"}
+    reader = spark.read.option("mergeSchema", True)
+    with pytest.raises(AssertionError):
+        reader.parquet(123)
+    assert reader._format == "parquet" and reader._options == {"mergeSchema": 
"true"}
+    reader = spark.read.option("sep", ";")
+    with pytest.raises(AssertionError):
+        reader.csv(123)
+    assert reader._format == "csv" and reader._options == {"sep": ";"}
+    # json and xml raise a PySparkTypeError, after their options, and xml's 
schema, which
+    # json does not set on a path of another type.
+    reader = spark.read
+    with pytest.raises(PySparkTypeError) as error:
+        reader.json(123, schema="a int", multiLine=True)
+    assert error.value.getCondition() == "NOT_EXPECTED_TYPE"
+    assert reader._format is None and reader._options == {"multiLine": "true"}
+    assert reader._schema == ""
+    reader = spark.read
+    with pytest.raises(PySparkTypeError):
+        reader.xml(123, schema="a int", rowTag="r")
+    assert reader._format is None and reader._options == {"rowTag": "r"}
+    assert reader._schema == "a int"
+
+
+def 
test_writers_keep_their_settings_when_the_path_is_not_a_str_as_pyspark(mock_connect):
+    # As PySpark, whose writer sets the settings of a call before it checks 
the path: a later
+    # save of the writer sends the format and the options of the failed call.
+    spark, service = mock_connect
+
+    def sent_write():
+        # ExecutePlanRequest.plan=3, Plan.command=2, Command.write_operation=2.
+        plan = parse_message(parse_message(service.execute_requests[-1])[3][0])
+        return parse_message(parse_message(plan[2][0])[2][0])
+
+    writer = spark.range(1).write.option("compression", "gzip")
+    with pytest.raises(TypeError):
+        writer.json(123)
+    writer.save("p")
+    # WriteOperation.source=2, and options=9, of entries of key=1 and value=2.
+    assert sent_write()[2] == [b"json"]
+    options = {parse_message(entry)[1][0]: parse_message(entry)[2][0] for 
entry in sent_write()[9]}
+    assert options == {b"compression": b"gzip"}
+
+    writer = spark.range(1).write.mode("overwrite")
+    with pytest.raises(TypeError):
+        writer.save(123, format="parquet")
+    writer.save("p")
+    # WriteOperation.source=2 and mode=5, of SAVE_MODE_OVERWRITE=2.
+    assert sent_write()[2] == [b"parquet"] and sent_write()[5] == [2]
+
+
+def 
test_stream_writers_keep_their_settings_when_the_path_is_not_a_str_as_pyspark(mock_connect):
+    # As PySpark, whose start sets the format, query name and output mode 
before it checks the
+    # path: a later start of the stream writer starts the query of the failed 
call's settings.
+    spark, service = mock_connect
+    # ExecutePlanResponse.write_stream_operation_start_result=8: query_id=1 
(id=1, run_id=2).
+    service.execute_payload = message_field(
+        8, message_field(1, message_field(1, "q") + message_field(2, "r")))
+    writer = spark.readStream.format("rate").load().writeStream
+    with pytest.raises(TypeError):
+        writer.start(123, format="memory", queryName="q", outputMode="append")
+    assert service.execute_requests == []
+    writer.start()
+    # ExecutePlanRequest.plan=3 -> Plan.command=2 -> 
Command.write_stream_operation_start=6.
+    plan = parse_message(parse_message(service.execute_requests[-1])[3][0])
+    start = parse_message(parse_message(plan[2][0])[6][0])
+    # WriteStreamOperationStart.format=2, output_mode=9, query_name=10.
+    assert start[2] == [b"memory"] and start[9] == [b"append"] and start[10] 
== [b"q"]
+    assert 11 not in start
+
+
 def test_functions_levenshtein():
     """Test levenshtein distance function."""
     from pyspark.sql import functions as F


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

Reply via email to