-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-39964][SQL] DS V2 pushdown should unify the translate path #37391
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,8 +18,11 @@ | |
| package org.apache.spark.sql.catalyst.util | ||
|
|
||
| import org.apache.spark.sql.catalyst.expressions._ | ||
| import org.apache.spark.sql.catalyst.expressions.aggregate.AggregateExpression | ||
| import org.apache.spark.sql.connector.expressions.{Cast => V2Cast, Expression => V2Expression, Extract => V2Extract, FieldReference, GeneralScalarExpression, LiteralValue, UserDefinedScalarFunc} | ||
| import org.apache.spark.sql.connector.expressions.aggregate.{Avg, Count, CountStar, GeneralAggregateFunc, Max, Min, Sum, UserDefinedAggregateFunc} | ||
| import org.apache.spark.sql.connector.expressions.filter.{AlwaysFalse, AlwaysTrue, And => V2And, Not => V2Not, Or => V2Or, Predicate => V2Predicate} | ||
| import org.apache.spark.sql.execution.datasources.PushableExpression | ||
| import org.apache.spark.sql.types.{BooleanType, IntegerType} | ||
|
|
||
| /** | ||
|
|
@@ -90,6 +93,52 @@ class V2ExpressionBuilder(e: Expression, isPredicate: Boolean = false) { | |
| } | ||
| case Cast(child, dataType, _, true) => | ||
| generateExpression(child).map(v => new V2Cast(v, dataType)) | ||
| case AggregateExpression(aggregateFunction, _, isDistinct, None, _) => | ||
| aggregateFunction match { | ||
|
||
| case aggregate.Min(PushableExpression(expr)) => Some(new Min(expr)) | ||
| case aggregate.Max(PushableExpression(expr)) => Some(new Max(expr)) | ||
| case count: aggregate.Count if count.children.length == 1 => | ||
| count.children.head match { | ||
| // COUNT(any literal) is the same as COUNT(*) | ||
| case Literal(_, _) => Some(new CountStar()) | ||
| case PushableExpression(expr) => Some(new Count(expr, isDistinct)) | ||
| case _ => None | ||
| } | ||
| case aggregate.Sum(PushableExpression(expr), _) => Some(new Sum(expr, isDistinct)) | ||
| case aggregate.Average(PushableExpression(expr), _) => Some(new Avg(expr, isDistinct)) | ||
| case aggregate.VariancePop(PushableExpression(expr), _) => | ||
| Some(new GeneralAggregateFunc("VAR_POP", isDistinct, Array(expr))) | ||
| case aggregate.VarianceSamp(PushableExpression(expr), _) => | ||
| Some(new GeneralAggregateFunc("VAR_SAMP", isDistinct, Array(expr))) | ||
| case aggregate.StddevPop(PushableExpression(expr), _) => | ||
| Some(new GeneralAggregateFunc("STDDEV_POP", isDistinct, Array(expr))) | ||
| case aggregate.StddevSamp(PushableExpression(expr), _) => | ||
| Some(new GeneralAggregateFunc("STDDEV_SAMP", isDistinct, Array(expr))) | ||
| case aggregate.CovPopulation(PushableExpression(left), PushableExpression(right), _) => | ||
| Some(new GeneralAggregateFunc("COVAR_POP", isDistinct, Array(left, right))) | ||
| case aggregate.CovSample(PushableExpression(left), PushableExpression(right), _) => | ||
| Some(new GeneralAggregateFunc("COVAR_SAMP", isDistinct, Array(left, right))) | ||
| case aggregate.Corr(PushableExpression(left), PushableExpression(right), _) => | ||
| Some(new GeneralAggregateFunc("CORR", isDistinct, Array(left, right))) | ||
| case aggregate.RegrIntercept(PushableExpression(left), PushableExpression(right)) => | ||
| Some(new GeneralAggregateFunc("REGR_INTERCEPT", isDistinct, Array(left, right))) | ||
| case aggregate.RegrR2(PushableExpression(left), PushableExpression(right)) => | ||
| Some(new GeneralAggregateFunc("REGR_R2", isDistinct, Array(left, right))) | ||
| case aggregate.RegrSlope(PushableExpression(left), PushableExpression(right)) => | ||
| Some(new GeneralAggregateFunc("REGR_SLOPE", isDistinct, Array(left, right))) | ||
| case aggregate.RegrSXY(PushableExpression(left), PushableExpression(right)) => | ||
| Some(new GeneralAggregateFunc("REGR_SXY", isDistinct, Array(left, right))) | ||
| // TODO supports other aggregate functions | ||
| case aggregate.V2Aggregator(aggrFunc, children, _, _) => | ||
| val translatedExprs = children.flatMap(PushableExpression.unapply(_)) | ||
| if (translatedExprs.length == children.length) { | ||
| Some(new UserDefinedAggregateFunc(aggrFunc.name(), | ||
| aggrFunc.canonicalName(), isDistinct, translatedExprs.toArray[V2Expression])) | ||
| } else { | ||
| None | ||
| } | ||
| case _ => None | ||
| } | ||
| case Abs(child, true) => generateExpressionWithName("ABS", Seq(child)) | ||
| case Coalesce(children) => generateExpressionWithName("COALESCE", children) | ||
| case Greatest(children) => generateExpressionWithName("GREATEST", children) | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.