malinjawi commented on code in PR #12215:
URL: https://github.com/apache/gluten/pull/12215#discussion_r3743351495


##########
gluten-delta/src/main/scala/org/apache/gluten/extension/DeltaDeletionVectorDmlUtils.scala:
##########
@@ -0,0 +1,166 @@
+/*
+ * 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.gluten.extension
+
+import org.apache.spark.sql.catalyst.expressions.{Expression, GetStructField, 
NamedExpression}
+import org.apache.spark.sql.catalyst.expressions.aggregation.BitmapAggregator
+import org.apache.spark.sql.catalyst.rules.Rule
+import org.apache.spark.sql.catalyst.trees.TreeNodeTag
+import org.apache.spark.sql.delta.DeltaParquetFileFormat
+import org.apache.spark.sql.delta.files.TahoeFileIndex
+import org.apache.spark.sql.delta.stats.PreparedDeltaFileIndex
+import org.apache.spark.sql.execution.{FileSourceScanExec, SparkPlan}
+import org.apache.spark.sql.types.{DataType, StructType}
+
+object DeltaDeletionVectorDmlUtils {
+  private val DmlRowIndexScanTag: TreeNodeTag[Boolean] =
+    TreeNodeTag[Boolean]("org.apache.gluten.delta.dml.row.index.scan")
+
+  // Spark 3.5+ exposes this as 
ParquetFileFormat.ROW_INDEX_TEMPORARY_COLUMN_NAME.
+  private val parquetTemporaryRowIndexColumnName = "_tmp_metadata_row_index"
+  private val deletionVectorRowIndexColumnNames =
+    Set(
+      "__delta_internal_row_index",
+      DeltaParquetFileFormat.ROW_INDEX_COLUMN_NAME,
+      parquetTemporaryRowIndexColumnName,
+      "row_index",
+      "rowIndexCol")
+  private val filePathColumnNames = Set("file_path", "filePath")
+
+  val tagDmlRowIndexScans: Rule[SparkPlan] = (plan: SparkPlan) => {
+    def visit(
+        node: SparkPlan,
+        hasRowIndexReference: Boolean,
+        hasFilePathReference: Boolean,
+        hasBitmapAggregation: Boolean): Unit = {
+      val nextHasBitmapAggregation =
+        hasBitmapAggregation || 
node.expressions.exists(referencesDeletionVectorBitmapAggregator)
+      // The row-index/file-path signature is only meaningful below Delta's 
BitmapAggregator.
+      // Avoid collecting expression references for every node in ordinary 
(non-DML) queries.
+      val nextHasRowIndexReference =
+        nextHasBitmapAggregation &&
+          (hasRowIndexReference || 
node.expressions.exists(referencesRowIndexColumn))
+      val nextHasFilePathReference =
+        nextHasBitmapAggregation &&
+          (hasFilePathReference || 
node.expressions.exists(referencesFilePathColumn))
+
+      node.children.foreach {
+        case scan: FileSourceScanExec
+            if nextHasBitmapAggregation &&
+              nextHasRowIndexReference &&
+              nextHasFilePathReference &&
+              hasDeletionVectorDmlRowIndexScanShape(scan) =>
+          scan.setTagValue(DmlRowIndexScanTag, true)
+        case child =>
+          visit(
+            child,
+            nextHasRowIndexReference,
+            nextHasFilePathReference,
+            nextHasBitmapAggregation)
+      }
+    }
+
+    visit(
+      plan,
+      hasRowIndexReference = false,
+      hasFilePathReference = false,
+      hasBitmapAggregation = false)
+    plan
+  }
+
+  def copyDmlRowIndexScanTag(from: SparkPlan, to: SparkPlan): Unit = {
+    if (from.getTagValue(DmlRowIndexScanTag).contains(true)) {
+      to.setTagValue(DmlRowIndexScanTag, true)
+    }
+  }
+
+  def isDeltaScan(scan: FileSourceScanExec): Boolean = {

Review Comment:
   @zhztheplayer 
   
   No duplicated implementation `OffloadDeltaScan.isDeltaScan` was a one-line 
delegate left behind when this PR moved its old private helpers into the utils 
object so the DML shape check could reuse them. 
   
   But agreed the organization was off for generic scan detection didn't belong 
in a DV-DML utils object. Reorganized now so the shared checks now live in 
`DeltaScanUtils`, `OffloadDeltaScan` calls it directly, and 
`DeltaDeletionVectorDmlUtils` keeps only the DML tagging and shape logic.



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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to