cloud-fan commented on a change in pull request #25502: [SPARK-28668][SQL][WIP] Support V2SessionCatalog for ALTER TABLE URL: https://github.com/apache/spark/pull/25502#discussion_r319036933
########## File path: sql/core/src/test/scala/org/apache/spark/sql/sources/v2/AlterTableTests.scala ########## @@ -0,0 +1,850 @@ +/* + * 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.sources.v2 + +import scala.collection.JavaConverters._ + +import org.apache.spark.SparkException +import org.apache.spark.sql.AnalysisException +import org.apache.spark.sql.test.SharedSparkSession +import org.apache.spark.sql.types._ + +trait AlterTableTests extends SharedSparkSession { + + protected def getTableMetadata(tableName: String): Table + + protected val catalogAndNamespace: String + + protected val v2Format: String + + private def fullTableName(tableName: String): String = { + if (catalogAndNamespace.isEmpty) { + s"default.$tableName" + } else { + s"${catalogAndNamespace}table_name" + } + } + + test("AlterTable: table does not exist") { + val t2 = s"${catalogAndNamespace}fake_table" + withTable(t2) { + sql(s"CREATE TABLE $t2 (id int) USING $v2Format") + val exc = intercept[AnalysisException] { + sql(s"ALTER TABLE ${catalogAndNamespace}table_name DROP COLUMN id") + } + + assert(exc.getMessage.contains(s"${catalogAndNamespace}table_name")) + assert(exc.getMessage.contains("Table or view not found")) + } + } + + test("AlterTable: change rejected by implementation") { + val t = s"${catalogAndNamespace}table_name" + withTable(t) { + sql(s"CREATE TABLE $t (id int) USING $v2Format") + + val exc = intercept[SparkException] { + sql(s"ALTER TABLE $t DROP COLUMN id") + } + + assert(exc.getMessage.contains("Unsupported table change")) + assert(exc.getMessage.contains("Cannot drop all fields")) // from the implementation Review comment: can we also test dropping all the fields of a struct-type column? ---------------------------------------------------------------- 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]
