JingsongLi commented on code in PR #3067: URL: https://github.com/apache/incubator-paimon/pull/3067#discussion_r1534988679
########## paimon-spark/paimon-spark-common/src/main/scala/org/apache/paimon/spark/commands/BucketProcessor.scala: ########## @@ -0,0 +1,142 @@ +/* + * 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.commands + +import org.apache.paimon.data.{InternalRow => PaimonInternalRow} +import org.apache.paimon.index.HashBucketAssigner +import org.apache.paimon.spark.SparkRow +import org.apache.paimon.spark.util.EncoderUtils +import org.apache.paimon.table.{AbstractFileStoreTable, FileStoreTable} +import org.apache.paimon.table.sink.RowPartitionKeyExtractor + +import org.apache.spark.TaskContext +import org.apache.spark.sql.Row +import org.apache.spark.sql.catalyst.{InternalRow => SparkInternalRow} +import org.apache.spark.sql.catalyst.encoders.ExpressionEncoder +import org.apache.spark.sql.catalyst.encoders.ExpressionEncoder.{Deserializer, Serializer} +import org.apache.spark.sql.types.StructType + +import java.util.UUID + +case class EncoderSerDeGroup(schema: StructType) { + + val encoder: ExpressionEncoder[Row] = EncoderUtils.encode(schema).resolveAndBind() + + private val serializer: Serializer[Row] = encoder.createSerializer() + + private val deserializer: Deserializer[Row] = encoder.createDeserializer() + + def rowToInternal(row: Row): SparkInternalRow = { + serializer(row) + } + + def internalToRow(internalRow: SparkInternalRow): Row = { + deserializer(internalRow) + } +} + +sealed trait BucketProcessor { + def processPartition(rowIterator: Iterator[Row]): Iterator[Row] +} + +case class CommonBucketProcessor( + table: FileStoreTable, + bucketColIndex: Int, + encoderGroup: EncoderSerDeGroup) + extends BucketProcessor { + + def processPartition(rowIterator: Iterator[Row]): Iterator[Row] = { + val rowType = table.rowType() + val rowKeyExtractor = table.asInstanceOf[AbstractFileStoreTable].createRowKeyExtractor() Review Comment: If you want this extractor, you could introduce a `createRowKeyExtractor` to `FileStoreTable`. Subsequent matters related to permission security may require us to wrap a `FileStoreTable` class, so it is best to rely only on the interface rather than the implementation. -- 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: issues-unsubscr...@paimon.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org