Repository navigation
[SPARK-62246][SQL] Make a DataFrame as-of join with using columns return one key column - #60796
Open
LukaZdravic wants to merge 1 commit into
Open
LukaZdravic wants to merge 1 commit into
LukaZdravic wants to merge 1 commit into
Conversation
…urn one key column
`Dataset.joinAsOf` with `usingColumns` now builds an `AsOfJoin` with `usingColumns` set, the same node that SQL `ASOF JOIN ... USING` builds. Both analyzers already expand it, so the output has one column per name, placed first, as in SQL.
It used to turn each name into `left(name) === right(name)`, which kept the key of both sides.
Spark Connect and PySpark `_joinAsOf` call `Dataset.joinAsOf`, so they change too. A migration guide line is added.
```
joinAsOf(quotes, ts, ts, usingColumns = Seq("sym"))
before: ts, sym, qty, ts, sym, bid (select("sym") fails with AMBIGUOUS_REFERENCE)
after: sym, ts, qty, ts, bid (same as SQL ASOF JOIN quotes ... USING (sym))
```
The DataFrame API and SQL gave different columns for the same join, and the key could not be selected by name.
Yes, for the private DataFrame as-of join (`DataFrame._joinAsOf` in PySpark, and Spark Connect) when `on` is a column name or a list of names. The output has one key column per name instead of two. There is no switch for the old output. The key keeps the type of the left side, and names are matched against top-level columns as in a regular USING join (a nested, quoted or metadata name now fails). A join with a Column for `on`, and `pandas.merge_asof`, are not changed.
- `DataFrameAsOfJoinSuite`: columns, schema and rows equal SQL `ASOF JOIN ... USING` for INNER and LEFT, one and two keys. Also select/filter/group by the key, an unmatched LEFT row and a NULL key, a self join, a missing name (`UNRESOLVED_USING_COLUMN_FOR_JOIN`), tolerance and direction against the rows of the Column-condition join. Each test runs with the fixed-point and single-pass analyzers, the sort-merge flag off and on, and ANSI on and off.
- Also: qualified access to the right key, INT vs BIGINT and STRING keys against SQL USING, case sensitivity, a nested field name.
- `SparkConnectProtoSuite`: a Connect as-of join with `using_columns` returns one key column, resolves plan-id keys with rows, with both analyzers.
- `StreamingAsOfJoinSuite`: a stream-static DataFrame join with using columns.
- Existing ASOF, join and codegen suites, with expected rows updated for the new column order.
Generated-by: Claude Code
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?
Dataset.joinAsOfwithusingColumnsnow builds anAsOfJoinwithusingColumnsset, the same node that SQLASOF JOIN ... USINGbuilds. Both analyzers already expand it, so the output has one column per name, placed first, as in SQL.It used to turn each name into
left(name) === right(name), which kept the key of both sides.Spark Connect and PySpark
_joinAsOfcallDataset.joinAsOf, so they change too. A migration guide line is added.Why are the changes needed?
The DataFrame API and SQL gave different columns for the same join, and the key could not be selected by name.
Does this PR introduce any user-facing change?
Yes, for the private DataFrame as-of join (
DataFrame._joinAsOfin PySpark, and Spark Connect) whenonis a column name or a list of names. The output has one key column per name instead of two. There is no switch for the old output. The key keeps the type of the left side, and names are matched against top-level columns as in a regular USING join (a nested, quoted or metadata name now fails). A join with a Column foron, andpandas.merge_asof, are not changed.How was this patch tested?
DataFrameAsOfJoinSuite: columns, schema and rows equal SQLASOF JOIN ... USINGfor INNER and LEFT, one and two keys. Also select/filter/group by the key, an unmatched LEFT row and a NULL key, a self join, a missing name (UNRESOLVED_USING_COLUMN_FOR_JOIN), tolerance and direction against the rows of the Column-condition join. Each test runs with the fixed-point and single-pass analyzers, the sort-merge flag off and on, and ANSI on and off.SparkConnectProtoSuite: a Connect as-of join withusing_columnsreturns one key column, resolves plan-id keys with rows, with both analyzers.StreamingAsOfJoinSuite: a stream-static DataFrame join with using columns.Was this patch authored or co-authored using generative AI tooling?
Generated-by: Claude Code
This pull request and its description were written by Isaac.