You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@datafusion.apache.org by "josh0yeh (via GitHub)" <gi...@apache.org> on 2025/08/08 21:12:57 UTC

[PR] fix: use spark ParquetFilters [datafusion-comet]

josh0yeh opened a new pull request, #2100:
URL: https://github.com/apache/datafusion-comet/pull/2100

   Before Spark 3.4.3, `ParquetFilters` were added originally so we could shade Parquet in Comet. Since, `ParquetFilters` has updated In/NotIn pushdown which comet needs. Remove `ParquetFilters` from Comet. Also refactor comet native filter functionalities into CometNativeFilter.scala
   


-- 
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: github-unsubscribe@datafusion.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] fix: use spark ParquetFilters [datafusion-comet]

Posted by "josh0yeh (via GitHub)" <gi...@apache.org>.
josh0yeh commented on PR #2100:
URL: https://github.com/apache/datafusion-comet/pull/2100#issuecomment-3169331714

   CC: @andygrove @parthchandra (please feel free to cc others I might overlook)


-- 
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: github-unsubscribe@datafusion.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] fix: use spark ParquetFilters [datafusion-comet]

Posted by "parthchandra (via GitHub)" <gi...@apache.org>.
parthchandra commented on PR #2100:
URL: https://github.com/apache/datafusion-comet/pull/2100#issuecomment-3180938744

   @josh0yeh The PR is causing a regressions. Specifically, tests are failing because of - 
   ```
   [info]   Cause: java.lang.UnsupportedOperationException: visit in is not supported.
   [info]   at org.apache.parquet.filter2.predicate.FilterPredicate$Visitor.visit(FilterPredicate.java:81)
   [info]   at org.apache.parquet.filter2.predicate.Operators$In.accept(Operators.java:323)
   [info]   at org.apache.comet.parquet.BloomFilterReader.visit(BloomFilterReader.java:125)
   [info]   at org.apache.comet.parquet.BloomFilterReader.visit(BloomFilterReader.java:47)
   [info]   at org.apache.parquet.filter2.predicate.Operators$And.accept(Operators.java:573)
   [info]   at org.apache.comet.parquet.RowGroupFilter.visit(RowGroupFilter.java:102)
   [info]   at org.apache.comet.parquet.RowGroupFilter.visit(RowGroupFilter.java:36)
   [info]   at org.apache.parquet.filter2.compat.FilterCompat$FilterPredicateCompat.accept(FilterCompat.java:157)
   [info]   at org.apache.comet.parquet.RowGroupFilter.filterRowGroups(RowGroupFilter.java:50)
   [info]   at org.apache.comet.parquet.FileReader.filterRowGroups(FileReader.java:827)
   [info]   at org.apache.comet.parquet.FileReader.filterRowGroups(FileReader.java:806)
   [info]   at org.apache.comet.parquet.FileReader.<init>(FileReader.java:218)
   [info]   at org.apache.comet.parquet.BatchReader.init(BatchReader.java:264)
   ```
   Can you investigate ?


-- 
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: github-unsubscribe@datafusion.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] fix: use spark ParquetFilters [datafusion-comet]

