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 b8927d88 [SPARK-61603][FOLLOWUP][CONNECT] Take any iterable in 
select_expr, summary, load_paths and fillna_map, and describe the column-list 
arguments of drop_columns, with_columns and grouping_sets
b8927d88 is described below

commit b8927d8804e543e815720a43b754049eeb59abc4
Author: Hyukjin Kwon <[email protected]>
AuthorDate: Fri Nov 13 14:28:43 2026 +0900

    [SPARK-61603][FOLLOWUP][CONNECT] Take any iterable in select_expr, summary, 
load_paths and fillna_map, and describe the column-list arguments of 
drop_columns, with_columns and grouping_sets
    
    ### What changes were proposed in this pull request?
    
    A follow-up of #598 (SPARK-61603), from a post-merge review:
    - `DataFrame::select_expr` and `summary`, and 
`DataFrameReader::load_paths`, which took a `Vec<&str>` or `Vec<String>`, take 
any iterable of names (`impl IntoIterator<Item = impl Into<String>>`), as the 
other list arguments do since SPARK-61603. So `df.select_expr(["id + 1"])` 
compiles. `fillna_map` takes any iterable of `(String, Value)` pairs, such as a 
`BTreeMap`; its names stay `String`s, so that `vec![]` and `("id".into(), 
value)` still infer their type. Every existing caller com [...]
    - The compatibility note:
      - The first list of `drop_columns` is of column references, as PySpark's 
`drop(F.col(name))`. A name of several columns is `AMBIGUOUS_REFERENCE`, and a 
dotted name refers to a nested field, which drops nothing.
      - Its second list is of plain names, as that of `drop`.
      - It describes the arguments of `with_columns` (pairs) and 
`grouping_sets` (iterables of iterables) as they are, and lists the newly 
changed methods.
    
    ### Why are the changes needed?
    
    To complete the column-list sweep of the Rust API, and to describe it 
accurately.
    
    ### Does this PR introduce _any_ user-facing change?
    
    Yes, in the Rust API. These methods take any iterable of names or pairs.
    
    ### How was this patch tested?
    
    - New unit tests of the changed methods; they fail to compile without the 
change.
    - The lib tests (674 passed), the build of all tests, and the builds of 
`pyspark-rs` and `examples`.
    - `check_doc_snippets.py` (59 snippets, 0 failures) and `cargo fmt --all 
--check`.
    
    ### 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 #613 from HyukjinKwon/SPARK-61603-followup.
    
    Authored-by: Hyukjin Kwon <[email protected]>
    Signed-off-by: Hyukjin Kwon <[email protected]>
---
 crates/spark-connect/src/dataframe.rs  | 69 ++++++++++++++++++++++++++++------
 crates/spark-connect/src/readwriter.rs | 32 +++++++++++++---
 docs/compatibility.md                  | 41 ++++++++++++--------
 3 files changed, 109 insertions(+), 33 deletions(-)

diff --git a/crates/spark-connect/src/dataframe.rs 
b/crates/spark-connect/src/dataframe.rs
index c1b85898..68836e9a 100644
--- a/crates/spark-connect/src/dataframe.rs
+++ b/crates/spark-connect/src/dataframe.rs
@@ -2077,14 +2077,17 @@ impl DataFrame {
         DataFrame::new(self.session.clone(), plan)
     }
 
-    /// Select with SQL expressions, mirroring `DataFrame.selectExpr`.
+    /// Select with SQL expressions, mirroring `DataFrame.selectExpr`, of any 
iterable of them.
     ///
     /// Each string is parsed as a SQL expression (e.g. `"id + 1 AS x"`), not 
treated
     /// as a bare column name - so it must go through `functions::expr` (an
     /// `ExpressionString` the server parses), not `col` (an unresolved 
attribute,
     /// which made `selectExpr("id + 1 AS x")` fail to resolve).
