pan3793 commented on code in PR #7436:
URL: https://github.com/apache/kyuubi/pull/7436#discussion_r3226370718


##########
extensions/spark/kyuubi-spark-connector-hive/src/main/scala/org/apache/kyuubi/spark/connector/hive/read/HiveRuntimeFilterSupport.scala:
##########
@@ -0,0 +1,115 @@
+/*
+ * 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.kyuubi.spark.connector.hive.read
+
+import java.util.Locale
+
+import org.apache.spark.internal.Logging
+import org.apache.spark.sql.catalyst.expressions.{AttributeReference, 
Expression, InSet}
+import org.apache.spark.sql.connector.expressions.{Expressions, Literal => 
V2Literal, NamedReference}
+import org.apache.spark.sql.connector.expressions.filter.Predicate
+import org.apache.spark.sql.hive.kyuubi.connector.HiveBridgeHelper.{sameType, 
StructTypeHelper}
+import org.apache.spark.sql.types.StructType
+
+/**
+ * Helpers for a Hive-backed V2 [[org.apache.spark.sql.connector.read.Scan]] to
+ * implement [[org.apache.spark.sql.connector.read.SupportsRuntimeV2Filtering]]
+ * for Dynamic Partition Pruning (DPP).
+ *
+ * Spark's `DataSourceV2Strategy` currently only emits the `IN` form of V2
+ * [[Predicate]] as a DPP runtime filter, so translation here handles `IN` 
only.
+ * Any predicate that does not match the expected shape (single partition 
column
+ * ref + scalar literals with matching dataType) is dropped as a whole to
+ * avoid incorrect pruning; drops are logged at DEBUG.
+ */
+object HiveRuntimeFilterSupport extends Logging {
+
+  /**
+   * Build the runtime-filterable attribute array. Only partition columns are 
exposed
+   * because DPP is only beneficial at the partition directory granularity.
+   */
+  def filterAttributes(partitionColumnNames: Seq[String]): 
Array[NamedReference] = {
+    partitionColumnNames.map(Expressions.column).toArray
+  }
+
+  /**
+   * Translate Spark's runtime V2 `IN` predicates into catalyst `InSet(attr, 
Set[Any])`
+   * expressions bound to the given partition attributes.
+   */
+  def toCatalystPartitionFilters(

Review Comment:
   This makes the code compatibility very fragile, catalyst code is treated as 
internal implementation details and does not provide any compatibility 
guarantee.
   
   Given the situation, why choose to implement `SupportsRuntimeV2Filtering` 
and translate the V2 `Predicate` to the catalyst `Filter` instead of just 
implement `SupportsRuntimeFiltering`?



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