Posted by "codecov-commenter (via GitHub)" <gi...@apache.org>.
codecov-commenter commented on PR #2100:
URL: https://github.com/apache/datafusion-comet/pull/2100#issuecomment-3169397214

   ## [Codecov](https://app.codecov.io/gh/apache/datafusion-comet/pull/2100?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
   :x: Patch coverage is `23.91304%` with `70 lines` in your changes missing coverage. Please review.
   :white_check_mark: Project coverage is 34.01%. Comparing base ([`f09f8af`](https://app.codecov.io/gh/apache/datafusion-comet/commit/f09f8af64c6599255e116a376f4f008f2fd63b43?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)) to head ([`0a3ca0d`](https://app.codecov.io/gh/apache/datafusion-comet/commit/0a3ca0dd3df1bbf3a6d04337594fa143a4962fbf?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)).
   :warning: Report is 359 commits behind head on main.
   
   | [Files with missing lines](https://app.codecov.io/gh/apache/datafusion-comet/pull/2100?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Patch % | Lines |
   |---|---|---|
   | [.../org/apache/comet/parquet/CometNativeFilters.scala](https://app.codecov.io/gh/apache/datafusion-comet/pull/2100?src=pr&el=tree&filepath=spark%2Fsrc%2Fmain%2Fscala%2Forg%2Fapache%2Fcomet%2Fparquet%2FCometNativeFilters.scala&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c3Bhcmsvc3JjL21haW4vc2NhbGEvb3JnL2FwYWNoZS9jb21ldC9wYXJxdWV0L0NvbWV0TmF0aXZlRmlsdGVycy5zY2FsYQ==) | 23.07% | [58 Missing and 12 partials :warning: ](https://app.codecov.io/gh/apache/datafusion-comet/pull/2100?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
   
   <details><summary>Additional details and impacted files</summary>
   
   
   
   ```diff
   @@              Coverage Diff              @@
   ##               main    #2100       +/-   ##
   =============================================
   - Coverage     56.12%   34.01%   -22.12%     
   + Complexity      976      751      -225     
   =============================================
     Files           119      140       +21     
     Lines         11743    12537      +794     
     Branches       2251     2177       -74     
   =============================================
   - Hits           6591     4264     -2327     
   - Misses         4012     7446     +3434     
   + Partials       1140      827      -313     
   ```
   </details>
   
   [:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/apache/datafusion-comet/pull/2100?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).   
   :loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
   <details><summary> :rocket: New features to boost your workflow: </summary>
   
   - :snowflake: [Test Analytics](https://docs.codecov.com/docs/test-analytics): Detect flaky tests, report on failures, and find test suite problems.
   </details>


-- 
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: github-unsubscribe@datafusion.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] fix: use spark ParquetFilters [datafusion-comet]

Posted by "mbutrovich (via GitHub)" <gi...@apache.org>.
mbutrovich closed pull request #2100: fix: use spark ParquetFilters
URL: https://github.com/apache/datafusion-comet/pull/2100


-- 
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: github-unsubscribe@datafusion.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] fix: use spark ParquetFilters [datafusion-comet]

Posted by "kazuyukitanimura (via GitHub)" <gi...@apache.org>.
kazuyukitanimura commented on code in PR #2100:
URL: https://github.com/apache/datafusion-comet/pull/2100#discussion_r2264041752


##########
spark/src/main/scala/org/apache/comet/parquet/CometNativeFilters.scala:
##########
@@ -0,0 +1,211 @@
+/*
+ * 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.comet.parquet
+
+import java.io.ByteArrayOutputStream
+
+import scala.collection.JavaConverters._
+
+import org.apache.spark.sql.sources
+import org.apache.spark.sql.types.StructType
+
+import org.apache.comet.parquet.SourceFilterSerde.{createBinaryExpr, createNameExpr, createUnaryExpr, createValueExpr}
+import org.apache.comet.serde.ExprOuterClass
+import org.apache.comet.serde.QueryPlanSerde.scalarFunctionExprToProto
+
+/**
+ * Utility class for creating native filters for Comet's native reader. This functionality is
+ * Comet-specific and not available in Spark's native ParquetFilters.
+ *
+ * The native filters are serialized into protobuf format and passed to Comet's native Rust reader
+ * for efficient filter evaluation.
+ */
+object CometNativeFilters {
+
+  /**
+   * Creates native filters from Spark Filter objects for Comet's native reader.
+   *
+   * @param predicates
+   *   Sequence of Spark Filter objects
+   * @param dataSchema
+   *   The data schema for field resolution
+   * @param nameToParquetField
+   *   Map of field names to parquet field info (currently unused but kept for API compatibility)
+   * @return
+   *   Optional byte array containing serialized protobuf filters
+   */
+  def createNativeFilters(
+      predicates: Seq[sources.Filter],
+      dataSchema: StructType,
+      nameToParquetField: Map[String, Any]): Option[Array[Byte]] = {
+    predicates.reduceOption(sources.And).flatMap(createNativeFilter(_, dataSchema)).map { expr =>
+      val outputStream = new ByteArrayOutputStream()
+      expr.writeTo(outputStream)
+      outputStream.close()
+      outputStream.toByteArray
+    }
+  }
+
+  /**
+   * Converts a single Spark Filter to a native protobuf expression.
+   */
+  private def createNativeFilter(
+      predicate: sources.Filter,
+      dataSchema: StructType): Option[ExprOuterClass.Expr] = {
+
+    def nameUnaryExpr(name: String)(
+        f: (ExprOuterClass.Expr.Builder, ExprOuterClass.UnaryExpr) => ExprOuterClass.Expr.Builder)
+        : Option[ExprOuterClass.Expr] = {
+      createNameExpr(name, dataSchema).map { case (_, childExpr) =>
+        createUnaryExpr(childExpr, f)
+      }
+    }
+
+    def nameValueBinaryExpr(name: String, value: Any)(
+        f: (
+            ExprOuterClass.Expr.Builder,
+            ExprOuterClass.BinaryExpr) => ExprOuterClass.Expr.Builder)
+        : Option[ExprOuterClass.Expr] = {
+      createNameExpr(name, dataSchema).flatMap { case (dataType, childExpr) =>
+        createValueExpr(value, dataType).map(createBinaryExpr(childExpr, _, f))
+      }
+    }
+
+    predicate match {
+      case sources.IsNull(name) =>

Review Comment:
   we used to have `canMakeFilterOn`. Do we have equivalent checks?



-- 
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: github-unsubscribe@datafusion.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] fix: use spark ParquetFilters [datafusion-comet]

Posted by "parthchandra (via GitHub)" <gi...@apache.org>.
parthchandra commented on code in PR #2100:
URL: https://github.com/apache/datafusion-comet/pull/2100#discussion_r2264165976


##########
spark/src/main/scala/org/apache/comet/parquet/CometNativeFilters.scala:
##########
@@ -0,0 +1,211 @@
+/*
+ * 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.comet.parquet
+
+import java.io.ByteArrayOutputStream
+
+import scala.collection.JavaConverters._
+
+import org.apache.spark.sql.sources
+import org.apache.spark.sql.types.StructType
+
+import org.apache.comet.parquet.SourceFilterSerde.{createBinaryExpr, createNameExpr, createUnaryExpr, createValueExpr}
+import org.apache.comet.serde.ExprOuterClass
+import org.apache.comet.serde.QueryPlanSerde.scalarFunctionExprToProto
+
+/**
+ * Utility class for creating native filters for Comet's native reader. This functionality is
+ * Comet-specific and not available in Spark's native ParquetFilters.
+ *
+ * The native filters are serialized into protobuf format and passed to Comet's native Rust reader
+ * for efficient filter evaluation.
+ */
+object CometNativeFilters {
+
+  /**
+   * Creates native filters from Spark Filter objects for Comet's native reader.
+   *
+   * @param predicates
+   *   Sequence of Spark Filter objects
+   * @param dataSchema
+   *   The data schema for field resolution
+   * @param nameToParquetField
+   *   Map of field names to parquet field info (currently unused but kept for API compatibility)
+   * @return
+   *   Optional byte array containing serialized protobuf filters
+   */
+  def createNativeFilters(
+      predicates: Seq[sources.Filter],
+      dataSchema: StructType,
+      nameToParquetField: Map[String, Any]): Option[Array[Byte]] = {
+    predicates.reduceOption(sources.And).flatMap(createNativeFilter(_, dataSchema)).map { expr =>
+      val outputStream = new ByteArrayOutputStream()
+      expr.writeTo(outputStream)
+      outputStream.close()
+      outputStream.toByteArray
+    }
+  }
+
+  /**
+   * Converts a single Spark Filter to a native protobuf expression.
+   */
+  private def createNativeFilter(
+      predicate: sources.Filter,
+      dataSchema: StructType): Option[ExprOuterClass.Expr] = {
+
+    def nameUnaryExpr(name: String)(
+        f: (ExprOuterClass.Expr.Builder, ExprOuterClass.UnaryExpr) => ExprOuterClass.Expr.Builder)
+        : Option[ExprOuterClass.Expr] = {
+      createNameExpr(name, dataSchema).map { case (_, childExpr) =>
+        createUnaryExpr(childExpr, f)
+      }
+    }
+
+    def nameValueBinaryExpr(name: String, value: Any)(
+        f: (
+            ExprOuterClass.Expr.Builder,
+            ExprOuterClass.BinaryExpr) => ExprOuterClass.Expr.Builder)
+        : Option[ExprOuterClass.Expr] = {
+      createNameExpr(name, dataSchema).flatMap { case (dataType, childExpr) =>
+        createValueExpr(value, dataType).map(createBinaryExpr(childExpr, _, f))
+      }
+    }
+
+    predicate match {
+      case sources.IsNull(name) =>

Review Comment:
   Looks like `canMakeFilterOn` was a private method in `ParquetFilters` and there is an identical implementation in Spark's `ParquetFilters`



-- 
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: github-unsubscribe@datafusion.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org