You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@fluss.apache.org by "Yohahaha (via GitHub)" <gi...@apache.org> on 2026/05/28 15:44:22 UTC

[PR] [spark] Split non-partition and partition predicates from pushPredicates to limit pushdown [fluss]

Yohahaha opened a new pull request, #3397:
URL: https://github.com/apache/fluss/pull/3397

   <!--
   *Thank you very much for contributing to Fluss - we are happy that you want to help us improve Fluss. To help the community review your contribution in the best possible way, please go through the checklist below, which will get the contribution into a shape in which it can be best reviewed.*
   
   ## Contribution Checklist
   
     - Make sure that the pull request corresponds to a [GitHub issue](https://github.com/apache/fluss/issues). Exceptions are made for typos in JavaDoc or documentation files, which need no issue.
   
     - Name the pull request in the format "[component] Title of the pull request", where *[component]* should be replaced by the name of the component being changed. Typically, this corresponds to the component label assigned to the issue (e.g., [kv], [log], [client], [flink]). Skip *[component]* if you are unsure about which is the best component.
   
     - Fill out the template below to describe the changes contributed by the pull request. That will give reviewers the context they need to do the review.
   
     - Make sure that the change passes the automated tests, i.e., `mvn clean verify` passes.
   
     - Each pull request should address only one issue, not mix up code from multiple issues.
   
     - **Generative AI disclosure:** Indicate whether generative AI tools were used in authoring this PR. If yes, specify the tool below.
       - [ ] No generative AI tools used
       - [ ] Yes (please specify the tool below)
   
   **(The sections below can be removed for hotfixes or typos)**
   -->
   
   <!--
   Generated-by: [Tool Name and Version] following [the guidelines](https://github.com/apache/fluss/blob/main/AGENTS.md)
   -->
   
   ### Purpose
   
   <!-- Linking this pull request to the issue -->
   Linked issue: close #xxx
   
   <!-- What is the purpose of the change -->
   
   
   Fix a bug where LIMIT is never pushed down when a query has partition filters (e.g., WHERE dt = 'x' LIMIT 1). The root cause is that pushPredicates returns all predicates including partition ones, causing Spark to keep a Filter node. Spark's pushDownLimit only invokes pushLimit when there are no filters (PhysicalOperation(_, Nil, ...)), so the Filter node blocks limit pushdown.
   
   ### Brief change log
   
   
    - `SparkPartitionPredicate.scala`: Refactor extract() to return nonPartitionPredicates and partitionPredicate.
    - `FlussScanBuilder.scala`: Return only non-partition predicates from pushPredicates() across all scan builders (partition filters, ARROW filters, lake filters).
   
   
   <!-- Please describe the changes made in this pull request and explain how they address the issue -->
   
   ### 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@fluss.apache.org

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


Re: [PR] [spark] Split non-partition and partition predicates from pushPredicates to limit pushdown [fluss]

Posted by "Yohahaha (via GitHub)" <gi...@apache.org>.
Yohahaha commented on code in PR #3397:
URL: https://github.com/apache/fluss/pull/3397#discussion_r3331382123


##########
fluss-spark/fluss-spark-common/src/main/scala/org/apache/fluss/spark/read/FlussScanBuilder.scala:
##########
@@ -163,7 +166,7 @@ class FlussUpsertScanBuilder(
     val tableInfo: TableInfo,
     options: CaseInsensitiveStringMap,
     val flussConfig: FlussConfiguration)
-  extends FlussSupportsPushDownPartitionFilters {
+  extends FlussSupportsPushDownV2Filters {

Review Comment:
   thank you for the input, I just update comments to highlight only log table was supportted.
   
   for pk table, convertAndStorePredicates never be called, pushedPredicates returns empty which means no filter was pushable, I think the behavior is spark expected.



-- 
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@fluss.apache.org

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


Re: [PR] [spark] Split non-partition and partition predicates from pushPredicates to limit pushdown [fluss]

Posted by "fresh-borzoni (via GitHub)" <gi...@apache.org>.
fresh-borzoni merged PR #3397:
URL: https://github.com/apache/fluss/pull/3397


-- 
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@fluss.apache.org

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


Re: [PR] [spark] Split non-partition and partition predicates from pushPredicates to limit pushdown [fluss]

Posted by "Yohahaha (via GitHub)" <gi...@apache.org>.
Yohahaha commented on PR #3397:
URL: https://github.com/apache/fluss/pull/3397#issuecomment-4582453628

   @fresh-borzoni @luoyuxia @YannByron PTAL!


-- 
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@fluss.apache.org

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


Re: [PR] [spark] Split non-partition and partition predicates from pushPredicates to limit pushdown [fluss]

Posted by "Yohahaha (via GitHub)" <gi...@apache.org>.
Yohahaha commented on code in PR #3397:
URL: https://github.com/apache/fluss/pull/3397#discussion_r3330158744


##########
fluss-spark/fluss-spark-common/src/main/scala/org/apache/fluss/spark/read/FlussScanBuilder.scala:
##########
@@ -96,8 +98,11 @@ trait FlussLakeSupportsPushDownV2Filters extends FlussSupportsPushDownV2Filters
   def flussConfig: FlussConfiguration
 
   override def pushPredicates(predicates: Array[Predicate]): Array[Predicate] = {
+    val nonPartitionPredicates = super.pushPredicates(predicates)

Review Comment:
   I did a small refactor on filter pushdown. Lake and non-lake paths can now implement
   pushdown logic freely. The common partition pushdown logic is in the parent class.
   
   You can see the new interface and class inheritance structure below
   ```
   SupportsPushDownV2Filters (Spark)
   │
   └── FlussSupportsPushDownPartitionFilters
       │
       ├── FlussSupportsPushDownV2Filters
       │   │
       │   ├── FlussAppendScanBuilder
       │   └── FlussUpsertScanBuilder
       │
       └── FlussLakeSupportsPushDownV2Filters
           │
           ├── FlussLakeAppendScanBuilder
           └── FlussLakeUpsertScanBuilder
   
   ```



-- 
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@fluss.apache.org

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


Re: [PR] [spark] Split non-partition and partition predicates from pushPredicates to limit pushdown [fluss]

Posted by "fresh-borzoni (via GitHub)" <gi...@apache.org>.
fresh-borzoni commented on code in PR #3397:
URL: https://github.com/apache/fluss/pull/3397#discussion_r3329601900


##########
fluss-spark/fluss-spark-ut/src/test/scala/org/apache/fluss/spark/SparkPrimaryKeyTableReadTest.scala:
##########
@@ -432,6 +434,28 @@ class SparkPrimaryKeyTableReadTest extends FlussSparkTestBase {
     }
   }
 
+  test("Spark Read: mixed partition and non-partition filter (PK table)") {

Review Comment:
   Could we add the opposite of the mixed-filter test above? i.e. a partition-only query (WHERE dt = '...') that asserts there's no FilterExec left in the plan. That's really the core thing this PR changes, and right now nothing checks it - easy to accidentally regress later.



##########
fluss-spark/fluss-spark-common/src/main/scala/org/apache/fluss/spark/utils/SparkPartitionPredicate.scala:
##########
@@ -28,25 +28,40 @@ import scala.jdk.CollectionConverters._
 /** Extracts a partition-key predicate and prunes the partition list at planning time. */
 object SparkPartitionPredicate {
 
-  def extract(tableInfo: TableInfo, predicates: Seq[Predicate]): Option[FlussPredicate] = {
+  def extract(
+      tableInfo: TableInfo,
+      predicates: Seq[Predicate]): (Seq[Predicate], Option[FlussPredicate]) = {
     val partitionKeys = tableInfo.getPartitionKeys
-    if (partitionKeys.isEmpty) return None
+    if (partitionKeys.isEmpty) {
+      return (predicates, None)
+    }
 
     val rowType = PartitionUtils.partitionRowType(tableInfo)
     val onlyPartitionKeys = new PartitionPredicateVisitor(partitionKeys)
 
-    val converted = predicates.flatMap {
+    // Separate predicates: those that can be converted and only touch partition keys
+    val (partitionPredicates, nonPartitionPredicates) = predicates.partition {
+      sparkPredicate =>
+        SparkPredicateConverter
+          .convert(rowType, sparkPredicate)

Review Comment:
   Small thing: we call convert(...) here to classify the predicate, then call it again right below to actually use it. Could we convert once and reuse the result? 
   
   Something like mapping each predicate to its converted form, then partition-ing on isDefined. Only runs at planning time so not a big deal, just avoids doing the same work twice.



##########
fluss-spark/fluss-spark-common/src/main/scala/org/apache/fluss/spark/read/FlussScanBuilder.scala:
##########
@@ -96,8 +98,11 @@ trait FlussLakeSupportsPushDownV2Filters extends FlussSupportsPushDownV2Filters
   def flussConfig: FlussConfiguration
 
   override def pushPredicates(predicates: Array[Predicate]): Array[Predicate] = {
+    val nonPartitionPredicates = super.pushPredicates(predicates)

Review Comment:
   Here the lake path calls super.pushPredicates, which for ARROW tables runs convertAndStorePredicates and sets pushedPredicate/acceptedPredicates, then we overwrite both a few lines down. 
   So that work gets thrown away every time. 
   
   Could we pull the partition-extraction bit into a small helper and call that instead of super, so we skip the ARROW step we don't use?



##########
fluss-spark/fluss-spark-common/src/main/scala/org/apache/fluss/spark/utils/SparkPartitionPredicate.scala:
##########
@@ -63,4 +78,19 @@ object SparkPartitionPredicate {
               PartitionUtils.toPartitionRow(p.getResolvedPartitionSpec.getPartitionValues, rowType))
         }
     }
+
+  /**
+   * Tests whether a partition (described by its ordered partition values) matches the given
+   * predicate. Returns true when no predicate is provided.
+   */
+  def matchesPartition(

Review Comment:
   If partitionValues ever comes in empty, toPartitionRow gets the wrong number of values and could blow up. 
   
   Should we just guard it (case Some(_) if partitionValues.isEmpty => true)?



-- 
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@fluss.apache.org

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


Re: [PR] [spark] Split non-partition and partition predicates from pushPredicates to limit pushdown [fluss]

Posted by "fresh-borzoni (via GitHub)" <gi...@apache.org>.
fresh-borzoni commented on code in PR #3397:
URL: https://github.com/apache/fluss/pull/3397#discussion_r3331252802


##########
fluss-spark/fluss-spark-common/src/main/scala/org/apache/fluss/spark/read/FlussScanBuilder.scala:
##########
@@ -163,7 +166,7 @@ class FlussUpsertScanBuilder(
     val tableInfo: TableInfo,
     options: CaseInsensitiveStringMap,
     val flussConfig: FlussConfiguration)
-  extends FlussSupportsPushDownPartitionFilters {
+  extends FlussSupportsPushDownV2Filters {

Review Comment:
   For PK we read from the KV snapshot and never apply ARROW filters - so convertAndStorePredicates just gets thrown away, and pushedPredicates() reports filters the scan doesn't apply. Results are still fine (Spark re-checks them), just wasted work + misleading.



-- 
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@fluss.apache.org

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