Repository navigation
[Spark] Fix replaceWhere with BETWEEN, NOT BETWEEN and NULLIF predicates - #7838
Open
maharanay22 wants to merge 1 commit into
Open
maharanay22 wants to merge 1 commit into
maharanay22 wants to merge 1 commit into
Conversation
On Spark 4, BETWEEN and NULLIF are replaced by `With` expressions that hold their shared operands in `CommonExpressionDef`s. `DeltaLogUtils.rewritePartitionFilters` rewrote partition attributes inside those definitions to unresolved `partitionValues` references, and rebuilding the `With` then called `nullable` on the unresolved attribute, failing with `[INTERNAL_ERROR] Invalid call to nullable on unresolved object`. This broke replaceWhere on partition columns with these predicates. Inline each `With` by substituting its common expression references before rewriting the partition attributes. Signed-off-by: Maha Rana Yadavalli <271375718+maharanay22@users.noreply.github.com>
1 of 8 tasks
Author
|
@murali-db @tdas could you approve the CI run and take a look when you have time? Same goes for #7840, #7841 and #7843, thanks |
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.
Which Delta project/connector is this regarding?
Description
Resolves #4776
On Spark 4,
BETWEENandNULLIFareRuntimeReplaceableexpressions whose replacement is aWithexpression that keeps the shared operand in aCommonExpressionDef. When replaceWhere targets partition columns,WriteIntoDeltadeletes the matching files throughDeleteCommand.performDelete, and that path callsDeltaLogUtils.rewritePartitionFilters. The rewrite turns every partitionAttributeintoCast(UnresolvedAttribute(partitionValues.<col>)), including the one inside theCommonExpressionDef. Rebuilding theWithnode then callsnullableon the unresolved attribute, so the write fails with[INTERNAL_ERROR] Invalid call to nullable on unresolved objectThis PR inlines
Withexpressions in the partition filters before the attribute rewrite by replacing eachCommonExpressionRefwith the child of its definition. Partition filters are deterministic, so evaluating the operand more than once is safe. Spark'sRewriteWithExpressionworks on logical plans and can't be applied to a standalone filter expression, so the inlining is done directlyHow was this patch tested?
Added a test in
DeltaSuitethat runs replaceWhere on a partitioned table withpart BETWEEN 2 AND 4,part NOT BETWEEN 2 AND 7andNULLIF(part, 3) IS NULLand checks that only the matching partitions get replaced. It also checks that writing a row outside theBETWEENrange still fails withDELTA_REPLACE_WHERE_MISMATCH. Without the fix the test fails with the internal error from the issue, and with the fix it passes. The change compiles against Spark 4.0, 4.1 and 4.2Does this PR introduce any user-facing changes?
Yes. replaceWhere with
BETWEEN,NOT BETWEENorNULLIFon partition columns used to fail with[INTERNAL_ERROR] Invalid call to nullable on unresolved objecton Delta 4.x with Spark 4. Now it replaces the matching partitions as expected