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

viirya 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 219a768e [SPARK-61496][CONNECT][PYTHON] Type the join type and 
direction of the as-of join, and document which node a shared plan ID gives
219a768e is described below

commit 219a768e40d5b3f58b2ec63001b4049f2ad0badb
Author: Liang-Chi Hsieh <[email protected]>
AuthorDate: Wed Nov 11 22:41:11 2026 -0800

    [SPARK-61496][CONNECT][PYTHON] Type the join type and direction of the 
as-of join, and document which node a shared plan ID gives
    
    ### What changes were proposed in this pull request?
    
    Two changes in `crates/spark-connect/src/plan.rs` and its callers.
    
    - The `AsOfJoin` plan node kept its join type and its direction as strings. 
They are now `AsOfJoinType` (`Inner`, `LeftOuter`, `Other(String)`) and 
`AsOfJoinDirection` (`Backward`, `Forward`, `Nearest`, `Other(String)`), each 
with `parse`, `as_str`, `From<&str>` and `Default`. `AsOfJoinOptions.join_type` 
and `direction` take them, and the PyO3 `_joinAsOf` parses `how` and 
`direction` into them.
    - `PlanIds::node_of` documents which node it gives for a plan ID that 
several nodes share, and why any of them does, and has tests of its own. Its 
code is unchanged.
    
    ### Why are the changes needed?
    
    **As-of join.** A join type or a direction could be any string in the plan. 
PySpark's `_joinAsOf` only asserts that `how` is a string. It sends `how` and 
`direction` as they are, and the server reads more spellings than the names 
(`JoinType` ignores case and underscores, `AsOfJoinDirection` ignores case) and 
refuses the rest in the analysis (`UNSUPPORTED_JOIN_TYPE`, 
`AS_OF_JOIN.UNSUPPORTED_DIRECTION`, or the `require` of `AsOfJoin` for a join 
type that is not inner or left outer). So  [...]
    
    **Plan IDs.** A plan ID is of more than one node whenever a relation that 
