forked from apache/spark
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SPARK-42978][SQL] Derby&PG: RENAME cannot qualify a new-table-Name w…
…ith a schema-Name ### What changes were proposed in this pull request? Fix `rename a table` in derby and pg, which schema name is not allowed to qualify the new table name ### Why are the changes needed? bugfix ### Does this PR introduce _any_ user-facing change? introduce a new error class ```json "CANNOT_RENAME_ACROSS_SCHEMA" : { "message" : [ "Renaming a <type> across schemas is not allowed." ], "sqlState" : "0AKD0" }, ``` ### How was this patch tested? new unit test Closes apache#40602 from yaooqinn/SPARK-42978. Authored-by: Kent Yao <[email protected]> Signed-off-by: Kent Yao <[email protected]>
- Loading branch information
Showing
13 changed files
with
127 additions
and
13 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
54 changes: 54 additions & 0 deletions
54
...est/scala/org/apache/spark/sql/execution/datasources/v2/jdbc/DerbyTableCatalogSuite.scala
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.apache.spark.sql.execution.datasources.v2.jdbc | ||
|
||
import org.apache.spark.{SparkConf, SparkThrowable} | ||
import org.apache.spark.sql.{AnalysisException, QueryTest, Row} | ||
import org.apache.spark.sql.test.SharedSparkSession | ||
import org.apache.spark.sql.types.MetadataBuilder | ||
import org.apache.spark.util.Utils | ||
|
||
class DerbyTableCatalogSuite extends QueryTest with SharedSparkSession { | ||
|
||
val tempDir = Utils.createTempDir() | ||
val url = s"jdbc:derby:memory:${tempDir.getCanonicalPath};create=true" | ||
val defaultMetadata = new MetadataBuilder().putLong("scale", 0).build() | ||
|
||
override def sparkConf: SparkConf = { | ||
super.sparkConf | ||
.set("spark.sql.catalog.derby", classOf[JDBCTableCatalog].getName) | ||
.set("spark.sql.catalog.derby.url", url) | ||
.set("spark.sql.catalog.derby.driver", "org.apache.derby.jdbc.EmbeddedDriver") | ||
} | ||
|
||
test("SPARK-42978: RENAME cannot qualify a new-table-Name with a schema-Name.") { | ||
val n1t1 = "derby.test1.table1" | ||
val n1t2 = "test1.table2" | ||
val n2t2 = "test2.table2" | ||
|
||
withTable(n1t1, n1t2) { | ||
sql(s"CREATE TABLE $n1t1(c1 int)") | ||
checkError( | ||
exception = intercept[AnalysisException]( | ||
sql(s"ALTER TABLE $n1t1 RENAME TO $n2t2")).getCause.asInstanceOf[SparkThrowable], | ||
errorClass = "CANNOT_RENAME_ACROSS_SCHEMA", | ||
parameters = Map("type" -> "table")) | ||
sql(s"ALTER TABLE $n1t1 RENAME TO $n1t2") | ||
checkAnswer(sql(s"SHOW TABLES IN derby.test1"), Row("test1", "TABLE2", false)) | ||
} | ||
} | ||
} |