huaxingao commented on code in PR #36918:
URL: https://github.com/apache/spark/pull/36918#discussion_r926056639
##########
sql/core/src/main/scala/org/apache/spark/sql/execution/dynamicpruning/PartitionPruning.scala:
##########
@@ -85,6 +85,13 @@ object PartitionPruning extends Rule[LogicalPlan] with
PredicateHelper with Join
} else {
None
}
+ case (resExp, r @ DataSourceV2ScanRelation(_, scan:
SupportsRuntimeV2Filtering, _, _, _)) =>
Review Comment:
I know it looks ugly to have duplicate code for both
`SupportsRuntimeFiltering` and `SupportsRuntimeV2Filtering`. I thought we will
deprecate and remove `SupportsRuntimeFiltering` in the future?
##########
sql/catalyst/src/test/scala/org/apache/spark/sql/connector/catalog/InMemoryTableWithV2Filter.scala:
##########
@@ -0,0 +1,77 @@
+/*
+ * 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.connector.catalog
+
+import java.util
+
+import org.apache.spark.sql.connector.expressions.{FieldReference,
LiteralValue, NamedReference, Transform}
+import org.apache.spark.sql.connector.expressions.filter.Predicate
+import org.apache.spark.sql.connector.read.{InputPartition, Scan, ScanBuilder,
SupportsRuntimeV2Filtering}
+import org.apache.spark.sql.types.StructType
+import org.apache.spark.sql.util.CaseInsensitiveStringMap
+
+class InMemoryTableWithV2Filter(
+ name: String,
+ schema: StructType,
+ partitioning: Array[Transform],
+ properties: util.Map[String, String])
+ extends InMemoryTable(name, schema, partitioning, properties) {
+
+ override def newScanBuilder(options: CaseInsensitiveStringMap): ScanBuilder
= {
+ new InMemoryV2FilterScanBuilder(schema)
+ }
+
+ class InMemoryV2FilterScanBuilder(tableSchema: StructType)
+ extends InMemoryScanBuilder(tableSchema) {
+ override def build: Scan =
+ InMemoryV2FilterBatchScan(data.map(_.asInstanceOf[InputPartition]),
schema, tableSchema)
+ }
+
+ case class InMemoryV2FilterBatchScan(
+ var _data: Seq[InputPartition],
+ readSchema: StructType,
+ tableSchema: StructType)
+ extends BatchScanBaseClass (_data, readSchema, tableSchema) with
SupportsRuntimeV2Filtering {
+
+ override def filterAttributes(): Array[NamedReference] = {
+ val scanFields = readSchema.fields.map(_.name).toSet
+ partitioning.flatMap(_.references)
+ .filter(ref => scanFields.contains(ref.fieldNames.mkString(".")))
+ }
+
+ override def filter(filters: Array[Predicate]): Unit = {
+ if (partitioning.length == 1 && partitioning.head.references().length ==
1) {
+ val ref = partitioning.head.references().head
+ filters.foreach {
+ case p : Predicate if p.name().equals("IN") =>
Review Comment:
`Predicate` is a java class. I don't think `unapply` can be used
--
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]