yihua commented on code in PR #12772:
URL: https://github.com/apache/hudi/pull/12772#discussion_r2365859380


##########
hudi-spark-datasource/hudi-spark4-common/src/main/scala/org/apache/spark/sql/hudi/catalog/HoodieCatalog.scala:
##########
@@ -0,0 +1,421 @@
+/*
+ * 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.spark.sql.hudi.catalog
+
+import org.apache.hudi.{DataSourceWriteOptions, SparkAdapterSupport}
+import org.apache.hudi.client.common.HoodieSparkEngineContext
+import org.apache.hudi.common.config.HoodieMetadataConfig
+import org.apache.hudi.common.table.HoodieTableMetaClient
+import org.apache.hudi.common.table.view.FileSystemViewManager
+import org.apache.hudi.common.util.ConfigUtils
+import org.apache.hudi.exception.HoodieException
+import org.apache.hudi.hadoop.fs.HadoopFSUtils
+import org.apache.hudi.sql.InsertMode
+import org.apache.hudi.storage.StoragePath
+
+import org.apache.hadoop.fs.Path
+import org.apache.spark.sql.{Dataset, SaveMode, SparkSession, _}
+import org.apache.spark.sql.HoodieSparkCatalogUtils.MatchBucketTransform
+import org.apache.spark.sql.catalyst.TableIdentifier
+import org.apache.spark.sql.catalyst.analysis.{NoSuchTableException, 
TableAlreadyExistsException, UnresolvedAttribute}
+import org.apache.spark.sql.catalyst.catalog._
+import org.apache.spark.sql.catalyst.catalog.HoodieCatalogTable.needFilterProps
+import org.apache.spark.sql.connector.catalog._
+import 
org.apache.spark.sql.connector.catalog.CatalogV2Implicits.IdentifierHelper
+import org.apache.spark.sql.connector.catalog.TableChange.{AddColumn, 
ColumnChange, UpdateColumnComment, UpdateColumnType}
+import org.apache.spark.sql.connector.expressions.{FieldReference, 
IdentityTransform, Transform}
+import org.apache.spark.sql.execution.datasources.DataSource
+import org.apache.spark.sql.hudi.{HoodieSqlCommonUtils, ProvidesHoodieConfig}
+import 
org.apache.spark.sql.hudi.analysis.HoodieSparkBaseAnalysis.HoodieV1OrV2Table
+import 
org.apache.spark.sql.hudi.catalog.HoodieCatalog.{buildPartitionTransforms, 
isTablePartitioned}
+import org.apache.spark.sql.hudi.command._
+import org.apache.spark.sql.hudi.command.exception.HoodieAnalysisException
+import org.apache.spark.sql.types.{StructField, StructType}
+
+import java.net.URI
+import java.util
+
+import scala.collection.JavaConverters._
+import scala.collection.mutable
+
+class HoodieCatalog extends DelegatingCatalogExtension

Review Comment:
   Same on removing this class as the `hudi-spark-common` module contains the 
class with latest changes which are not reflected here.



##########
hudi-spark-datasource/hudi-spark4-common/src/main/scala/org/apache/spark/sql/hudi/catalog/BasicStagedTable.scala:
##########
@@ -0,0 +1,60 @@
+/*
+ * 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.spark.sql.hudi.catalog
+
+import org.apache.hudi.exception.HoodieException
+
+import org.apache.spark.sql.connector.catalog._
+import org.apache.spark.sql.connector.expressions.Transform
+import org.apache.spark.sql.connector.write.{LogicalWriteInfo, WriteBuilder}
+import org.apache.spark.sql.types.StructType
+
+import java.util
+
+/**
+ * Basic implementation that represents a table which is staged for being 
committed.
+ *
+ * @param ident   table ident
+ * @param table   table
+ * @param catalog table catalog
+ */
+case class BasicStagedTable(ident: Identifier,

Review Comment:
   This is the same as `BasicStagedTable` in `hudi-spark-common` module.  Can 
this be removed?



##########
hudi-spark-datasource/hudi-spark4-common/src/main/scala/org/apache/spark/sql/adapter/BaseSpark4Adapter.scala:
##########
@@ -0,0 +1,181 @@
+/*
+ * 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.spark.sql.adapter
+
+import org.apache.hudi.{AvroConversionUtils, DefaultSource, 
HoodiePartitionCDCFileGroupMapping, HoodiePartitionFileSliceMapping, 
Spark4HoodiePartitionCDCFileGroupMapping, 
Spark4HoodiePartitionFileSliceMapping, Spark4RowSerDe}
+import org.apache.hudi.client.model.{HoodieInternalRow, 
Spark4HoodieInternalRow}
+import org.apache.hudi.client.utils.SparkRowSerDe
+import org.apache.hudi.common.model.{FileSlice, HoodieRecord}
+import org.apache.hudi.common.table.HoodieTableMetaClient
+import org.apache.hudi.common.table.cdc.HoodieCDCFileSplit
+import org.apache.hudi.common.util.JsonUtils
+import org.apache.hudi.common.util.collection.{FlatLists, Spark4FlatLists}
+import org.apache.hudi.spark4.internal.ReflectUtil
+import org.apache.hudi.storage.StoragePath
+
+import org.apache.avro.Schema
+import org.apache.spark.api.java.JavaSparkContext
+import org.apache.spark.internal.Logging
+import org.apache.spark.sql.{AnalysisException, HoodieSpark4CatalogUtils, 
SparkSession, SQLContext}
+import org.apache.spark.sql.avro.{HoodieAvroSchemaConverters, 
HoodieSparkAvroSchemaConverters}
+import org.apache.spark.sql.catalyst.InternalRow
+import org.apache.spark.sql.catalyst.expressions.{Expression, 
InterpretedPredicate, Predicate}
+import org.apache.spark.sql.catalyst.parser.ParseException
+import org.apache.spark.sql.catalyst.trees.Origin
+import org.apache.spark.sql.catalyst.util.DateFormatter
+import org.apache.spark.sql.execution.{PartitionedFileUtil, QueryExecution, 
SQLExecution}
+import org.apache.spark.sql.execution.datasources._
+import org.apache.spark.sql.hudi.SparkAdapter
+import org.apache.spark.sql.sources.{BaseRelation, Filter}
+import org.apache.spark.sql.types.StructType
+import org.apache.spark.sql.vectorized.{ColumnarBatch, ColumnVector}
+import org.apache.spark.storage.StorageLevel
+import org.apache.spark.unsafe.types.UTF8String
+
+import java.time.ZoneId
+import java.util.TimeZone
+import java.util.concurrent.ConcurrentHashMap
+
+import scala.collection.JavaConverters._
+
+/**
+ * Base implementation of [[SparkAdapter]] for Spark 3.x branch
+ */
+abstract class BaseSpark4Adapter extends SparkAdapter with Logging {
+
+  JsonUtils.registerModules()
+
+  private val cache = new ConcurrentHashMap[ZoneId, DateFormatter](1)
+
+  def getCatalogUtils: HoodieSpark4CatalogUtils
+
+  override def createSparkRowSerDe(schema: StructType): SparkRowSerDe = {
+    new Spark4RowSerDe(getCatalystExpressionUtils.getEncoder(schema))
+  }
+
+  override def getAvroSchemaConverters: HoodieAvroSchemaConverters = 
HoodieSparkAvroSchemaConverters
+
+  override def getSparkParsePartitionUtil: SparkParsePartitionUtil = 
Spark4ParsePartitionUtil
+
+  override def getDateFormatter(tz: TimeZone): DateFormatter = {
+    cache.computeIfAbsent(tz.toZoneId, zoneId => 
ReflectUtil.getDateFormatter(zoneId))
+  }
+
+  /**
+   * Combine [[PartitionedFile]] to [[FilePartition]] according to 
`maxSplitBytes`.
+   */
+  override def getFilePartitions(
+      sparkSession: SparkSession,
+      partitionedFiles: Seq[PartitionedFile],
+      maxSplitBytes: Long): Seq[FilePartition] = {
+    FilePartition.getFilePartitions(sparkSession, partitionedFiles, 
maxSplitBytes)
+  }
+
+  override def createInterpretedPredicate(e: Expression): InterpretedPredicate 
= {
+    Predicate.createInterpreted(e)
+  }
+
+  override def createRelation(sqlContext: SQLContext,
+                              metaClient: HoodieTableMetaClient,
+                              schema: Schema,
+                              globPaths: Array[StoragePath],
+                              parameters: java.util.Map[String, String]): 
BaseRelation = {
+    val dataSchema = 
Option(schema).map(AvroConversionUtils.convertAvroSchemaToStructType).orNull
+    DefaultSource.createRelation(sqlContext, metaClient, dataSchema, 
globPaths, parameters.asScala.toMap)
+  }
+
+  override def convertStorageLevelToString(level: StorageLevel): String
+
+  override def translateFilter(predicate: Expression,
+                               supportNestedPredicatePushdown: Boolean = 
false): Option[Filter] = {
+    DataSourceStrategy.translateFilter(predicate, 
supportNestedPredicatePushdown)
+  }
+
+  override def makeColumnarBatch(vectors: Array[ColumnVector], numRows: Int): 
ColumnarBatch = {
+    new ColumnarBatch(vectors, numRows)
+  }
+
+  override def sqlExecutionWithNewExecutionId[T](sparkSession: SparkSession,
+                                                 queryExecution: 
QueryExecution,
+                                                 name: Option[String])(body: 
=> T): T = {
+      SQLExecution.withNewExecutionId(queryExecution, name)(body)
+  }
+
+  def stopSparkContext(jssc: JavaSparkContext, exitCode: Int): Unit
+
+  override def compareUTF8String(a: UTF8String, b: UTF8String): Int = 
a.binaryCompare(b)
+
+  override def createComparableList(t: Array[AnyRef]): 
FlatLists.ComparableList[Comparable[HoodieRecord[_]]] = 
Spark4FlatLists.ofComparableArray(t)
+
+  override def createInternalRow(commitTime: UTF8String,
+                                 commitSeqNumber: UTF8String,
+                                 recordKey: UTF8String,
+                                 partitionPath: UTF8String,
+                                 fileName: UTF8String,
+                                 sourceRow: InternalRow,
+                                 sourceContainsMetaFields: Boolean): 
HoodieInternalRow = {
+    new Spark4HoodieInternalRow(commitTime, commitSeqNumber, recordKey, 
partitionPath, fileName, sourceRow, sourceContainsMetaFields)
+  }
+
+  override def createInternalRow(metaFields: Array[UTF8String],
+                                 sourceRow: InternalRow,
+                                 sourceContainsMetaFields: Boolean): 
HoodieInternalRow = {
+    new Spark4HoodieInternalRow(metaFields, sourceRow, 
sourceContainsMetaFields)
+  }
+
+  override def createHoodiePartitionCDCFileGroupMapping(partitionValues: 
InternalRow,
+                                                        fileSplits: 
List[HoodieCDCFileSplit]): HoodiePartitionCDCFileGroupMapping = {
+    new Spark4HoodiePartitionCDCFileGroupMapping(partitionValues, fileSplits)
+  }
+
+  override def createHoodiePartitionFileSliceMapping(values: InternalRow,
+                                                     slices: Map[String, 
FileSlice]): HoodiePartitionFileSliceMapping = {
+    new Spark4HoodiePartitionFileSliceMapping(values, slices)
+  }
+
+  override def newParseException(command: Option[String],
+                                 exception: AnalysisException,
+                                 start: Origin,
+                                 stop: Origin): ParseException = {
+    new ParseException(command, start, stop, exception.getErrorClass, 
exception.getMessageParameters.asScala.toMap)

Review Comment:
   Got it.  Thanks for the clarification!



-- 
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]

Reply via email to