zhongyujiang commented on code in PR #5531: URL: https://github.com/apache/paimon/pull/5531#discussion_r2062631195
########## paimon-spark/paimon-spark-common/src/main/scala/org/apache/paimon/spark/SparkWriteRequirement.scala: ########## @@ -0,0 +1,67 @@ +/* + * 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.paimon.spark + +import org.apache.paimon.table.{BucketMode, FileStoreTable} + +import org.apache.spark.sql.connector.distributions.{ClusteredDistribution, Distribution, Distributions} +import org.apache.spark.sql.connector.expressions.{Expression, Expressions, SortOrder} + +import scala.collection.JavaConverters._ + +/** Distribution requirements of Spark write. */ +case class SparkWriteRequirement(distribution: Distribution, ordering: Array[SortOrder]) + +object SparkWriteRequirement { + private val EMPTY_ORDERING: Array[SortOrder] = Array.empty + private val EMPTY: SparkWriteRequirement = + SparkWriteRequirement(Distributions.unspecified(), EMPTY_ORDERING) + + def apply(table: FileStoreTable): SparkWriteRequirement = { + val bucketSpec = table.bucketSpec() + val bucketExpr = bucketSpec.getBucketMode match { + case BucketMode.HASH_FIXED => + Seq( + Expressions.bucket( + bucketSpec.getNumBuckets, + bucketSpec.getBucketKeys.asScala.map(quote).toArray: _*)) + case BucketMode.BUCKET_UNAWARE => + Seq.empty + case _ => + throw new UnsupportedOperationException( + s"Unsupported bucket mode ${bucketSpec.getBucketMode}") + } + + val partitionExprs = + table.schema().partitionKeys().asScala.map(key => Expressions.identity(quote(key))) + + val clusteringExpressions: Seq[Expression] = partitionExprs ++ bucketExpr Review Comment: This is requesting clustering based on partition and bucket, and when calculating the bucket, only the bucket columns will be used. I think the bucket within each partition is the smallest unit of clustering. If clustering is done only by bucket, the same bucket across different partitions may be assigned to a single task, which could cause data skew, right? -- 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. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