the session sent has a DataFrame of its own (`DataFrame::from_sent_relation`), 
such as an unpickled copy of a DataFrame: `assign` gives the copy the plan ID 
of the DataFrame it was of, which may still be alive. `node_of` scans a 
`HashMap` and gives the first live node of the ID that it meets, so any of 
them. That used to lose observed metrics when the node was a copy. SPARK-61426 
(#532) fixed that by setting the [...]
    
    The lookup stays a scan. It runs once for each DataFrame made of a sent 
relation, over the nodes that the session tracks. A second map by plan ID would 
have to be kept in step with the first on every insert and prune.
    
    ### Does this PR introduce _any_ user-facing change?
    
    Yes, in the Rust API: `AsOfJoinOptions.join_type` and `direction` are 
`AsOfJoinType` and `AsOfJoinDirection` in place of `String`. `"left".into()` 
and `AsOfJoinType::parse` take a string.
    
    No change in Python: `_joinAsOf` sends `how` and `direction` as before.
    
    ### How was this patch tested?
    
    - New `crates/spark-connect/tests/as_of_join.rs`: the names parse to their 
variants and are sent by name, and other strings (`"LEFT"`, `"left_outer"`, 
`"sideways"`, `""`) are kept in `Other` and sent byte for byte, with no client 
error.
    - New `plan_id_tests` in `plan.rs`: `node_of` for a numbered node, for 
nodes given the same ID, as nodes are dropped, and for an unknown ID.
    - `test_join_as_of_sends_the_as_of_join_as_pyspark` in 
`python/tests/test_dropin_offline.py` now also sends each of eight `how` values 
with each of six `direction` values and checks the fields of the request, and 
checks the `AssertionError` of a `how` that is not a string.
    - `cargo test -p apache-spark-connect --release --lib` (618 passed), the 
`--no-run` builds with and without `wasm-udf`, `cargo fmt --all --check`, the 
golden-proto tests with their golden files unchanged, and the Python offline 
suite with `TZ=UTC` (1894 passed, 8 skipped).
    
    ### Was this patch authored or co-authored using generative AI tooling?
    
    Generated-by: Claude Fable 5.2
    
    This pull request and its description were written by Isaac.
    
    Closes #543 from viirya/SPARK-61496-asof-enums-plan-ids.
    
    Authored-by: Liang-Chi Hsieh <[email protected]>
    Signed-off-by: Liang-Chi Hsieh <[email protected]>
---
 crates/pyspark-rs/src/dataframe.rs       |  19 ++--
 crates/spark-connect/src/dataframe.rs    |  28 +++---
 crates/spark-connect/src/plan.rs         | 163 ++++++++++++++++++++++++++++++-
 crates/spark-connect/tests/as_of_join.rs |  97 ++++++++++++++++++
 python/tests/test_dropin_offline.py      |  16 +++
 5 files changed, 301 insertions(+), 22 deletions(-)

diff --git a/crates/pyspark-rs/src/dataframe.rs 
b/crates/pyspark-rs/src/dataframe.rs
index 1745b241..eb365d47 100644
--- a/crates/pyspark-rs/src/dataframe.rs
+++ b/crates/pyspark-rs/src/dataframe.rs
@@ -3,7 +3,7 @@
 use pyo3::prelude::*;
 use pyo3::types::{PyDict, PyInt, PyList, PyTuple};
 use spark_connect::dataframe::{AsOfJoinOptions, DataFrame, LocalRowIterator};
-use spark_connect::plan::JoinType;
+use spark_connect::plan::{AsOfJoinDirection, AsOfJoinType, JoinType};
 use spark_connect::udf::{eval_type, CommonInlineUserDefinedFunctionExpression, 
PythonUDFPayload};
 
 use crate::column::PyColumn;
@@ -1048,7 +1048,9 @@ impl PyDataFrame {
     /// tolerance=None, allowExactMatches=True, direction="backward")`, the 
as-of join of
     /// pandas-on-Spark's `merge_asof`, as PySpark's. The as-of columns are 
Columns, or names of
     /// their DataFrame. `on` is a name, a Column condition, or a list of 
either. `how` (inner by
-    /// default) and `direction` are sent as they are, and the server checks 
them.
+    /// default) and `direction` are not checked, as PySpark does not check 
them: a string that
+    /// is none of the join types or directions of the core is sent as it is, 
and the server
+    /// refuses what it does not read.
     #[pyo3(name = "_joinAsOf", signature = (other, leftAsOfColumn, 
rightAsOfColumn, on=None, how=None, *, tolerance=None, allowExactMatches=true, 
direction="backward"))]
     #[allow(non_snake_case, clippy::too_many_arguments)]
     fn join_as_of(
@@ -1065,10 +1067,13 @@ impl PyDataFrame {
         // As PySpark's `_check_same_session`, first.
         let other = self.same_session(other)?;
         let join_type = match how.filter(|how| !how.is_none()) {
-            None => "inner".to_string(),
-            Some(how) => how.extract::<String>().map_err(|_| {
-                pyo3::exceptions::PyAssertionError::new_err("how should be a 
string")
-            })?,
+            None => AsOfJoinType::Inner,
+            Some(how) => {
+                let how = how.extract::<String>().map_err(|_| {
+                    pyo3::exceptions::PyAssertionError::new_err("how should be 
a string")
+                })?;
+                AsOfJoinType::parse(&how)
+            }
         };
         let tolerance = match tolerance.filter(|tolerance| 
!tolerance.is_none()) {
             None => None,
@@ -1091,7 +1096,7 @@ impl PyDataFrame {
             join_type,
             tolerance,
             allow_exact_matches: allowExactMatches,
-            direction: direction.to_string(),
+            direction: AsOfJoinDirection::parse(direction),
         };
         let df = self
             .dataframe
diff --git a/crates/spark-connect/src/dataframe.rs 
b/crates/spark-connect/src/dataframe.rs
index 72ca0e3f..ee9e41ae 100644
--- a/crates/spark-connect/src/dataframe.rs
+++ b/crates/spark-connect/src/dataframe.rs
@@ -12,7 +12,10 @@ use spark_connect_proto as proto;
 
 use crate::column::Column;
 use crate::expression::{Expression, ExpressionNode, SortOrder};
-use crate::plan::{AggregateGroupType, JoinType, LogicalPlan, RelationOwner, 
SetOpType};
+use crate::plan::{
+    AggregateGroupType, AsOfJoinDirection, AsOfJoinType, JoinType, 
LogicalPlan, RelationOwner,
+    SetOpType,
+};
 use crate::progress::ExecutionStream;
 use crate::row::{Row, StructValue, Value};
 use crate::session::{ExecutionInfo, SparkSession};
@@ -75,14 +78,15 @@ pub struct AsOfJoinOptions {
     pub on: Option<Column>,
     /// Column names that both sides share, sent as `using_columns`.
     pub using_columns: Vec<String>,
-    /// The join type, such as `"inner"` or `"left"`, sent as it is.
-    pub join_type: String,
+    /// The join type: inner or left outer, or a string for the server to read.
+    pub join_type: AsOfJoinType,
     /// The as-of tolerance: the largest distance a match may have.
     pub tolerance: Option<Column>,
     /// Whether a row may match a row with the same as-of value.
     pub allow_exact_matches: bool,
-    /// `"backward"`, `"forward"` or `"nearest"`, sent as it is.
-    pub direction: String,
+    /// The direction of the search: backward, forward or nearest, or a string 
for the server
+    /// to read.
+    pub direction: AsOfJoinDirection,
 }
 
 impl AsOfJoinOptions {
@@ -93,10 +97,10 @@ impl AsOfJoinOptions {
             right_as_of,
             on: None,
             using_columns: Vec::new(),
-            join_type: "inner".to_string(),
+            join_type: AsOfJoinType::Inner,
             tolerance: None,
             allow_exact_matches: true,
-            direction: "backward".to_string(),
+            direction: AsOfJoinDirection::Backward,
         }
     }
 }
@@ -669,8 +673,10 @@ impl DataFrame {
     /// As-of join with another DataFrame: each row of this DataFrame is 
matched with the
     /// nearest row of `right` on the as-of columns, as `DataFrame._joinAsOf` 
does.
     ///
-    /// Errors with `SESSION_NOT_SAME` when `right` is of another session. The 
join type and
-    /// the direction are sent as they are; the server checks them.
+    /// Errors with `SESSION_NOT_SAME` when `right` is of another session. As 
PySpark, this
+    /// does not check the join type and the direction: a string that is none 
of
+    /// [`AsOfJoinType`] or of [`AsOfJoinDirection`] is sent as it is, and the 
server refuses
+    /// what it does not read.
     pub fn as_of_join(&self, right: &DataFrame, options: AsOfJoinOptions) -> 
Result<DataFrame> {
         // As PySpark's `_check_same_session`.
         if self.session.client().session_id() != 
right.session.client().session_id() {
@@ -5519,10 +5525,10 @@ mod plan_construction_tests {
         let right = spark.range(4).unwrap();
         let options = AsOfJoinOptions {
             using_columns: vec!["id".to_string()],
-            join_type: "left".to_string(),
+            join_type: AsOfJoinType::LeftOuter,
             tolerance: Some(crate::column::lit(1)),
             allow_exact_matches: false,
-            direction: "forward".to_string(),
+            direction: AsOfJoinDirection::Forward,
             ..AsOfJoinOptions::new(col("id"), col("id"))
         };
         let joined = left.as_of_join(&right, options).unwrap();
diff --git a/crates/spark-connect/src/plan.rs b/crates/spark-connect/src/plan.rs
index fdbf8c48..23dad520 100644
--- a/crates/spark-connect/src/plan.rs
+++ b/crates/spark-connect/src/plan.rs
@@ -464,10 +464,10 @@ pub enum LogicalPlan {
         right_as_of: Column,
         on: Option<Column>,
         using_columns: Vec<String>,
-        join_type: String,
+        join_type: AsOfJoinType,
         tolerance: Option<Column>,
         allow_exact_matches: bool,
-        direction: String,
+        direction: AsOfJoinDirection,
     },
     /// NearestByJoin: `DataFrame.nearestByJoin`.
     NearestByJoin {
@@ -513,6 +513,99 @@ pub enum JoinType {
     Cross,
 }
 
+/// The join type of an as-of join (`DataFrame._joinAsOf`): the server joins 
as of only an
+/// inner or a left outer join.
+///
+/// PySpark does not check `how`: it sends the string as it is, and the server 
reads it as any
+/// join type, without regard to case or underscores (`"LEFT"`, 
`"left_outer"`), and fails the
+/// analysis for a join type that is not one, or that an as-of join does not 
have. So a string
+/// that is not exactly the name of a variant is kept in `Other`, and is sent 
as it is.
+#[derive(Debug, Clone, PartialEq, Eq, Default)]
+pub enum AsOfJoinType {
+    /// `"inner"`, the default: the rows of the left side that have a match.
+    #[default]
+    Inner,
+    /// `"left"`: every row of the left side.
+    LeftOuter,
+    /// Any other string, sent as it is, for the server to read or to refuse.
+    Other(String),
+}
+
+impl AsOfJoinType {
+    /// The join type of `how`: `"inner"`, `"left"`, or the string as it is.
+    pub fn parse(how: &str) -> Self {
+        match how {
+            "inner" => AsOfJoinType::Inner,
+            "left" => AsOfJoinType::LeftOuter,
+            other => AsOfJoinType::Other(other.to_string()),
+        }
+    }
+
+    /// The string that is sent as the `join_type` of the as-of join.
+    pub fn as_str(&self) -> &str {
+        match self {
+            AsOfJoinType::Inner => "inner",
+            AsOfJoinType::LeftOuter => "left",
+            AsOfJoinType::Other(how) => how,
+        }
+    }
+}
+
+impl From<&str> for AsOfJoinType {
+    fn from(how: &str) -> Self {
+        AsOfJoinType::parse(how)
+    }
+}
+
+/// The direction in which an as-of join (`DataFrame._joinAsOf`) searches for 
the match of a
+/// row.
+///
+/// PySpark does not check `direction`: it sends the string as it is, and the 
server reads it
+/// without regard to case, and fails the analysis with 
`AS_OF_JOIN.UNSUPPORTED_DIRECTION` for
+/// any other. So a string that is not exactly the name of a variant is kept 
in `Other`, and is
+/// sent as it is.
+#[derive(Debug, Clone, PartialEq, Eq, Default)]
+pub enum AsOfJoinDirection {
+    /// `"backward"`, the default: the last row whose as-of value is not 
greater.
+    #[default]
+    Backward,
+    /// `"forward"`: the first row whose as-of value is not smaller.
+    Forward,
+    /// `"nearest"`: the row whose as-of value is the closest.
+    Nearest,
+    /// Any other string, sent as it is, for the server to read or to refuse.
+    Other(String),
+}
+
+impl AsOfJoinDirection {
+    /// The direction of `direction`: `"backward"`, `"forward"`, `"nearest"`, 
or the string as
+    /// it is.
+    pub fn parse(direction: &str) -> Self {
+        match direction {
+            "backward" => AsOfJoinDirection::Backward,
+            "forward" => AsOfJoinDirection::Forward,
+            "nearest" => AsOfJoinDirection::Nearest,
+            other => AsOfJoinDirection::Other(other.to_string()),
+        }
+    }
+
+    /// The string that is sent as the `direction` of the as-of join.
+    pub fn as_str(&self) -> &str {
+        match self {
+            AsOfJoinDirection::Backward => "backward",
+            AsOfJoinDirection::Forward => "forward",
+            AsOfJoinDirection::Nearest => "nearest",
+            AsOfJoinDirection::Other(direction) => direction,
+        }
+    }
+}
+
+impl From<&str> for AsOfJoinDirection {
+    fn from(direction: &str) -> Self {
+        AsOfJoinDirection::parse(direction)
+    }
+}
+
 /// Set operation type (UNION, INTERSECT, EXCEPT).
 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
 pub enum SetOpType {
@@ -598,6 +691,18 @@ impl PlanIds {
 
     /// A live node of the plan ID `id`, such as that of the DataFrame of a 
relation that this
     /// session sent.
+    ///
+    /// A plan ID is of one node that this session numbered (`id_of`), and of 
each node that
+    /// was given it (`assign`): each DataFrame of a relation that the session 
sent, such as
+    /// each unpickled copy of a DataFrame, is a node of its own with the plan 
ID of the
+    /// DataFrame it was of, which may be alive too. Any one of them is given, 
on purpose: they
+    /// are all the relation of that plan ID, and each copy took the 
Observations of a node of
+    /// the ID when it was made (`DataFrame::from_sent_relation`, the one 
caller), so they all
+    /// have the same ones.
+    ///
+    /// This scans every node of the session, once for each DataFrame made of 
a sent relation,
+    /// which costs less than keeping a second map by plan ID in step with the 
first on every
+    /// insert and prune.
     pub(crate) fn node_of(&self, id: i64) -> Option<Arc<LogicalPlan>> {
         let nodes = self.nodes.lock().unwrap_or_else(|e| e.into_inner());
         nodes
@@ -1485,10 +1590,10 @@ impl LogicalPlan {
                     right_as_of: Some(right_as_of.to_proto()),
                     join_expr: on.as_ref().map(|condition| 
condition.to_proto()),
                     using_columns: using_columns.clone(),
-                    join_type: join_type.clone(),
+                    join_type: join_type.as_str().to_string(),
                     tolerance: tolerance.as_ref().map(|tolerance| 
tolerance.to_proto()),
                     allow_exact_matches: *allow_exact_matches,
-                    direction: direction.clone(),
+                    direction: direction.as_str().to_string(),
                 };
                 relation.rel_type = 
Some(proto::relation::RelType::AsOfJoin(Box::new(aj)));
             }
@@ -3125,6 +3230,56 @@ mod with_relations_tests {
     }
 }
 
+#[cfg(test)]
+mod plan_id_tests {
+    use super::*;
+
+    /// Whether `node` is one of the allocations of `expected`.
+    fn one_of(node: Option<Arc<LogicalPlan>>, expected: &[&Arc<LogicalPlan>]) 
-> bool {
+        node.is_some_and(|node| expected.iter().any(|expected| 
Arc::ptr_eq(&node, expected)))
+    }
+
+    #[test]
+    fn a_numbered_node_is_the_one_node_of_its_plan_id() {
+        let ids = PlanIds::new();
+        let (first, second) = (Arc::new(range(0, 3, 1)), Arc::new(range(0, 5, 
1)));
+        let (first_id, second_id) = (ids.id_of(&first), ids.id_of(&second));
+        assert_ne!(first_id, second_id);
+        assert!(one_of(ids.node_of(first_id), &[&first]));
+        assert!(one_of(ids.node_of(second_id), &[&second]));
+        // The plan ID of the root of a node within its `WithRelations` is 
another ID of it.
+        let root_id = ids.root_id_of(&first);
+        assert_ne!(root_id, first_id);
+        assert!(one_of(ids.node_of(root_id), &[&first]));
+        assert!(ids.node_of(-1).is_none());
+    }
+
+    /// A relation that the session sent keeps its plan ID in each DataFrame 
of it, so a plan
+    /// ID is of all of them and of the node it was first of: the node of the 
ID is one of
+    /// those that are alive.
+    #[test]
+    fn the_node_of_a_plan_id_that_was_given_is_one_of_its_live_nodes() {
+        let ids = PlanIds::new();
+        let numbered = Arc::new(range(0, 3, 1));
+        let id = ids.id_of(&numbered);
+        let (copy, other_copy) = (Arc::new(range(0, 3, 1)), Arc::new(range(0, 
3, 1)));
+        ids.assign(&copy, id);
+        ids.assign(&other_copy, id);
+        assert_eq!(ids.id_of(&copy), id);
+        assert!(one_of(ids.node_of(id), &[&numbered, &copy, &other_copy]));
+        // A node that is dropped is no longer a node of the ID; the others 
still are.
+        std::mem::drop(numbered);
+        assert!(one_of(ids.node_of(id), &[&copy, &other_copy]));
+        std::mem::drop(copy);
+        assert!(one_of(ids.node_of(id), &[&other_copy]));
+        std::mem::drop(other_copy);
+        assert!(ids.node_of(id).is_none());
+        // A plan ID that was given is not one that the session numbers a 
later node with.
+        let later = Arc::new(range(0, 1, 1));
+        assert_ne!(ids.id_of(&later), id);
+    }
+}
+
 #[cfg(test)]
 mod inline_udtf_tests {
     use super::*;
diff --git a/crates/spark-connect/tests/as_of_join.rs 
b/crates/spark-connect/tests/as_of_join.rs
new file mode 100644
index 00000000..ba54104a
--- /dev/null
+++ b/crates/spark-connect/tests/as_of_join.rs
@@ -0,0 +1,97 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+//! The join type and the direction of an as-of join: the values that the 
client knows, and the
+//! strings that it sends as they are, as PySpark's `_joinAsOf` sends `how` 
and `direction`
+//! without checking them. No server is needed: a session connects when it 
first sends.
+
+mod common;
+
+use spark_connect::column::col;
+use spark_connect::dataframe::AsOfJoinOptions;
+use spark_connect::plan::{AsOfJoinDirection, AsOfJoinType};
+use spark_connect_proto as proto;
+
+/// The `join_type` and the `direction` that an as-of join of `join_type` and 
`direction` sends.
+fn sent(join_type: AsOfJoinType, direction: AsOfJoinDirection) -> (String, 
String) {
+    let spark = common::session();
+    let (left, right) = (spark.range(3).unwrap(), spark.range(5).unwrap());
+    let options = AsOfJoinOptions {
+        join_type,
+        direction,
+        ..AsOfJoinOptions::new(col("id"), col("id"))
+    };
+    let joined = left.as_of_join(&right, options).unwrap();
+    let relation = joined.to_relation().unwrap();
+    let Some(proto::relation::RelType::AsOfJoin(as_of)) = relation.rel_type 
else {
+        panic!("expected AsOfJoin: {relation:?}");
+    };
+    (as_of.join_type, as_of.direction)
+}
+
+#[test]
+fn the_join_types_and_directions_of_an_as_of_join_are_sent_by_their_names() {
+    assert_eq!(AsOfJoinType::default(), AsOfJoinType::Inner);
+    assert_eq!(AsOfJoinDirection::default(), AsOfJoinDirection::Backward);
+    for (join_type, name) in [
+        (AsOfJoinType::Inner, "inner"),
+        (AsOfJoinType::LeftOuter, "left"),
+    ] {
+        assert_eq!(AsOfJoinType::parse(name), join_type);
+        assert_eq!(AsOfJoinType::from(name), join_type);
+        assert_eq!(join_type.as_str(), name);
+        assert_eq!(sent(join_type, AsOfJoinDirection::default()).0, name);
+    }
+    for (direction, name) in [
+        (AsOfJoinDirection::Backward, "backward"),
+        (AsOfJoinDirection::Forward, "forward"),
+        (AsOfJoinDirection::Nearest, "nearest"),
+    ] {
+        assert_eq!(AsOfJoinDirection::parse(name), direction);
+        assert_eq!(AsOfJoinDirection::from(name), direction);
+        assert_eq!(direction.as_str(), name);
+        assert_eq!(sent(AsOfJoinType::default(), direction).1, name);
+    }
+}
+
+/// PySpark checks neither `how` nor `direction`, and the server reads more 
spellings than the
+/// names above (`"LEFT"`, `"left_outer"`, `"Forward"`) and refuses the rest 
in the analysis
+/// (`UNSUPPORTED_JOIN_TYPE`, `AS_OF_JOIN.UNSUPPORTED_DIRECTION`). So the 
client fails for no
+/// string, and sends each byte for byte.
+#[test]
+fn any_other_join_type_or_direction_is_sent_as_it_is_for_the_server_to_check() 
{
+    for how in [
+        "LEFT",
+        "left_outer",
+        "leftouter",
+        "Inner",
+        "right",
+        "sideways",
+        "",
+    ] {
+        let join_type = AsOfJoinType::parse(how);
+        assert_eq!(join_type, AsOfJoinType::Other(how.to_string()));
+        assert_eq!(join_type.as_str(), how);
+        assert_eq!(sent(join_type, AsOfJoinDirection::default()).0, how);
+    }
+    for name in ["Forward", "BACKWARD", "sideways", ""] {
+        let direction = AsOfJoinDirection::parse(name);
+        assert_eq!(direction, AsOfJoinDirection::Other(name.to_string()));
+        assert_eq!(direction.as_str(), name);
+        assert_eq!(sent(AsOfJoinType::default(), direction).1, name);
+    }
+}
diff --git a/python/tests/test_dropin_offline.py 
b/python/tests/test_dropin_offline.py
index 82317535..3cf52d6d 100644
--- a/python/tests/test_dropin_offline.py
+++ b/python/tests/test_dropin_offline.py
@@ -11116,6 +11116,22 @@ def 
test_join_as_of_sends_the_as_of_join_as_pyspark(mock_connect):
     assert attribute(join[3][0]) == "id" and 5 in join and 6 not in join
     assert join[7] == [b"left"] and join[10] == [b"backward"]
 
+    # As PySpark, which checks neither `how` nor `direction` but that `how` is 
a string: each
+    # is sent as it is. The server reads the names, and other spellings of 
them, and refuses
+    # the rest in the analysis.
+    for how in ("inner", "left", "LEFT", "left_outer", "leftouter", "right", 
"sideways", ""):
+        for direction in ("backward", "forward", "nearest", "Forward", 
"sideways", ""):
+            join = sent_as_of_join(left._joinAsOf(
+                right, "id", "id", how=how, direction=direction))
+            # An empty string is the default of its field, which is not sent.
+            assert join.get(7, [b""]) == [how.encode()]
+            assert join.get(10, [b""]) == [direction.encode()]
+    join = sent_as_of_join(left._joinAsOf(right, "id", "id", how=None))
+    assert join[7] == [b"inner"]
+    for how in (1, ["left"], b"left"):
+        with pytest.raises(AssertionError, match="^how should be a string$"):
+            left._joinAsOf(right, "id", "id", how=how)
+
 
 def 
test_grouping_sets_group_by_their_grouping_columns_as_pyspark(mock_connect):
     # As PySpark's, groupingSets(groupingSets, *cols) groups by the sets with 
the grouping


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

Reply via email to