You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@spark.apache.org by ya...@apache.org on 2023/03/24 14:19:11 UTC
[spark] branch branch-3.4 updated: [SPARK-42917][SQL] Correct getUpdateColumnNullabilityQuery for DerbyDialect
This is an automated email from the ASF dual-hosted git repository.
yao pushed a commit to branch branch-3.4
in repository https://gitbox.apache.org/repos/asf/spark.git
The following commit(s) were added to refs/heads/branch-3.4 by this push:
new f5f53e4916d [SPARK-42917][SQL] Correct getUpdateColumnNullabilityQuery for DerbyDialect
f5f53e4916d is described below
commit f5f53e4916d57a767aa6db49bf4261599cbba5c7
Author: Kent Yao <ya...@apache.org>
AuthorDate: Fri Mar 24 22:18:11 2023 +0800
[SPARK-42917][SQL] Correct getUpdateColumnNullabilityQuery for DerbyDialect
### What changes were proposed in this pull request?
Fix nullability clause for derby dialect, according to the official derby lang ref guide.
### Why are the changes needed?
To fix bugs like:
```
spark-sql ()> create table src2(ID INTEGER NOT NULL, deptno INTEGER NOT NULL);
spark-sql ()> alter table src2 ALTER COLUMN ID drop not null;
java.sql.SQLSyntaxErrorException: Syntax error: Encountered "NULL" at line 1, column 42.
```
### Does this PR introduce _any_ user-facing change?
yes, but a necessary bugfix
### How was this patch tested?
Test manually.
Closes #40544 from yaooqinn/SPARK-42917.
Authored-by: Kent Yao <ya...@apache.org>
Signed-off-by: Kent Yao <ya...@apache.org>
(cherry picked from commit bcadbb69be6ac9759cb79fc4ee7bd93a37a63277)
Signed-off-by: Kent Yao <ya...@apache.org>
---
.../main/scala/org/apache/spark/sql/jdbc/DerbyDialect.scala | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/sql/core/src/main/scala/org/apache/spark/sql/jdbc/DerbyDialect.scala b/sql/core/src/main/scala/org/apache/spark/sql/jdbc/DerbyDialect.scala
index 439e0697d9f..3a7b644d281 100644
--- a/sql/core/src/main/scala/org/apache/spark/sql/jdbc/DerbyDialect.scala
+++ b/sql/core/src/main/scala/org/apache/spark/sql/jdbc/DerbyDialect.scala
@@ -66,6 +66,19 @@ private object DerbyDialect extends JdbcDialect {
throw QueryExecutionErrors.commentOnTableUnsupportedError()
}
+ // Derby Support 2 types of clauses for nullability constraint alteration
+ // columnName { SET | DROP } NOT NULL
+ // columnName [ NOT ] NULL
+ // Here we use the 2nd one
+ // For more information, https://db.apache.org/derby/docs/10.16/ref/rrefsqlj81859.html
+ override def getUpdateColumnNullabilityQuery(
+ tableName: String,
+ columnName: String,
+ isNullable: Boolean): String = {
+ val nullable = if (isNullable) "NULL" else "NOT NULL"
+ s"ALTER TABLE $tableName ALTER COLUMN ${quoteIdentifier(columnName)} $nullable"
+ }
+
override def getLimitClause(limit: Integer): String = {
""
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@spark.apache.org
For additional commands, e-mail: commits-help@spark.apache.org