You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@paimon.apache.org by "YannByron (via GitHub)" <gi...@apache.org> on 2023/11/29 14:05:32 UTC

[PR] [spark] Supports runtime filter [incubator-paimon]

YannByron opened a new pull request, #2421:
URL: https://github.com/apache/incubator-paimon/pull/2421

   <!-- Please specify the module before the PR name: [core] ... or [flink] ... -->
   
   ### Purpose
   
   <!-- Linking this pull request to the issue -->
   Linked issue: close #xxx
   
   <!-- What is the purpose of the change -->
   
   ### Tests
   
   <!-- List UT and IT cases to verify this change -->
   
   ### API and Format
   
   <!-- Does this change affect API or storage format -->
   
   ### Documentation
   
   <!-- Does this change introduce a new feature -->
   


-- 
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: issues-unsubscribe@paimon.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [spark] Supports runtime filter [incubator-paimon]

Posted by "Zouxxyy (via GitHub)" <gi...@apache.org>.
Zouxxyy commented on code in PR #2421:
URL: https://github.com/apache/incubator-paimon/pull/2421#discussion_r1410249356


##########
paimon-spark/paimon-spark-common/src/main/scala/org/apache/paimon/spark/PaimonScan.scala:
##########
@@ -0,0 +1,94 @@
+/*
+ * 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.paimon.spark
+
+import org.apache.paimon.predicate.PredicateBuilder
+import org.apache.paimon.spark.sources.PaimonMicroBatchStream
+import org.apache.paimon.table.{DataTable, Table}
+import org.apache.paimon.table.source.{ReadBuilder, Split}
+
+import org.apache.spark.sql.Utils.fieldReference
+import org.apache.spark.sql.connector.expressions.NamedReference
+import org.apache.spark.sql.connector.read.{Batch, Scan, Statistics, SupportsReportStatistics, SupportsRuntimeFiltering}
+import org.apache.spark.sql.connector.read.streaming.MicroBatchStream
+import org.apache.spark.sql.sources.{EqualTo, Filter, In}
+import org.apache.spark.sql.types.StructType
+
+import java.util.OptionalLong
+
+import scala.collection.JavaConverters._
+
+case class PaimonScan(table: Table, readBuilder: ReadBuilder)
+  extends Scan
+  with SupportsReportStatistics
+  with SupportsRuntimeFiltering {
+
+  private var splits: Array[Split] = _
+
+  override def description(): String = {
+    s"paimon(${readBuilder.tableName()})"
+  }
+
+  override def readSchema(): StructType = {
+    SparkTypeUtils.fromPaimonRowType(readBuilder.readType())
+  }
+
+  override def toBatch: Batch = {
+    PaimonBatch(getSplits, readBuilder)
+  }
+
+  override def toMicroBatchStream(checkpointLocation: String): MicroBatchStream = {
+    new PaimonMicroBatchStream(table.asInstanceOf[DataTable], readBuilder, checkpointLocation)
+  }
+
+  override def estimateStatistics(): Statistics = {
+    val rowCount = getSplits.map(_.rowCount).sum
+    val scannedTotalSize = rowCount * readSchema().defaultSize
+
+    new Statistics {
+      override def sizeInBytes(): OptionalLong = OptionalLong.of(scannedTotalSize)
+
+      override def numRows(): OptionalLong = OptionalLong.of(rowCount)
+    }
+  }
+
+  override def filterAttributes(): Array[NamedReference] = {
+    table.partitionKeys().asScala.toArray.map(fieldReference)
+  }
+
+  override def filter(filters: Array[Filter]): Unit = {
+    val converter = new SparkFilterConverter(table.rowType())
+    val partitionFilter = filters.flatMap {
+      case In(attr, values) if table.partitionKeys().contains(attr) =>
+        Some(PredicateBuilder.or(values.map(value => converter.convert(EqualTo(attr, value))): _*))

Review Comment:
   here can use converter.covert() directly



##########
paimon-spark/paimon-spark-common/src/test/scala/org/apache/paimon/spark/sql/PaimonPushDownTest.scala:
##########
@@ -30,6 +31,8 @@ import scala.collection.JavaConverters._
 
 class SparkPushDownTest extends PaimonSparkTestBase {

Review Comment:
   Class name and package are not aligned



-- 
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: issues-unsubscribe@paimon.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [spark] Supports runtime filter [incubator-paimon]

Posted by "YannByron (via GitHub)" <gi...@apache.org>.
YannByron commented on PR #2421:
URL: https://github.com/apache/incubator-paimon/pull/2421#issuecomment-1838197223

   https://github.com/apache/incubator-paimon/issues/2404


-- 
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: issues-unsubscribe@paimon.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [spark] Supports runtime filter [incubator-paimon]

Posted by "Zouxxyy (via GitHub)" <gi...@apache.org>.
Zouxxyy commented on PR #2421:
URL: https://github.com/apache/incubator-paimon/pull/2421#issuecomment-1835729901

   +1


-- 
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: issues-unsubscribe@paimon.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [spark] Supports runtime filter [incubator-paimon]

Posted by "JingsongLi (via GitHub)" <gi...@apache.org>.
JingsongLi merged PR #2421:
URL: https://github.com/apache/incubator-paimon/pull/2421


-- 
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: issues-unsubscribe@paimon.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org