viirya opened a new pull request, #60746:
URL: https://github.com/apache/spark/pull/60746
### What changes were proposed in this pull request?
This PR changes the return type of the DSv2 connector method
`SupportsExternalLookup.selectLookupPredicates` from `Predicate[]` to `int[]`.
The connector now returns the positions of the selected predicates in the
`candidates` array, instead of the selected `Predicate` instances.
- `SupportsExternalLookup.selectLookupPredicates(Predicate[] candidates)`
returns `int[]`. Each element is a position in `candidates`; the positions must
be distinct and in range. As before, the order of the result defines the fields
of each parameter row: field `i` is the value for the predicate at the `i`-th
returned position. An empty result still means that no access path fits.
- `PrepareExternalLookupJoin` maps the positions back to the offered
candidates, replacing the `IdentityHashMap` matching.
- Error conditions under `DATA_SOURCE_INVALID_EXTERNAL_LOOKUP`:
- `UNOFFERED_SELECTED_PREDICATE` is replaced by
`INVALID_SELECTED_PREDICATE_INDEX` (`<index>`, `<numCandidates>`), raised for a
negative or out-of-range position.
- `DUPLICATE_SELECTED_PREDICATE` now also reports the `<index>`.
- `NULL_RESULT` (null array) and
`EXTERNAL_LOOKUP_JOIN_UNSUPPORTED.NO_LOOKUP_PREDICATE` (empty array) are
unchanged.
- The test connectors are updated to return positions.
### Why are the changes needed?
The current contract asks the connector to return the offered `Predicate`
instances unchanged, and Spark matches them by object identity, not `equals`. A
connector that returns an equal copy, for example after rebuilding a predicate
from its name and children, fails at query start with
`UNOFFERED_SELECTED_PREDICATE`. This is easy to get wrong when writing a
connector, and the requirement is visible only in the Javadoc.
A connector only needs to say which of the offered candidates it serves, and
in which order. Positions express exactly that: they are unambiguous for
same-shaped candidates (such as two `id = ?` bound to different stream
columns), they keep the connector-chosen order that defines the parameter row
layout, and they do not depend on object identity. Two alternatives were
considered:
- Keep `Predicate[]` but match by `equals`. Because `LookupParameter` uses
identity equality, this works only if the copy keeps the same `LookupParameter`
instance, so the contract would still rely on identity, just one level down.
- Return a `boolean[]` mask. This loses the connector's order, which defines
the parameter row layout (for example, a composite key in the connector's key
order).
The API was added in 4.4.0, which is not released yet, so this is the
cheapest time to change it.
### Does this PR introduce _any_ user-facing change?
Yes, for connector developers, compared to the unreleased master and
branch-4.4: `SupportsExternalLookup.selectLookupPredicates` returns `int[]`
positions instead of `Predicate[]` instances, and the error condition
`DATA_SOURCE_INVALID_EXTERNAL_LOOKUP.UNOFFERED_SELECTED_PREDICATE` is replaced
by `DATA_SOURCE_INVALID_EXTERNAL_LOOKUP.INVALID_SELECTED_PREDICATE_INDEX`. No
change compared to released Spark versions.
### How was this patch tested?
Updated the existing tests and added negative cases for negative,
out-of-range and duplicate positions, alongside the existing null and empty
results:
```
build/sbt 'sql/testOnly *PrepareExternalLookupJoinSuite
*ExternalLookupJoinSuite *ExternalLookupJoinStartupCheckSuite'
build/sbt 'core/testOnly *SparkThrowableSuite'
```
### Was this patch authored or co-authored using generative AI tooling?
Generated-by: Claude Code (claude-opus-5-5)
This pull request and its description were written by Isaac.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]