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-48760][SQL] Fix CatalogV2Util.applyClusterByChanges #47288

Closed
wants to merge 1 commit into from
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 @@ -178,16 +178,19 @@ private[sql] object CatalogV2Util {
schema: StructType,
changes: Seq[TableChange]): Array[Transform] = {

val newPartitioning = partitioning.filterNot(_.isInstanceOf[ClusterByTransform]).toBuffer
changes.foreach {
case clusterBy: ClusterBy =>
newPartitioning += ClusterBySpec.extractClusterByTransform(
var newPartitioning = partitioning
// If there is a clusterBy change (only the first one), we overwrite the existing
// clustering columns.
val clusterByOpt = changes.collectFirst { case c: ClusterBy => c }
clusterByOpt.foreach { clusterBy =>
newPartitioning = partitioning.map {
case _: ClusterByTransform => ClusterBySpec.extractClusterByTransform(
schema, ClusterBySpec(clusterBy.clusteringColumns.toIndexedSeq), conf.resolver)

case _ =>
// ignore other changes
case other => other
}
}
newPartitioning.toArray

newPartitioning
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,9 @@ trait DescribeTableSuiteBase extends QueryTest with DDLCommandTestUtils {

test("describe a clustered table") {
withNamespaceAndTable("ns", "tbl") { tbl =>
sql(s"CREATE TABLE $tbl (col1 STRING COMMENT 'this is comment', col2 struct<x:int, y:int>) " +
sql(s"CREATE TABLE $tbl (col1 STRING, col2 struct<x:int, y:int>) " +
s"$defaultUsing CLUSTER BY (col1, col2.x)")
sql(s"ALTER TABLE $tbl ALTER COLUMN col1 COMMENT 'this is comment';")
val descriptionDf = sql(s"DESC $tbl")
assert(descriptionDf.schema.map(field => (field.name, field.dataType)) === Seq(
("col_name", StringType),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This updated test would fail without the fix.

Expand Down