Repository navigation
[SPARK-61180][CONNECT][PYTHON] Add DataFrame._joinAsOf, the as-of join of pandas-on-Spark's merge_asof, in the Rust and Python clients as PySpark does - #376
Open
HyukjinKwon wants to merge 1 commit into
Conversation
…n of pandas-on-Spark's merge_asof, in the Rust and Python clients as PySpark does Add DataFrame._joinAsOf to the Rust core, the PyO3 drop-in and its tests. PySpark Connect builds the AsOfJoin relation for it, and pandas-on-Spark's merge_asof calls it. The as-of join takes the as-of columns, the join condition or the shared column names, the join type, an optional tolerance, allowExactMatches, and the direction, and the server runs it. Co-authored-by: Isaac <no-reply@databricks.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changes were proposed in this pull request?
SPARK-61180: PySpark Connect's
DataFrame._joinAsOf(other, leftAsOfColumn, rightAsOfColumn, on=None, how=None, *, tolerance=None, allowExactMatches=True, direction="backward")builds the Spark ConnectAsOfJoinrelation. pandas-on-Spark'smerge_asofcalls it.DataFrame::as_of_join(&right, AsOfJoinOptions)with a newAsOfJoinOptionsstruct (AsOfJoinOptions::new(left_as_of, right_as_of)sets the PySpark defaults: inner, exact matches allowed,"backward"). The plan is a newLogicalPlan::AsOfJoin, serialized toAsOfJoinwithleft_as_of,right_as_of,join_exprorusing_columns,join_type,tolerance,allow_exact_matchesanddirection. A DataFrame of another session fails withSESSION_NOT_SAME.DataFrame._joinAsOfwith PySpark's signature.howdefaults to inner and must be a string.tolerancemust be a Column.onis a name, a Column, or a list of names or Columns, as inplan.AsOfJoin. A string as-of column is a column of its DataFrame, asdf._col(name).join_typeanddirectionare sent as they are, so the server checks them as it does for PySpark.Why are the changes needed?
ps.merge_asoffailed, because_joinAsOfdid not exist and the name resolved throughDataFrame.__getattr__to a Column:PySpark returns
[[1, 1.0, 'a', nan, None], [5, 5.0, 'b', 4.0, 'y']]for L =[(1, 1.0, "a"), (5, 5.0, "b")]("t int, x double, k string") and R =[(2, 2.0, "x"), (4, 4.0, "y")]("t int, y double, k string").Does this PR introduce any user-facing change?
Yes.
DataFrame._joinAsOfandpandas.merge_asof(pandas-on-Spark) work on the Rust client as they do on PySpark Connect. Before, they raised theTypeErrorabove.How was this patch tested?
test_join_as_of_sends_the_as_of_join_as_pyspark(offline,python/tests/test_dropin_offline.py): checks the fields of the sentAsOfJoinrelation for a listonwithhow,tolerance,allowExactMatches=Falseanddirection, for the defaults, and for a Columnon.test_join_as_of_and_merge_asof_give_the_rows_of_pyspark(e2e,python/tests/test_dropin_e2e.py): the rows of_joinAsOffor each direction,allowExactMatches, tolerance,onas a list, and the inner default, and the rows ofps.merge_asofwithon,by,direction,tolerance, andleft_on/right_on/left_by/right_by.as_of_join_sends_every_field_of_the_as_of_join,as_of_join_defaults_and_sends_a_condition_as_join_exprandas_of_join_rejects_a_dataframe_of_another_session(Rust unit tests,crates/spark-connect/src/dataframe.rs).TypeError: 'pyspark.sql.connect.column.Column' object is not callable. The same cases give the same schemas, rows, and error messages on official PySpark 4.3.0 against the same server. The explain text matches apart from plan IDs.wasm-udf, the offline Python suites (2228 passed, 8 skipped), and the live drop-in and Arrow suites (211 passed) and live cases (10 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.