Skip to content

[Spark] Allow BETWEEN in generated column expressions - #7843

Open
maharanay22 wants to merge 1 commit into
delta-io:masterfrom
maharanay22:fix-generated-column-between
Open

maharanay22 wants to merge 1 commit into
delta-io:masterfrom
maharanay22:fix-generated-column-between

Conversation

@maharanay22

Copy link
Copy Markdown

Which Delta project/connector is this regarding?

  • Spark
  • Standalone
  • Flink
  • Kernel
  • Other (fill in here)

Description

Resolves #7842

On Spark 4, v BETWEEN 0 AND 10 resolves to a Between expression whose replacement is a With expression. #7634 added With and CommonExpressionDef/Ref to AllowedUserProvidedExpressions for NULLIF, but Between itself was not added, so CREATE TABLE t (v INT, g BOOLEAN GENERATED ALWAYS AS (v BETWEEN 0 AND 10)) USING delta fails with DELTA_UNSUPPORTED_EXPRESSION_GENERATED_COLUMN. This adds Between next to the other predicates. Between exists in all supported Spark versions (4.0, 4.1 and 4.2), so no shim is needed

How 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

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>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG][Spark] Generated column using BETWEEN fails with DELTA_UNSUPPORTED_EXPRESSION_GENERATED_COLUMN

1 participant