Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import org.scalactic.source.Position
import org.scalatest.Tag

import org.apache.spark.sql.{AnalysisException, QueryTest, Row}
import org.apache.spark.sql.catalyst.analysis.NoSuchPartitionsException
import org.apache.spark.sql.execution.datasources.PartitioningUtils
import org.apache.spark.sql.internal.SQLConf
import org.apache.spark.sql.test.SQLTestUtils
Expand Down Expand Up @@ -146,4 +147,20 @@ trait AlterTableDropPartitionSuiteBase extends QueryTest with SQLTestUtils {
assert(errMsg.contains(notFullPartitionSpecErr))
}
}

test("partition not exists") {
withNsTable("ns", "tbl") { t =>
sql(s"CREATE TABLE $t (id bigint, data string) $defaultUsing PARTITIONED BY (id)")
sql(s"ALTER TABLE $t ADD PARTITION (id=1) LOCATION 'loc'")

val errMsg = intercept[NoSuchPartitionsException] {
sql(s"ALTER TABLE $t DROP PARTITION (id=1), PARTITION (id=2)")
}.getMessage
assert(errMsg.contains("partitions not found in table"))

checkPartitions(t, Map("id" -> "1"))
sql(s"ALTER TABLE $t DROP IF EXISTS PARTITION (id=1), PARTITION (id=2)")
checkPartitions(t)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

package org.apache.spark.sql.execution.command.v1

import org.apache.spark.sql.catalyst.analysis.NoSuchPartitionsException
import org.apache.spark.sql.connector.catalog.CatalogManager
import org.apache.spark.sql.execution.command
import org.apache.spark.sql.test.SharedSparkSession
Expand All @@ -32,21 +31,4 @@ trait AlterTableDropPartitionSuiteBase extends command.AlterTableDropPartitionSu

class AlterTableDropPartitionSuite
extends AlterTableDropPartitionSuiteBase
with SharedSparkSession {

test("partition not exists") {
withNsTable("ns", "tbl") { t =>
sql(s"CREATE TABLE $t (id bigint, data string) $defaultUsing PARTITIONED BY (id)")
sql(s"ALTER TABLE $t ADD PARTITION (id=1) LOCATION 'loc'")

val errMsg = intercept[NoSuchPartitionsException] {
sql(s"ALTER TABLE $t DROP PARTITION (id=1), PARTITION (id=2)")
}.getMessage
assert(errMsg.contains("partitions not found in table"))

checkPartitions(t, Map("id" -> "1"))
sql(s"ALTER TABLE $t DROP IF EXISTS PARTITION (id=1), PARTITION (id=2)")
checkPartitions(t)
}
}
}
with SharedSparkSession
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package org.apache.spark.sql.execution.command.v2

import org.apache.spark.SparkConf
import org.apache.spark.sql.AnalysisException
import org.apache.spark.sql.catalyst.analysis.NoSuchPartitionsException
import org.apache.spark.sql.connector.{InMemoryPartitionTableCatalog, InMemoryTableCatalog}
import org.apache.spark.sql.execution.command
import org.apache.spark.sql.test.SharedSparkSession
Expand All @@ -38,22 +37,6 @@ class AlterTableDropPartitionSuite
.set(s"spark.sql.catalog.$catalog", classOf[InMemoryPartitionTableCatalog].getName)
.set(s"spark.sql.catalog.non_part_$catalog", classOf[InMemoryTableCatalog].getName)

test("partition not exists") {
withNsTable("ns", "tbl") { t =>
sql(s"CREATE TABLE $t (id bigint, data string) $defaultUsing PARTITIONED BY (id)")
sql(s"ALTER TABLE $t ADD PARTITION (id=1) LOCATION 'loc'")

val errMsg = intercept[NoSuchPartitionsException] {
sql(s"ALTER TABLE $t DROP PARTITION (id=1), PARTITION (id=2)")
}.getMessage
assert(errMsg.contains("partitions not found in table"))

checkPartitions(t, Map("id" -> "1"))
sql(s"ALTER TABLE $t DROP IF EXISTS PARTITION (id=1), PARTITION (id=2)")
checkPartitions(t)
}
}

test("SPARK-33650: drop partition into a table which doesn't support partition management") {
withNsTable("ns", "tbl", s"non_part_$catalog") { t =>
sql(s"CREATE TABLE $t (id bigint, data string) $defaultUsing")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ import org.apache.spark.internal.Logging
import org.apache.spark.metrics.source.HiveCatalogMetrics
import org.apache.spark.sql.AnalysisException
import org.apache.spark.sql.catalyst.TableIdentifier
import org.apache.spark.sql.catalyst.analysis.{NoSuchDatabaseException, NoSuchPartitionException, PartitionsAlreadyExistException}
import org.apache.spark.sql.catalyst.analysis.{NoSuchDatabaseException, NoSuchPartitionException, NoSuchPartitionsException, PartitionsAlreadyExistException}
import org.apache.spark.sql.catalyst.catalog._
import org.apache.spark.sql.catalyst.catalog.CatalogTypes.TablePartitionSpec
import org.apache.spark.sql.catalyst.expressions.Expression
Expand Down Expand Up @@ -630,9 +630,7 @@ private[hive] class HiveClientImpl(
// (b='1', c='1') and (b='1', c='2'), a partial spec of (b='1') will match both.
val parts = client.getPartitions(hiveTable, s.asJava).asScala
if (parts.isEmpty && !ignoreIfNotExists) {
throw new AnalysisException(
s"No partition is dropped. One partition spec '$s' does not exist in table '$table' " +
s"database '$db'")
throw new NoSuchPartitionsException(db, table, Seq(s))
}
parts.map(_.getValues)
}.distinct
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

package org.apache.spark.sql.hive.execution.command

import org.apache.spark.sql.AnalysisException
import org.apache.spark.sql.execution.command.v1
import org.apache.spark.sql.hive.test.TestHiveSingleton

Expand All @@ -27,22 +26,4 @@ class AlterTableDropPartitionSuite

override def version: String = "Hive V1"
override def defaultUsing: String = "USING HIVE"

override protected val notFullPartitionSpecErr = "No partition is dropped"

test("partition not exists") {
withNsTable("ns", "tbl") { t =>
sql(s"CREATE TABLE $t (id bigint, data string) $defaultUsing PARTITIONED BY (id)")
sql(s"ALTER TABLE $t ADD PARTITION (id=1) LOCATION 'loc'")

val errMsg = intercept[AnalysisException] {
sql(s"ALTER TABLE $t DROP PARTITION (id=1), PARTITION (id=2)")
}.getMessage
assert(errMsg.contains("No partition is dropped"))

checkPartitions(t, Map("id" -> "1"))
sql(s"ALTER TABLE $t DROP IF EXISTS PARTITION (id=1), PARTITION (id=2)")
checkPartitions(t)
}
}
}