Skip to content

Commit

Permalink
fix applyClusterByChanges
Browse files Browse the repository at this point in the history
  • Loading branch information
zedtang committed Jul 10, 2024
1 parent 0fdebcc commit 17b152f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
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),
Expand Down

0 comments on commit 17b152f

Please sign in to comment.