yaooqinn commented on a change in pull request #27110: [SPARK-30439][SQL]
Support NOT NULL in column data type
URL: https://github.com/apache/spark/pull/27110#discussion_r363573426
##########
File path:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/CheckAnalysis.scala
##########
@@ -466,6 +466,10 @@ trait CheckAnalysis extends PredicateHelper {
s"${field.dataType.simpleString} cannot be cast to " +
s"${update.newDataType.simpleString}")
}
+ if (!update.isNullable && field.nullable) {
+ throw new AnalysisException(
+ s"Cannot change optional column to required:
${field.name}")
Review comment:
```sql
postgres=# create table a(a int null);
CREATE TABLE
postgres=# create table bb(b int not null);
CREATE TABLE
postgres=# alter table a alter column a set not null;
ALTER TABLE
postgres=# alter table bb alter column b drop not null;
ALTER TABLE
postgres=# alter table a alter column a drop not null;
ALTER TABLE
postgres=# insert into a values(null);
INSERT 0 1
postgres=# alter table a alter column a set not null;
ERROR: column "a" contains null values
```
Postgres seems not to fail with analysis
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]