hudi-agent commented on code in PR #18277:
URL: https://github.com/apache/hudi/pull/18277#discussion_r3346373388


##########
hudi-spark-datasource/hudi-spark-common/src/main/scala/org/apache/spark/sql/hudi/v2/HoodieScanBuilder.scala:
##########
@@ -0,0 +1,641 @@
+/*
+ * 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.v2
+
+import org.apache.hudi.{DataSourceReadOptions, HoodieBaseRelation, 
HoodieDataSourceHelper, HoodieFileIndex, HoodieSparkUtils, SparkAdapterSupport}
+import org.apache.hudi.client.utils.SparkInternalSchemaConverter
+import org.apache.hudi.common.config.HoodieMetadataConfig
+import org.apache.hudi.common.engine.HoodieLocalEngineContext
+import org.apache.hudi.common.model.HoodieTableType.COPY_ON_WRITE
+import org.apache.hudi.common.schema.HoodieSchema
+import org.apache.hudi.common.table.{HoodieTableMetaClient, 
TableSchemaResolver}
+import org.apache.hudi.common.table.timeline.TimelineLayout
+import org.apache.hudi.common.util.{Option => HOption}
+import org.apache.hudi.common.util.collection.Pair
+import org.apache.hudi.config.HoodieBootstrapConfig
+import org.apache.hudi.internal.schema.InternalSchema
+import org.apache.hudi.internal.schema.utils.SerDeHelper
+import org.apache.hudi.metadata.{HoodieBackedTableMetadata, 
MetadataPartitionType}
+import org.apache.hudi.stats.HoodieColumnRangeMetadata
+import org.apache.hudi.util.SparkConfigUtils
+
+import org.apache.spark.sql.HoodieCatalystExpressionUtils
+import org.apache.spark.sql.SparkSession
+import org.apache.spark.sql.catalyst.InternalRow
+import org.apache.spark.sql.catalyst.expressions.{Expression, 
GenericInternalRow}
+import org.apache.spark.sql.connector.expressions.NamedReference
+import org.apache.spark.sql.connector.expressions.aggregate.{Aggregation, 
Count, CountStar, Max, Min}
+import org.apache.spark.sql.connector.read.{InputPartition, Scan, ScanBuilder, 
SupportsPushDownAggregates, SupportsPushDownFilters, 
SupportsPushDownRequiredColumns}
+import org.apache.spark.sql.execution.datasources.FileFormat
+import org.apache.spark.sql.hudi.HoodieSqlCommonUtils
+import org.apache.spark.sql.hudi.v2.HoodieScanBuilder.{CountStarAbsent, 
CountStarColumn, CountStarMissingTarget, CountStarWithColumn}
+import org.apache.spark.sql.sources.Filter
+import org.apache.spark.sql.types.{BooleanType, ByteType, DataType, 
DoubleType, FloatType, IntegerType, LongType, ShortType, StringType, 
StructField, StructType}
+import org.apache.spark.unsafe.types.UTF8String
+import org.apache.spark.util.SerializableConfiguration
+import org.slf4j.LoggerFactory
+
+import scala.collection.JavaConverters._
+
+/**
+ * Scan builder for DSv2 CoW snapshot reads.
+ */
+class HoodieScanBuilder(spark: SparkSession,
+                        metaClient: HoodieTableMetaClient,
+                        tableSchema: StructType,
+                        options: Map[String, String]) extends ScanBuilder
+  with SupportsPushDownFilters
+  with SupportsPushDownRequiredColumns
+  with HoodiePartialLimitPushDown
+  with SupportsPushDownAggregates
+  with SparkAdapterSupport {
+
+  private val log = LoggerFactory.getLogger(getClass)
+
+  private var requiredSchema: StructType = tableSchema
+  private var _pushedFilters: Array[Filter] = Array.empty
+  private var partitionFilterExprs: Seq[Expression] = Seq.empty
+  private var dataFilterExprs: Seq[Expression] = Seq.empty
+  private var hasPostScanFilters: Boolean = false
+
+  private var pushedLimit: Option[Int] = None
+  private var pushedAggregation: Option[Aggregation] = None
+  private var aggregateResult: Option[Array[InternalRow]] = None
+
+  private lazy val fileIndex = HoodieFileIndex(spark, metaClient, 
Some(tableSchema), options,
+    includeLogFiles = false, shouldEmbedFileSlices = false)
+
+  override def pushFilters(filters: Array[Filter]): Array[Filter] = {
+    val (pushed, postScan) = filters.partition { f =>
+      HoodieCatalystExpressionUtils.convertToCatalystExpression(f, 
tableSchema).isDefined
+    }
+
+    val expressions = pushed.flatMap(f =>
+      HoodieCatalystExpressionUtils.convertToCatalystExpression(f, 
tableSchema))
+
+    val (partFilters, datFilters) = HoodieCatalystExpressionUtils
+      .splitPartitionAndDataPredicates(spark, expressions, 
fileIndex.partitionSchema.fieldNames)

Review Comment:
   🤖 nit: could this be `dataFilters` instead of `datFilters`? It reads like a 
truncation, and the field it feeds into is named `dataFilterExprs` — keeping 
the `data` prefix consistent would make the connection clearer at a glance.
   
   <sub><i>- AI-generated; verify before applying. React 👍/👎 to flag 
quality.</i></sub>



##########
hudi-spark-datasource/hudi-spark-common/src/main/scala/org/apache/spark/sql/hudi/v2/HoodiePartitionReaderFactory.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.v2
+
+import org.apache.hudi.common.schema.HoodieSchema
+import org.apache.hudi.common.util.{Option => HOption}
+import org.apache.hudi.internal.schema.InternalSchema
+
+import org.apache.spark.broadcast.Broadcast
+import org.apache.spark.sql.catalyst.InternalRow
+import org.apache.spark.sql.connector.read.{InputPartition, PartitionReader, 
PartitionReaderFactory}
+import org.apache.spark.sql.execution.datasources.SparkColumnarFileReader
+import org.apache.spark.sql.sources.Filter
+import org.apache.spark.sql.types.StructType
+import org.apache.spark.util.SerializableConfiguration
+
+/**
+ * Factory that creates partition readers for COW snapshot reads.
+ */
+class HoodiePartitionReaderFactory(broadcastReader: 
Broadcast[SparkColumnarFileReader],
+                                   broadcastConf: 
Broadcast[SerializableConfiguration],

Review Comment:
   🤖 nit: the six schema/filter params (`requiredDataSchema`, 
`requiredPartitionSchema`, `internalSchemaOpt`, `pushedFilters`, `pushedLimit`, 
`tableAvroSchema`) appear with the same signatures in `HoodieBatchScan`, 
`HoodiePartitionReaderFactory`, and `HoodiePartitionReader` — have you 
considered grouping them into a small `HoodieScanContext` or similar value 
class so a future parameter addition only touches one place?
   
   <sub><i>- AI-generated; verify before applying. React 👍/👎 to flag 
quality.</i></sub>



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