Skip to content

Conversation

@allisonport-db
Copy link
Contributor

What changes were proposed in this pull request?

#38823 added support for defining generated columns in create table statements. This included generation expression validation. This validation currently erroneously fails when there are char or varchar columns anywhere in the table schema since the checkAnalysis fails here https://github.com/apache/spark/blob/master/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/util/GeneratedColumn.scala#L123.

This PR replaces any char/varchar columns in the schema with a string before analysis.

Why are the changes needed?

This should not fail.

CREATE TABLE default.example (
    name VARCHAR(64),
    tstamp TIMESTAMP,
    tstamp_date DATE GENERATED ALWAYS AS (CAST(tstamp as DATE))
)

Does this PR introduce any user-facing change?

No.

How was this patch tested?

Adds a unit test.

@github-actions github-actions bot added the SQL label Jul 5, 2023
@allisonport-db allisonport-db changed the title [SPARK-44313] Fix generated column expression validation when there is a char/varchar column in the schema [SPARK-44313][SQL] Fix generated column expression validation when there is a char/varchar column in the schema Jul 5, 2023
Copy link

@ShreyeshArangath ShreyeshArangath left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for fixing this

@yaooqinn yaooqinn closed this in f0e1828 Jul 6, 2023
yaooqinn pushed a commit that referenced this pull request Jul 6, 2023
…ere is a char/varchar column in the schema

### What changes were proposed in this pull request?

#38823 added support for defining generated columns in create table statements. This included generation expression validation. This validation currently erroneously fails when there are char or varchar columns anywhere in the table schema since the checkAnalysis fails here https://github.com/apache/spark/blob/master/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/util/GeneratedColumn.scala#L123.

This PR replaces any char/varchar columns in the schema with a string before analysis.

### Why are the changes needed?

This should not fail.
```
CREATE TABLE default.example (
    name VARCHAR(64),
    tstamp TIMESTAMP,
    tstamp_date DATE GENERATED ALWAYS AS (CAST(tstamp as DATE))
)
```

### Does this PR introduce _any_ user-facing change?

No.

### How was this patch tested?

Adds a unit test.

Closes #41868 from allisonport-db/validateGeneratedColumns-charvarchar.

Authored-by: Allison Portis <allison.portis@databricks.com>
Signed-off-by: Kent Yao <yao@apache.org>
(cherry picked from commit f0e1828)
Signed-off-by: Kent Yao <yao@apache.org>
@yaooqinn
Copy link
Member

yaooqinn commented Jul 6, 2023

thanks @allisonport-db @cloud-fan @ShreyeshArangath merged to master and 3.4

viirya pushed a commit to viirya/spark-1 that referenced this pull request Oct 19, 2023
…ere is a char/varchar column in the schema

### What changes were proposed in this pull request?

apache#38823 added support for defining generated columns in create table statements. This included generation expression validation. This validation currently erroneously fails when there are char or varchar columns anywhere in the table schema since the checkAnalysis fails here https://github.com/apache/spark/blob/master/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/util/GeneratedColumn.scala#L123.

This PR replaces any char/varchar columns in the schema with a string before analysis.

### Why are the changes needed?

This should not fail.
```
CREATE TABLE default.example (
    name VARCHAR(64),
    tstamp TIMESTAMP,
    tstamp_date DATE GENERATED ALWAYS AS (CAST(tstamp as DATE))
)
```

### Does this PR introduce _any_ user-facing change?

No.

### How was this patch tested?

Adds a unit test.

Closes apache#41868 from allisonport-db/validateGeneratedColumns-charvarchar.

Authored-by: Allison Portis <allison.portis@databricks.com>
Signed-off-by: Kent Yao <yao@apache.org>
(cherry picked from commit f0e1828)
Signed-off-by: Kent Yao <yao@apache.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants