Repository navigation
[Spark] Allow BETWEEN in generated column expressions - #7843
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, `v BETWEEN 0 AND 10` resolves to a `Between` expression whose replacement is a `With` expression. `With` and `CommonExpressionDef/Ref` were added to the allowlist in delta-io#7634, but `Between` itself was not, so creating a table with a generated column that uses BETWEEN fails with DELTA_UNSUPPORTED_EXPRESSION_GENERATED_COLUMN. Add `Between` to AllowedUserProvidedExpressions next to the other predicates. Signed-off-by: Maha Rana Yadavalli <271375718+maharanay22@users.noreply.github.com>
1 of 5 tasks
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 #7842
On Spark 4,
v BETWEEN 0 AND 10resolves to aBetweenexpression whose replacement is aWithexpression. #7634 addedWithandCommonExpressionDef/Refto AllowedUserProvidedExpressions for NULLIF, butBetweenitself was not added, soCREATE TABLE t (v INT, g BOOLEAN GENERATED ALWAYS AS (v BETWEEN 0 AND 10)) USING deltafails with DELTA_UNSUPPORTED_EXPRESSION_GENERATED_COLUMN. This addsBetweennext to the other predicates.Betweenexists in all supported Spark versions (4.0, 4.1 and 4.2), so no shim is neededHow was this patch tested?
New test in GeneratedColumnSuite, modeled on the NULLIF test from #7634. With spark.sql.optimizer.alwaysInlineCommonExpr set to both false and true, it creates a table with a BETWEEN generated column, inserts rows, checks the generated values, and checks that an explicit value that doesn't match the expression is rejected. It fails without the fix with DELTA_UNSUPPORTED_EXPRESSION_GENERATED_COLUMN and passes with it. GeneratedColumnSuite and CheckConstraintsSuite show no other differences with and without the fix
Does this PR introduce any user-facing changes?
Yes. Generated columns can now use BETWEEN. Previously creating them failed with DELTA_UNSUPPORTED_EXPRESSION_GENERATED_COLUMN