Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SPARK-33667][SQL] Respect the spark.sql.caseSensitive config while resolving partition spec in v1 SHOW PARTITIONS #30615

Closed
Closed
Show file tree
Hide file tree
Changes from 4 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 @@ -1006,20 +1006,18 @@ case class ShowPartitionsCommand(
DDLUtils.verifyPartitionProviderIsHive(sparkSession, table, "SHOW PARTITIONS")

/**
* Validate the partitioning spec by making sure all the referenced columns are
* Normalizes the partition spec w.r.t the partition columns and case sensitivity settings,
* and validates the spec by making sure all the referenced columns are
* defined as partitioning columns in table definition. An AnalysisException exception is
* thrown if the partitioning spec is invalid.
*/
if (spec.isDefined) {
val badColumns = spec.get.keySet.filterNot(table.partitionColumnNames.contains)
if (badColumns.nonEmpty) {
val badCols = badColumns.mkString("[", ", ", "]")
throw new AnalysisException(
s"Non-partitioning column(s) $badCols are specified for SHOW PARTITIONS")
}
}
Comment on lines -1013 to -1020
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This duplicates the check inside of normalizePartitionSpec()

val normalizedSpec = spec.map(partitionSpec => PartitioningUtils.normalizePartitionSpec(
partitionSpec,
table.partitionColumnNames,
table.identifier.quotedString,
sparkSession.sessionState.conf.resolver))

val partNames = catalog.listPartitionNames(tableName, spec)
val partNames = catalog.listPartitionNames(tableName, normalizedSpec)
partNames.map(Row(_))
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ import org.scalactic.source.Position
import org.scalatest.Tag

import org.apache.spark.sql.{AnalysisException, QueryTest, Row}
import org.apache.spark.sql.internal.SQLConf
import org.apache.spark.sql.test.SQLTestUtils
import org.apache.spark.sql.types.{StringType, StructType}

trait ShowPartitionsSuiteBase extends QueryTest with SQLTestUtils {
protected def version: String
protected def catalog: String
protected def defaultUsing: String
protected def wrongPartitionColumnsError(columns: String*): String
// Gets the schema of `SHOW PARTITIONS`
private val showSchema: StructType = new StructType().add("partition", StringType, false)
protected def runShowPartitionsSql(sqlText: String, expected: Seq[Row]): Unit = {
Expand Down Expand Up @@ -94,7 +94,7 @@ trait ShowPartitionsSuiteBase extends QueryTest with SQLTestUtils {
val errMsg = intercept[AnalysisException] {
sql(s"SHOW PARTITIONS $table PARTITION(abcd=2015, xyz=1)")
}.getMessage
assert(errMsg.contains(wrongPartitionColumnsError("abcd", "xyz")))
assert(errMsg.contains("abcd is not a valid partition column"))
}
}
}
Expand Down Expand Up @@ -149,4 +149,28 @@ trait ShowPartitionsSuiteBase extends QueryTest with SQLTestUtils {
}
}
}

test("case sensitivity of partition spec") {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shall we add a JIRA prefix @MaxGekk?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test already has prefixes V1, V2 or Hive V1. If I add one more prefix, this will look not beauty, though...

withNamespace(s"$catalog.ns") {
sql(s"CREATE NAMESPACE $catalog.ns")
val t = s"$catalog.ns.part_table"
withTable(t) {
sql(s"""
|CREATE TABLE $t (price int, qty int, year int, month int)
|$defaultUsing
|PARTITIONED BY (year, month)""".stripMargin)
sql(s"INSERT INTO $t PARTITION(year = 2015, month = 1) SELECT 1, 1")
Seq(
true -> "PARTITION(year = 2015, month = 1)",
false -> "PARTITION(YEAR = 2015, Month = 1)"
).foreach { case (caseSensitive, partitionSpec) =>
withSQLConf(SQLConf.CASE_SENSITIVE.key -> caseSensitive.toString) {
runShowPartitionsSql(
s"SHOW PARTITIONS $t $partitionSpec",
Row("year=2015/month=1") :: Nil)
}
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@ trait ShowPartitionsSuiteBase extends command.ShowPartitionsSuiteBase {
override def catalog: String = CatalogManager.SESSION_CATALOG_NAME
override def defaultUsing: String = "USING parquet"

override protected def wrongPartitionColumnsError(columns: String*): String = {
s"Non-partitioning column(s) ${columns.mkString("[", ", ", "]")} are specified"
}

test("show everything in the default database") {
val table = "dateTable"
withTable(table) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,6 @@ class ShowPartitionsSuite extends command.ShowPartitionsSuiteBase with SharedSpa
.set(s"spark.sql.catalog.$catalog", classOf[InMemoryPartitionTableCatalog].getName)
.set(s"spark.sql.catalog.non_part_$catalog", classOf[InMemoryTableCatalog].getName)

override protected def wrongPartitionColumnsError(columns: String*): String = {
s"${columns.head} is not a valid partition column"
}

test("a table does not support partitioning") {
val table = s"non_part_$catalog.tab1"
withTable(table) {
Expand Down