-    pub fn select_expr(&self, exprs: Vec<&str>) -> DataFrame {
-        let cols: Vec<Column> = exprs.iter().map(|e| 
crate::functions::expr(e)).collect();
+    pub fn select_expr<S: Into<String>>(&self, exprs: impl IntoIterator<Item = 
S>) -> DataFrame {
+        let cols: Vec<Column> = exprs
+            .into_iter()
+            .map(|e| crate::functions::expr(&e.into()))
+            .collect();
         self.select(cols)
     }
 
@@ -2165,10 +2168,15 @@ impl DataFrame {
         DataFrame::new(self.session.clone(), plan)
     }
 
-    /// Fill NA values per column from `(column, value)` pairs. Mirrors
-    /// `df.fillna({col: value, ...})`: the values are as those of 
[`DataFrame::fillna_value`],
-    /// and an empty map is a `CANNOT_BE_EMPTY` error, as PySpark raises.
-    pub fn fillna_map(&self, pairs: Vec<(String, crate::row::Value)>) -> 
Result<DataFrame> {
+    /// Fill NA values per column from `(column, value)` pairs, of any 
iterable of them, such as a
+    /// `Vec`, an array or a map of the names. Mirrors `df.fillna({col: value, 
...})`: the values
+    /// are as those of [`DataFrame::fillna_value`], and an empty map is a 
`CANNOT_BE_EMPTY`
+    /// error, as PySpark raises.
+    pub fn fillna_map(
+        &self,
+        pairs: impl IntoIterator<Item = (String, crate::row::Value)>,
+    ) -> Result<DataFrame> {
+        let pairs: Vec<(String, crate::row::Value)> = 
pairs.into_iter().collect();
         if pairs.is_empty() {
             return Err(SparkError::classed(
                 SparkErrorKind::ValueError,
@@ -2272,12 +2280,12 @@ impl DataFrame {
         DataFrame::new(self.session.clone(), plan)
     }
 
-    /// Get summary statistics.
-    pub fn summary(&self, percentiles: Vec<&str>) -> DataFrame {
-        let percs = percentiles.iter().map(|s| s.to_string()).collect();
+    /// Get summary statistics, of any iterable of their names, such as 
`"count"` and `"25%"`, as
+    /// PySpark's `DataFrame.summary(*statistics)`.
+    pub fn summary<S: Into<String>>(&self, statistics: impl IntoIterator<Item 
= S>) -> DataFrame {
         let plan = LogicalPlan::Summary {
             input: Arc::clone(&self.plan),
-            percentiles: percs,
+            percentiles: statistics.into_iter().map(Into::into).collect(),
         };
         DataFrame::new(self.session.clone(), plan)
     }
@@ -7085,6 +7093,45 @@ mod plan_construction_tests {
         );
     }
 
+    /// The SQL expressions of `select_expr`, the statistics of `summary` and 
the pairs of
+    /// `fillna_map` are of any iterable too: an array, a Vec and an iterator 
build the same plan,
+    /// and `fillna_map` takes a map of the names as well.
+    #[test]
+    fn 
expression_statistic_and_fill_lists_take_any_iterable_as_their_vec_does() {
+        use crate::row::Value;
+        use std::collections::BTreeMap;
+
+        let df = session().range(5).unwrap();
+        let same_as = |vec_form: &DataFrame, others: [&DataFrame; 2]| {
+            for other in others {
+                assert_eq!(other.plan.to_proto(), vec_form.plan.to_proto());
+            }
+        };
+
+        same_as(
+            &df.select_expr(vec!["id + 1 AS x", "id"]),
+            [
+                &df.select_expr(["id + 1 AS x", "id"]),
+                &df.select_expr(["id + 1 AS x", "id"].iter().map(|e| 
e.to_string())),
+            ],
+        );
+        same_as(
+            &df.summary(vec!["count", "25%"]),
+            [
+                &df.summary(["count", "25%"]),
+                &df.summary(["count", "25%"].iter().copied()),
+            ],
+        );
+        let pairs = || [("id".to_string(), Value::Long(0))];
+        same_as(
+            &df.fillna_map(pairs().to_vec()).unwrap(),
+            [
+                &df.fillna_map(pairs()).unwrap(),
+                &df.fillna_map(BTreeMap::from(pairs())).unwrap(),
+            ],
+        );
+    }
+
     /// Streaming reader terminal builders (serialize their plans) + the 
writer builder
     /// chain across every Trigger variant (setters only; no server-side 
start()).
     #[test]
diff --git a/crates/spark-connect/src/readwriter.rs 
b/crates/spark-connect/src/readwriter.rs
index 22e05ce3..20e7ab27 100644
--- a/crates/spark-connect/src/readwriter.rs
+++ b/crates/spark-connect/src/readwriter.rs
@@ -89,13 +89,12 @@ impl DataFrameReader {
 
     /// Load data from the specified path(s) with the configured format, 
schema, and options.
     pub fn load(self, path: Option<&str>) -> DataFrame {
-        self.load_paths(path.map(|p| vec![p.to_string()]).unwrap_or_default())
+        self.load_paths(path)
     }
 
-    /// Load data from `paths`, mirroring `DataFrameReader.load` of a list of 
paths, with the
-    /// configured format, schema, and options.
-    pub fn load_paths(self, paths: Vec<String>) -> DataFrame {
-        let paths = Some(paths);
+    /// Load data from `paths`, any iterable of them, mirroring 
`DataFrameReader.load` of a list
+    /// of paths, with the configured format, schema, and options.
+    pub fn load_paths<S: Into<String>>(self, paths: impl IntoIterator<Item = 
S>) -> DataFrame {
         let plan = LogicalPlan::Read {
             read_type: ReadType::DataSource {
                 format: self.format,
@@ -105,7 +104,7 @@ impl DataFrameReader {
                     Some(self.schema)
                 },
                 options: self.options,
-                paths: paths.unwrap_or_default(),
+                paths: paths.into_iter().map(Into::into).collect(),
                 predicates: vec![],
                 source_name: None,
             },
@@ -1048,6 +1047,27 @@ mod tests {
         }
     }
 
+    #[test]
+    fn load_paths_takes_any_iterable_of_paths_as_its_vec_does() {
+        // As the other list arguments of the Rust API: a Vec, an array and an 
iterator of the
+        // paths build the same plan, and `load` is `load_paths` of its path, 
if any.
+        let spark = session();
+        let read = || spark.read().format("csv");
+        let plan_of = |df: DataFrame| df.plan.to_proto();
+        let paths = ["/a.csv", "/b.csv"];
+        let vec_form = 
plan_of(read().load_paths(paths.map(String::from).to_vec()));
+        assert_eq!(plan_of(read().load_paths(paths)), vec_form);
+        assert_eq!(plan_of(read().load_paths(paths.iter().copied())), 
vec_form);
+        assert_eq!(
+            plan_of(read().load(Some("/a.csv"))),
+            plan_of(read().load_paths(["/a.csv"]))
+        );
+        assert_eq!(
+            plan_of(read().load(None)),
+            plan_of(read().load_paths(Vec::<String>::new()))
+        );
+    }
+
     #[test]
     fn parse_sends_the_strings_with_the_schema_and_options_of_the_reader() {
         use crate::plan::ParseFormat;
diff --git a/docs/compatibility.md b/docs/compatibility.md
index 3f594bea..b1d8f63f 100644
--- a/docs/compatibility.md
+++ b/docs/compatibility.md
@@ -22,25 +22,34 @@ Python `timedelta` map keys are not yet supported.
 
 `DataFrame::sort`, `order_by`, `sort_within_partitions`, `agg`, `observe`, 
`observe_with`,
 `hint_expressions`, `repartition_by_range`, `repartition_by_range_opt`,
-`repartition_by_expressions`, `drop_columns`, `with_columns`, `grouping_sets` 
and
-`grouping_sets_with_columns`, `GroupedData::agg`, the `partition_by` and 
`order_by` of `Window`
+`repartition_by_expressions`, `GroupedData::agg`, the `partition_by` and 
`order_by` of `Window`
 and `WindowSpec`, and `TableValuedFunction::udtf` take
 `impl IntoIterator<Item = impl Into<Column>>`, as `select` and `group_by` do: 
Columns, column
 names or expressions, such as `df.sort([col("x").desc()])` and
-`.agg([sum(col("id")).alias("total")])`, without `.expression().clone()`. The 
names of `drop`,
-`describe`, `to_df`, `to_schema`, `melt`, the numeric aggregates of 
`GroupedData` (`sum`, `avg`,
-`min`, `max`, `mean`, `numeric_agg`), the `freq_items` and `approx_quantile` 
of `StatFunctions`,
-`Column::drop_fields` and the `partition_by` and `cluster_by` of 
`DataStreamWriter` take any
-iterable of names. The `(name, Column)` pairs of `with_columns` and the `(old, 
new)` pairs of
-`with_columns_renamed` take any iterable of pairs, and 
`functions::count_distinct_columns` and
-`UserDefinedFunction::to_expression` (wasm) takes any Columns. A `Vec` or an 
array of them
-compiles as before. The `Vec<Expression>` that the sort and aggregate methods 
took still compiles,
-by the new `From<Expression> for Column`, and so does the `Vec<SortOrder>` of 
the `order_by` of a
-window, by `From<SortOrder> for Column`; there a Column that is not a sort 
order is sorted
-ascending, nulls first, as PySpark's `WindowSpec.orderBy` sorts it. An empty 
`vec![]` or `[]` has
-no item type to infer: pass `Vec::<Column>::new()` or `Vec::<&str>::new()` 
instead. The optional
-`subset` arguments of the null functions, and the optional `value_vars` of 
`melt`, stay
-`Option<Vec<&str>>`, so that `None` still infers its type.
+`.agg([sum(col("id")).alias("total")])`, without `.expression().clone()`. So 
does the first list
+of `drop_columns`, of column references: a name in it is `col(name)`, as in 
PySpark's
+`drop(F.col(name))`, so a name of several columns is `AMBIGUOUS_REFERENCE`, 
and a dotted name such
+as `a.b` refers to the field `b` of a column `a`, which drops nothing 
(``"`a.b`"`` refers to a
+column named `a.b`). Its second list is of plain names, as that of `drop`: a 
name drops every
+column of that name, and `a.b` the column named `a.b`. `grouping_sets` takes 
any iterable of
+grouping sets, each any iterable of Columns, such as `[[col("a")], [col("a"), 
col("b")]]`, and
+`grouping_sets_with_columns` takes such sets and any iterable of the grouping 
Columns. The names
+of `drop`, `describe`, `to_df`, `to_schema`, `melt`, the numeric aggregates of 
`GroupedData`
+(`sum`, `avg`, `min`, `max`, `mean`, `numeric_agg`), the `freq_items` and 
`approx_quantile` of
+`StatFunctions`, `Column::drop_fields` and the `partition_by` and `cluster_by` 
of
+`DataStreamWriter` take any iterable of names, as do the SQL expressions of 
`select_expr`, the
+statistics of `summary` and the paths of `DataFrameReader::load_paths`. The 
`(name, Column)`
+pairs of `with_columns` and the `(old, new)` pairs of `with_columns_renamed` 
take any iterable of
+pairs, and so do the `(String, Value)` pairs of `fillna_map`, such as a 
`BTreeMap<String, Value>`
+(its names stay `String`s, so that `vec![]` and `("id".into(), value)` still 
infer their type).
+`functions::count_distinct_columns` and `UserDefinedFunction::to_expression` 
(wasm) take any
+Columns. A `Vec` or an array of them compiles as before. The `Vec<Expression>` 
that the sort and
+aggregate methods took still compiles, by the new `From<Expression> for 
Column`, and so does the
+`Vec<SortOrder>` of the `order_by` of a window, by `From<SortOrder> for 
Column`; there a Column
+that is not a sort order is sorted ascending, nulls first, as PySpark's 
`WindowSpec.orderBy` sorts
+it. An empty `vec![]` or `[]` has no item type to infer: pass 
`Vec::<Column>::new()` or
+`Vec::<&str>::new()` instead. The optional `subset` arguments of the null 
functions, and the
+optional `value_vars` of `melt`, stay `Option<Vec<&str>>`, so that `None` 
still infers its type.
 
 `BinaryClassificationEvaluator::set_score_col` and `score_col`, and the Python
 `scoreCol=` argument and `setScoreCol` of v4.2.0 are removed, without an alias:


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

Reply via email to