You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@gluten.apache.org by "Zouxxyy (via GitHub)" <gi...@apache.org> on 2025/11/22 07:19:09 UTC
[PR] [CORE] Refactor push down filter to scan [incubator-gluten]
Zouxxyy opened a new pull request, #11153:
URL: https://github.com/apache/incubator-gluten/pull/11153
<!--
Thank you for submitting a pull request! Here are some tips:
1. For first-time contributors, please read our contributing guide:
https://github.com/apache/incubator-gluten/blob/main/CONTRIBUTING.md
2. If necessary, create a GitHub issue for discussion beforehand to avoid duplicate work.
3. If the PR is specific to a single backend, include [VL] or [CH] in the PR title to indicate the
Velox or ClickHouse backend, respectively.
4. If the PR is not ready for review, please mark it as a draft.
-->
## What changes are proposed in this pull request?
<!--
Provide a clear and concise description of the changes introduced in this PR.
Ensure the PR description aligns with the code changes, especially after updates.
If applicable, include "Fixes #<GitHub_Issue_ID>" to automatically close the corresponding issue
when the PR is merged.
-->
## How was this patch tested?
<!--
Describe how the changes were tested, if applicable.
Include new tests to validate the functionality, if necessary.
For UI-related changes, attach screenshots to demonstrate the updates.
-->
--
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: commits-unsubscribe@gluten.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@gluten.apache.org
For additional commands, e-mail: commits-help@gluten.apache.org
Re: [PR] [CORE] Refactor push down filter to scan [incubator-gluten]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #11153:
URL: https://github.com/apache/incubator-gluten/pull/11153#issuecomment-3566242956
Run Gluten Clickhouse CI on x86
--
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: commits-unsubscribe@gluten.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@gluten.apache.org
For additional commands, e-mail: commits-help@gluten.apache.org
Re: [PR] [CORE] Refactor push down filter to scan [incubator-gluten]
Posted by "jinchengchenghh (via GitHub)" <gi...@apache.org>.
jinchengchenghh commented on code in PR #11153:
URL: https://github.com/apache/incubator-gluten/pull/11153#discussion_r2567755588
##########
gluten-substrait/src/main/scala/org/apache/gluten/execution/BatchScanExecTransformer.scala:
##########
@@ -102,30 +109,13 @@ abstract class BatchScanExecTransformerBase(
postDriverMetrics()
}
- // Similar to the problem encountered in https://github.com/oap-project/gluten/pull/3184,
- // we cannot add member variables to BatchScanExecTransformerBase, which inherits from case
- // class. Otherwise, we will encounter an issue where makeCopy cannot find a constructor
- // with the corresponding number of parameters.
- // The workaround is to add a mutable list to pass in pushdownFilters.
- protected var pushdownFilters: Seq[Expression] = scan match {
- case fileScan: FileScan =>
- fileScan.dataFilters.filter {
- expr =>
- ExpressionConverter.canReplaceWithExpressionTransformer(
- ExpressionConverter.replaceAttributeReference(expr),
- output)
- }
+ override def scanFilters: Seq[Expression] = scan match {
+ case fileScan: FileScan => fileScan.dataFilters
case _ =>
- logInfo(s"${scan.getClass.toString} does not support push down filters")
+ // todo: support DSv2 scan
Review Comment:
Please keep this comment, DSv2 scan is also FileScan, InMeroryTableScan may trigger this
--
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: commits-unsubscribe@gluten.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@gluten.apache.org
For additional commands, e-mail: commits-help@gluten.apache.org
Re: [PR] [CORE] Refactor push down filter to scan [incubator-gluten]
Posted by "Zouxxyy (via GitHub)" <gi...@apache.org>.
Zouxxyy commented on code in PR #11153:
URL: https://github.com/apache/incubator-gluten/pull/11153#discussion_r2567984675
##########
gluten-substrait/src/main/scala/org/apache/gluten/extension/columnar/PushDownFilterToScan.scala:
##########
@@ -31,35 +31,15 @@ object PushDownFilterToScan extends Rule[SparkPlan] with PredicateHelper {
override def apply(plan: SparkPlan): SparkPlan = plan.transformUp {
case filter: FilterExecTransformerBase =>
filter.child match {
- case fileScan: FileSourceScanExecTransformer =>
- val pushDownFilters =
- BackendsApiManager.getSparkPlanExecApiInstance.postProcessPushDownFilter(
- splitConjunctivePredicates(filter.cond),
- fileScan)
- val newScan = fileScan.copy(dataFilters = pushDownFilters)
+ case scan: BasicScanExecTransformer
+ if BackendsApiManager.getSparkPlanExecApiInstance.supportPushDownFilterToScan(
+ scan) && scan.pushDownFilters.isEmpty =>
Review Comment:
Thansk, updated. It seems more appropriate to let Spark handle the planning itself.
Previously, I explicitly set `Some(Seq.empty)` to indicate that a scan (e.g., `HiveTableScanExecTransformer` and `MicroBatchScanExecTransformer`) does not support filter pushdown. Now that this has been removed, I've introduced a `supportPushDownFilters` flag to explicitly indicate whether filter pushdown is supported by the Scan.
--
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: commits-unsubscribe@gluten.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@gluten.apache.org
For additional commands, e-mail: commits-help@gluten.apache.org
Re: [PR] [CORE] Refactor push down filter to scan [incubator-gluten]
Posted by "Zouxxyy (via GitHub)" <gi...@apache.org>.
Zouxxyy commented on code in PR #11153:
URL: https://github.com/apache/incubator-gluten/pull/11153#discussion_r2567878049
##########
gluten-substrait/src/main/scala/org/apache/gluten/execution/BatchScanExecTransformer.scala:
##########
@@ -102,30 +109,13 @@ abstract class BatchScanExecTransformerBase(
postDriverMetrics()
}
- // Similar to the problem encountered in https://github.com/oap-project/gluten/pull/3184,
- // we cannot add member variables to BatchScanExecTransformerBase, which inherits from case
- // class. Otherwise, we will encounter an issue where makeCopy cannot find a constructor
- // with the corresponding number of parameters.
- // The workaround is to add a mutable list to pass in pushdownFilters.
- protected var pushdownFilters: Seq[Expression] = scan match {
- case fileScan: FileScan =>
- fileScan.dataFilters.filter {
- expr =>
- ExpressionConverter.canReplaceWithExpressionTransformer(
- ExpressionConverter.replaceAttributeReference(expr),
- output)
- }
+ override def scanFilters: Seq[Expression] = scan match {
+ case fileScan: FileScan => fileScan.dataFilters
case _ =>
- logInfo(s"${scan.getClass.toString} does not support push down filters")
+ // todo: support DSv2 scan
Review Comment:
Thanks for the review, I've made some minor adjustments.
I'd like to comment here is that we could support other DSv2 scans in the future. For example, if IcebergScan or PaimonScan retains Spark's Catalyst Filters and provides interface to expose them, then we could either match more case or just inherit this method.
--
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: commits-unsubscribe@gluten.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@gluten.apache.org
For additional commands, e-mail: commits-help@gluten.apache.org
Re: [PR] [CORE] Refactor push down filter to scan [incubator-gluten]
Posted by "liujiayi771 (via GitHub)" <gi...@apache.org>.
liujiayi771 merged PR #11153:
URL: https://github.com/apache/incubator-gluten/pull/11153
--
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: commits-unsubscribe@gluten.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@gluten.apache.org
For additional commands, e-mail: commits-help@gluten.apache.org
Re: [PR] [CORE] Refactor push down filter to scan [incubator-gluten]
Posted by "Zouxxyy (via GitHub)" <gi...@apache.org>.
Zouxxyy commented on code in PR #11153:
URL: https://github.com/apache/incubator-gluten/pull/11153#discussion_r2554492099
##########
backends-clickhouse/src/main/scala/org/apache/gluten/backendsapi/clickhouse/CHSparkPlanExecApi.scala:
##########
@@ -849,10 +849,7 @@ class CHSparkPlanExecApi extends SparkPlanExecApi with Logging {
}
}
- /** Clickhouse Backend only supports part of filters for parquet. */
- override def postProcessPushDownFilter(
- extraFilters: Seq[Expression],
- sparkExecNode: LeafExecNode): Seq[Expression] = {
+ override def supportPushDownFilterToScan(sparkExecNode: LeafExecNode): Boolean = {
Review Comment:
Here I'm just retaining the previous logic:
1. Do not push down filters when using Parquet scan.
2. Add CK's additional `isSupportPushDownFilter` condition.
--
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: commits-unsubscribe@gluten.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@gluten.apache.org
For additional commands, e-mail: commits-help@gluten.apache.org
Re: [PR] [CORE] Refactor push down filter to scan [incubator-gluten]
Posted by "zml1206 (via GitHub)" <gi...@apache.org>.
zml1206 commented on code in PR #11153:
URL: https://github.com/apache/incubator-gluten/pull/11153#discussion_r2567862858
##########
gluten-substrait/src/main/scala/org/apache/gluten/extension/columnar/PushDownFilterToScan.scala:
##########
@@ -31,35 +31,15 @@ object PushDownFilterToScan extends Rule[SparkPlan] with PredicateHelper {
override def apply(plan: SparkPlan): SparkPlan = plan.transformUp {
case filter: FilterExecTransformerBase =>
filter.child match {
- case fileScan: FileSourceScanExecTransformer =>
- val pushDownFilters =
- BackendsApiManager.getSparkPlanExecApiInstance.postProcessPushDownFilter(
- splitConjunctivePredicates(filter.cond),
- fileScan)
- val newScan = fileScan.copy(dataFilters = pushDownFilters)
+ case scan: BasicScanExecTransformer
+ if BackendsApiManager.getSparkPlanExecApiInstance.supportPushDownFilterToScan(
+ scan) && scan.pushDownFilters.isEmpty =>
Review Comment:
Is `scan.pushDownFilters.isEmpty` redundant?
--
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: commits-unsubscribe@gluten.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@gluten.apache.org
For additional commands, e-mail: commits-help@gluten.apache.org
Re: [PR] [CORE] Refactor push down filter to scan [incubator-gluten]
Posted by "Zouxxyy (via GitHub)" <gi...@apache.org>.
Zouxxyy commented on code in PR #11153:
URL: https://github.com/apache/incubator-gluten/pull/11153#discussion_r2567997009
##########
gluten-substrait/src/main/scala/org/apache/gluten/execution/BasicScanExecTransformer.scala:
##########
@@ -37,7 +37,40 @@ trait BasicScanExecTransformer extends LeafTransformSupport with BaseDataSource
import org.apache.spark.sql.catalyst.util._
/** Returns the filters that can be pushed down to native file scan */
- def filterExprs(): Seq[Expression]
+ final def filterExprs(): Seq[Expression] = {
+ if (pushDownFilters.nonEmpty) {
+ val (_, scanFiltersNotInPushDownFilters) =
+ scanFilters.partition(pushDownFilters.get.contains(_))
+ // For filters that only exists in scan, we need to check if they are supported.
+ val unsupportedFilters = scanFiltersNotInPushDownFilters.filter(
+ !BackendsApiManager.getSparkPlanExecApiInstance.isSupportedScanFilter(_, this))
+ if (unsupportedFilters.nonEmpty) {
+ throw new UnsupportedOperationException(
+ "Found unsupported filter in scan " + unsupportedFilters.mkString(", "))
+ }
+ val supportedPushDownFilters = pushDownFilters.get
+ .filter(BackendsApiManager.getSparkPlanExecApiInstance.isSupportedScanFilter(_, this))
+ FilterHandler.combineFilters(supportedPushDownFilters, scanFiltersNotInPushDownFilters)
+ } else {
+ // todo: When PushDownFilterToScan is not performed, find a way to throw an
+ // exception to trigger scan fallback when encountering unsupported scan filters,
+ // instead of simply filtering them out.
+ scanFilters.filter(
+ BackendsApiManager.getSparkPlanExecApiInstance.isSupportedScanFilter(_, this))
+ }
+ }
+
+ /** Returns the filters that already exists in scan. */
+ def scanFilters: Seq[Expression]
+
+ /**
+ * Returns the filters that pushed by
+ * [[org.apache.gluten.extension.columnar.PushDownFilterToScan]].
+ */
+ def pushDownFilters: Option[Seq[Expression]]
+
+ /** Copy the scan with filters that pushed by filterNode. */
+ def withNewPushdownFilters(filters: Seq[Expression]): BasicScanExecTransformer
Review Comment:
We can only call copy on final case classes, it's not available in abstract class.
--
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: commits-unsubscribe@gluten.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@gluten.apache.org
For additional commands, e-mail: commits-help@gluten.apache.org
Re: [PR] [CORE] Refactor push down filter to scan [incubator-gluten]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #11153:
URL: https://github.com/apache/incubator-gluten/pull/11153#issuecomment-3581067670
Run Gluten Clickhouse CI on x86
--
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: commits-unsubscribe@gluten.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@gluten.apache.org
For additional commands, e-mail: commits-help@gluten.apache.org
Re: [PR] [CORE] Refactor push down filter to scan [incubator-gluten]
Posted by "Zouxxyy (via GitHub)" <gi...@apache.org>.
Zouxxyy commented on code in PR #11153:
URL: https://github.com/apache/incubator-gluten/pull/11153#discussion_r2567891601
##########
gluten-substrait/src/main/scala/org/apache/gluten/extension/columnar/PushDownFilterToScan.scala:
##########
@@ -31,35 +31,15 @@ object PushDownFilterToScan extends Rule[SparkPlan] with PredicateHelper {
override def apply(plan: SparkPlan): SparkPlan = plan.transformUp {
case filter: FilterExecTransformerBase =>
filter.child match {
- case fileScan: FileSourceScanExecTransformer =>
- val pushDownFilters =
- BackendsApiManager.getSparkPlanExecApiInstance.postProcessPushDownFilter(
- splitConjunctivePredicates(filter.cond),
- fileScan)
- val newScan = fileScan.copy(dataFilters = pushDownFilters)
+ case scan: BasicScanExecTransformer
+ if BackendsApiManager.getSparkPlanExecApiInstance.supportPushDownFilterToScan(
+ scan) && scan.pushDownFilters.isEmpty =>
Review Comment:
> Is `scan.pushDownFilters.isEmpty` redundant?
`pushDownFilters` is an Option variable, and populating it once is sufficient.
--
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: commits-unsubscribe@gluten.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@gluten.apache.org
For additional commands, e-mail: commits-help@gluten.apache.org
Re: [PR] [CORE] Refactor push down filter to scan [incubator-gluten]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #11153:
URL: https://github.com/apache/incubator-gluten/pull/11153#issuecomment-3588397926
Run Gluten Clickhouse CI on x86
--
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: commits-unsubscribe@gluten.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@gluten.apache.org
For additional commands, e-mail: commits-help@gluten.apache.org
Re: [PR] [CORE] Refactor push down filter to scan [incubator-gluten]
Posted by "Zouxxyy (via GitHub)" <gi...@apache.org>.
Zouxxyy commented on PR #11153:
URL: https://github.com/apache/incubator-gluten/pull/11153#issuecomment-3578503339
CC @liujiayi771 for a look too
--
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: commits-unsubscribe@gluten.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@gluten.apache.org
For additional commands, e-mail: commits-help@gluten.apache.org
Re: [PR] [CORE] Refactor push down filter to scan [incubator-gluten]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #11153:
URL: https://github.com/apache/incubator-gluten/pull/11153#issuecomment-3565917438
Run Gluten Clickhouse CI on x86
--
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: commits-unsubscribe@gluten.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@gluten.apache.org
For additional commands, e-mail: commits-help@gluten.apache.org
Re: [PR] [CORE] Refactor push down filter to scan [incubator-gluten]
Posted by "liujiayi771 (via GitHub)" <gi...@apache.org>.
liujiayi771 commented on code in PR #11153:
URL: https://github.com/apache/incubator-gluten/pull/11153#discussion_r2563511315
##########
gluten-kafka/src/main/scala/org/apache/gluten/execution/MicroBatchScanExecTransformer.scala:
##########
@@ -64,7 +64,13 @@ case class MicroBatchScanExecTransformer(
@transient override lazy val inputPartitionsShim: Seq[InputPartition] =
stream.planInputPartitions(start, end)
- override def filterExprs(): Seq[Expression] = Seq.empty
+ override def scanFilters: Seq[Expression] = Seq.empty
+
+ def pushDownFilters: Option[Seq[Expression]] = Some(Seq.empty)
+
+ def withNewPushdownFilters(filters: Seq[Expression]): BatchScanExecTransformerBase = {
+ throw new UnsupportedOperationException()
Review Comment:
Pls add some exception msg.
##########
gluten-substrait/src/main/scala/org/apache/gluten/execution/BatchScanExecTransformer.scala:
##########
@@ -198,6 +188,15 @@ abstract class BatchScanExecTransformerBase(
@transient override lazy val fileFormat: ReadFileFormat =
BackendsApiManager.getSettings.getSubstraitReadFileFormatV2(scan)
+ override def equals(other: Any): Boolean = other match {
+ case other: BatchScanExecTransformerBase =>
+ this.pushDownFilters == other.pushDownFilters && super.equals(other)
+ case _ =>
+ false
+ }
+
+ override def hashCode(): Int = Objects.hashCode(batch, runtimeFilters, pushDownFilters)
+
Review Comment:
What is the purpose of this here?
##########
gluten-ut/spark34/src/test/scala/org/apache/spark/sql/execution/datasources/orc/GlutenOrcV2SchemaPruningSuite.scala:
##########
@@ -35,7 +35,8 @@ class GlutenOrcV2SchemaPruningSuite extends OrcV2SchemaPruningSuite with GlutenS
val fileSourceScanSchemata =
collect(df.queryExecution.executedPlan) {
case BatchScanExec(_, scan: OrcScan, _, _, _, _, _, _, _) => scan.readDataSchema
- case BatchScanExecTransformer(_, scan: OrcScan, _, _, _, _, _, _, _) => scan.readDataSchema
+ case BatchScanExecTransformer(_, scan: OrcScan, _, _, _, _, _, _, _, _) =>
Review Comment:
ditto
##########
gluten-ut/spark35/src/test/scala/org/apache/spark/sql/execution/datasources/orc/GlutenOrcV2SchemaPruningSuite.scala:
##########
@@ -35,7 +35,8 @@ class GlutenOrcV2SchemaPruningSuite extends OrcV2SchemaPruningSuite with GlutenS
val fileSourceScanSchemata =
collect(df.queryExecution.executedPlan) {
case BatchScanExec(_, scan: OrcScan, _, _, _, _) => scan.readDataSchema
- case BatchScanExecTransformer(_, scan: OrcScan, _, _, _, _, _, _, _) => scan.readDataSchema
+ case BatchScanExecTransformer(_, scan: OrcScan, _, _, _, _, _, _, _, _) =>
Review Comment:
ditto
##########
gluten-ut/spark33/src/test/scala/org/apache/spark/sql/execution/datasources/orc/GlutenOrcV2SchemaPruningSuite.scala:
##########
@@ -35,7 +35,8 @@ class GlutenOrcV2SchemaPruningSuite extends OrcV2SchemaPruningSuite with GlutenS
val fileSourceScanSchemata =
collect(df.queryExecution.executedPlan) {
case BatchScanExec(_, scan: OrcScan, _, _) => scan.readDataSchema
- case BatchScanExecTransformer(_, scan: OrcScan, _, _, _, _, _, _, _) => scan.readDataSchema
+ case BatchScanExecTransformer(_, scan: OrcScan, _, _, _, _, _, _, _, _) =>
Review Comment:
ditto
##########
gluten-ut/spark32/src/test/scala/org/apache/spark/sql/execution/datasources/orc/GlutenOrcV2SchemaPruningSuite.scala:
##########
@@ -30,7 +30,8 @@ class GlutenOrcV2SchemaPruningSuite extends OrcV2SchemaPruningSuite with GlutenS
val fileSourceScanSchemata =
collect(df.queryExecution.executedPlan) {
case BatchScanExec(_, scan: OrcScan, _) => scan.readDataSchema
- case BatchScanExecTransformer(_, scan: OrcScan, _, _, _, _, _, _, _) => scan.readDataSchema
Review Comment:
I think using this approach is better, as it's less likely to cause compatibility issues:
```scala
case b: BatchScanExecTransformer if b.scan.isInstanceOf[OrcScan] =>
```
##########
gluten-substrait/src/main/scala/org/apache/spark/sql/hive/HiveTableScanExecTransformer.scala:
##########
@@ -63,7 +63,12 @@ case class HiveTableScanExecTransformer(
hiveQlTable.getOutputFormatClass,
hiveQlTable.getMetadata)
- override def filterExprs(): Seq[Expression] = Seq.empty
+ override def scanFilters: Seq[Expression] = Seq.empty
+
+ override def pushDownFilters: Option[Seq[Expression]] = Some(Seq.empty)
+
+ override def withNewPushdownFilters(filters: Seq[Expression]): BasicScanExecTransformer =
+ throw new UnsupportedOperationException()
Review Comment:
ditto
##########
gluten-ut/spark40/src/test/scala/org/apache/spark/sql/execution/datasources/orc/GlutenOrcV2SchemaPruningSuite.scala:
##########
@@ -35,7 +35,8 @@ class GlutenOrcV2SchemaPruningSuite extends OrcV2SchemaPruningSuite with GlutenS
val fileSourceScanSchemata =
collect(df.queryExecution.executedPlan) {
case BatchScanExec(_, scan: OrcScan, _, _, _, _) => scan.readDataSchema
- case BatchScanExecTransformer(_, scan: OrcScan, _, _, _, _, _, _, _) => scan.readDataSchema
+ case BatchScanExecTransformer(_, scan: OrcScan, _, _, _, _, _, _, _, _) =>
Review Comment:
ditto
--
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: commits-unsubscribe@gluten.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@gluten.apache.org
For additional commands, e-mail: commits-help@gluten.apache.org
Re: [PR] [CORE] Refactor push down filter to scan [incubator-gluten]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #11153:
URL: https://github.com/apache/incubator-gluten/pull/11153#issuecomment-3566699341
Run Gluten Clickhouse CI on x86
--
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: commits-unsubscribe@gluten.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@gluten.apache.org
For additional commands, e-mail: commits-help@gluten.apache.org
Re: [PR] [CORE] Refactor push down filter to scan [incubator-gluten]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #11153:
URL: https://github.com/apache/incubator-gluten/pull/11153#issuecomment-3567918178
Run Gluten Clickhouse CI on x86
--
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: commits-unsubscribe@gluten.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@gluten.apache.org
For additional commands, e-mail: commits-help@gluten.apache.org
Re: [PR] [CORE] Refactor push down filter to scan [incubator-gluten]
Posted by "zml1206 (via GitHub)" <gi...@apache.org>.
zml1206 commented on code in PR #11153:
URL: https://github.com/apache/incubator-gluten/pull/11153#discussion_r2567909813
##########
gluten-substrait/src/main/scala/org/apache/gluten/extension/columnar/PushDownFilterToScan.scala:
##########
@@ -31,35 +31,15 @@ object PushDownFilterToScan extends Rule[SparkPlan] with PredicateHelper {
override def apply(plan: SparkPlan): SparkPlan = plan.transformUp {
case filter: FilterExecTransformerBase =>
filter.child match {
- case fileScan: FileSourceScanExecTransformer =>
- val pushDownFilters =
- BackendsApiManager.getSparkPlanExecApiInstance.postProcessPushDownFilter(
- splitConjunctivePredicates(filter.cond),
- fileScan)
- val newScan = fileScan.copy(dataFilters = pushDownFilters)
+ case scan: BasicScanExecTransformer
+ if BackendsApiManager.getSparkPlanExecApiInstance.supportPushDownFilterToScan(
+ scan) && scan.pushDownFilters.isEmpty =>
Review Comment:
The same plan will only be traversed once?
--
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: commits-unsubscribe@gluten.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@gluten.apache.org
For additional commands, e-mail: commits-help@gluten.apache.org
Re: [PR] [CORE] Refactor push down filter to scan [incubator-gluten]
Posted by "Zouxxyy (via GitHub)" <gi...@apache.org>.
Zouxxyy commented on PR #11153:
URL: https://github.com/apache/incubator-gluten/pull/11153#issuecomment-3587737722
The CK's test pipline appears to be failing to trigger correctly, it was successful previously.
--
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: commits-unsubscribe@gluten.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@gluten.apache.org
For additional commands, e-mail: commits-help@gluten.apache.org
Re: [PR] [CORE] Refactor push down filter to scan [incubator-gluten]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #11153:
URL: https://github.com/apache/incubator-gluten/pull/11153#issuecomment-3575422758
Run Gluten Clickhouse CI on x86
--
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: commits-unsubscribe@gluten.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@gluten.apache.org
For additional commands, e-mail: commits-help@gluten.apache.org
Re: [PR] [CORE] Refactor push down filter to scan [incubator-gluten]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #11153:
URL: https://github.com/apache/incubator-gluten/pull/11153#issuecomment-3567910322
Run Gluten Clickhouse CI on x86
--
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: commits-unsubscribe@gluten.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@gluten.apache.org
For additional commands, e-mail: commits-help@gluten.apache.org
Re: [PR] [CORE] Refactor push down filter to scan [incubator-gluten]
Posted by "Zouxxyy (via GitHub)" <gi...@apache.org>.
Zouxxyy commented on code in PR #11153:
URL: https://github.com/apache/incubator-gluten/pull/11153#discussion_r2567984675
##########
gluten-substrait/src/main/scala/org/apache/gluten/extension/columnar/PushDownFilterToScan.scala:
##########
@@ -31,35 +31,15 @@ object PushDownFilterToScan extends Rule[SparkPlan] with PredicateHelper {
override def apply(plan: SparkPlan): SparkPlan = plan.transformUp {
case filter: FilterExecTransformerBase =>
filter.child match {
- case fileScan: FileSourceScanExecTransformer =>
- val pushDownFilters =
- BackendsApiManager.getSparkPlanExecApiInstance.postProcessPushDownFilter(
- splitConjunctivePredicates(filter.cond),
- fileScan)
- val newScan = fileScan.copy(dataFilters = pushDownFilters)
+ case scan: BasicScanExecTransformer
+ if BackendsApiManager.getSparkPlanExecApiInstance.supportPushDownFilterToScan(
+ scan) && scan.pushDownFilters.isEmpty =>
Review Comment:
Thanks, updated. It seems more appropriate to let Spark handle the planning itself.
Previously, I explicitly set `Some(Seq.empty)` to indicate that a scan (e.g., `HiveTableScanExecTransformer` and `MicroBatchScanExecTransformer`) does not support filter pushdown.
Now that this has been removed, I've introduced a `supportPushDownFilters` flag to explicitly indicate whether filter pushdown is supported by the Scan.
--
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: commits-unsubscribe@gluten.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@gluten.apache.org
For additional commands, e-mail: commits-help@gluten.apache.org
Re: [PR] [CORE] Refactor push down filter to scan [incubator-gluten]
Posted by "jinchengchenghh (via GitHub)" <gi...@apache.org>.
jinchengchenghh commented on PR #11153:
URL: https://github.com/apache/incubator-gluten/pull/11153#issuecomment-3585018831
Run Gluten Clickhouse CI on x86
--
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: commits-unsubscribe@gluten.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@gluten.apache.org
For additional commands, e-mail: commits-help@gluten.apache.org
Re: [PR] [CORE] Refactor push down filter to scan [incubator-gluten]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #11153:
URL: https://github.com/apache/incubator-gluten/pull/11153#issuecomment-3565968519
Run Gluten Clickhouse CI on x86
--
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: commits-unsubscribe@gluten.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@gluten.apache.org
For additional commands, e-mail: commits-help@gluten.apache.org
Re: [PR] [CORE] Refactor push down filter to scan [incubator-gluten]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #11153:
URL: https://github.com/apache/incubator-gluten/pull/11153#issuecomment-3566002875
Run Gluten Clickhouse CI on x86
--
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: commits-unsubscribe@gluten.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@gluten.apache.org
For additional commands, e-mail: commits-help@gluten.apache.org
Re: [PR] [CORE] Refactor push down filter to scan [incubator-gluten]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #11153:
URL: https://github.com/apache/incubator-gluten/pull/11153#issuecomment-3567405397
Run Gluten Clickhouse CI on x86
--
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: commits-unsubscribe@gluten.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@gluten.apache.org
For additional commands, e-mail: commits-help@gluten.apache.org
Re: [PR] [CORE] Refactor push down filter to scan [incubator-gluten]
Posted by "zml1206 (via GitHub)" <gi...@apache.org>.
zml1206 commented on code in PR #11153:
URL: https://github.com/apache/incubator-gluten/pull/11153#discussion_r2567896014
##########
gluten-substrait/src/main/scala/org/apache/gluten/execution/BasicScanExecTransformer.scala:
##########
@@ -37,7 +37,40 @@ trait BasicScanExecTransformer extends LeafTransformSupport with BaseDataSource
import org.apache.spark.sql.catalyst.util._
/** Returns the filters that can be pushed down to native file scan */
- def filterExprs(): Seq[Expression]
+ final def filterExprs(): Seq[Expression] = {
+ if (pushDownFilters.nonEmpty) {
+ val (_, scanFiltersNotInPushDownFilters) =
+ scanFilters.partition(pushDownFilters.get.contains(_))
+ // For filters that only exists in scan, we need to check if they are supported.
+ val unsupportedFilters = scanFiltersNotInPushDownFilters.filter(
+ !BackendsApiManager.getSparkPlanExecApiInstance.isSupportedScanFilter(_, this))
+ if (unsupportedFilters.nonEmpty) {
+ throw new UnsupportedOperationException(
+ "Found unsupported filter in scan " + unsupportedFilters.mkString(", "))
+ }
+ val supportedPushDownFilters = pushDownFilters.get
+ .filter(BackendsApiManager.getSparkPlanExecApiInstance.isSupportedScanFilter(_, this))
+ FilterHandler.combineFilters(supportedPushDownFilters, scanFiltersNotInPushDownFilters)
+ } else {
+ // todo: When PushDownFilterToScan is not performed, find a way to throw an
+ // exception to trigger scan fallback when encountering unsupported scan filters,
+ // instead of simply filtering them out.
+ scanFilters.filter(
+ BackendsApiManager.getSparkPlanExecApiInstance.isSupportedScanFilter(_, this))
+ }
+ }
+
+ /** Returns the filters that already exists in scan. */
+ def scanFilters: Seq[Expression]
+
+ /**
+ * Returns the filters that pushed by
+ * [[org.apache.gluten.extension.columnar.PushDownFilterToScan]].
+ */
+ def pushDownFilters: Option[Seq[Expression]]
+
+ /** Copy the scan with filters that pushed by filterNode. */
+ def withNewPushdownFilters(filters: Seq[Expression]): BasicScanExecTransformer
Review Comment:
Suggestion:
```
val pushDownFilters: Option[Seq[Expression]]
/** Copy the scan with filters that pushed by filterNode. */
def withNewPushdownFilters(filters: Seq[Expression]): BasicScanExecTransformer = {
this.copy(pushDownFilters = Some(filters))
}
```
Reduce the override of `withNewPushdownFilters`.
--
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: commits-unsubscribe@gluten.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@gluten.apache.org
For additional commands, e-mail: commits-help@gluten.apache.org
Re: [PR] [CORE] Refactor push down filter to scan [incubator-gluten]
Posted by "Zouxxyy (via GitHub)" <gi...@apache.org>.
Zouxxyy commented on code in PR #11153:
URL: https://github.com/apache/incubator-gluten/pull/11153#discussion_r2564781755
##########
gluten-substrait/src/main/scala/org/apache/gluten/execution/BatchScanExecTransformer.scala:
##########
@@ -198,6 +188,15 @@ abstract class BatchScanExecTransformerBase(
@transient override lazy val fileFormat: ReadFileFormat =
BackendsApiManager.getSettings.getSubstraitReadFileFormatV2(scan)
+ override def equals(other: Any): Boolean = other match {
+ case other: BatchScanExecTransformerBase =>
+ this.pushDownFilters == other.pushDownFilters && super.equals(other)
+ case _ =>
+ false
+ }
+
+ override def hashCode(): Int = Objects.hashCode(batch, runtimeFilters, pushDownFilters)
+
Review Comment:
This is because even though BatchScanExec is a case class, spark still overwrite the equals and hashCode
See in gluten's `AbstractBatchScanExec` or spark's `BatchScanExec`
```scala
// TODO: unify the equal/hashCode implementation for all data source v2 query plans.
override def equals(other: Any): Boolean = other match {
case other: AbstractBatchScanExec =>
this.batch != null && this.batch == other.batch &&
this.runtimeFilters == other.runtimeFilters &&
this.commonPartitionValues == other.commonPartitionValues &&
this.replicatePartitions == other.replicatePartitions &&
this.applyPartialClustering == other.applyPartialClustering
case _ =>
false
}
override def hashCode(): Int = Objects.hashCode(batch, runtimeFilters)
```
Here add a new val `pushDownFilters `, so we need to overwrite them too.
--
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: commits-unsubscribe@gluten.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@gluten.apache.org
For additional commands, e-mail: commits-help@gluten.apache.org