-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-38855][SQL] DS V2 supports push down math functions #36140
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
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,7 +17,7 @@ | |
|
|
||
| package org.apache.spark.sql.catalyst.util | ||
|
|
||
| import org.apache.spark.sql.catalyst.expressions.{Abs, Add, And, BinaryComparison, BinaryOperator, BitwiseAnd, BitwiseNot, BitwiseOr, BitwiseXor, CaseWhen, Cast, Coalesce, Contains, Divide, EndsWith, EqualTo, Expression, In, InSet, IsNotNull, IsNull, Literal, Multiply, Not, Or, Predicate, Remainder, StartsWith, StringPredicate, Subtract, UnaryMinus} | ||
| import org.apache.spark.sql.catalyst.expressions.{Abs, Add, And, BinaryComparison, BinaryOperator, BitwiseAnd, BitwiseNot, BitwiseOr, BitwiseXor, CaseWhen, Cast, Ceil, Coalesce, Contains, Divide, EndsWith, EqualTo, Exp, Expression, Floor, In, InSet, IsNotNull, IsNull, Literal, Log, Multiply, Not, Or, Pow, Predicate, Remainder, Sqrt, StartsWith, StringPredicate, Subtract, UnaryMinus, WidthBucket} | ||
| import org.apache.spark.sql.connector.expressions.{Cast => V2Cast, Expression => V2Expression, FieldReference, GeneralScalarExpression, LiteralValue} | ||
| 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.PushableColumn | ||
|
|
@@ -104,6 +104,35 @@ class V2ExpressionBuilder( | |
| } else { | ||
| None | ||
| } | ||
| case Log(child) => generateExpression(child) | ||
| .map(v => new GeneralScalarExpression("LN", Array[V2Expression](v))) | ||
|
||
| case Exp(child) => generateExpression(child) | ||
| .map(v => new GeneralScalarExpression("EXP", Array[V2Expression](v))) | ||
| case Pow(left, right) => | ||
| val l = generateExpression(left) | ||
| val r = generateExpression(right) | ||
| if (l.isDefined && r.isDefined) { | ||
| Some(new GeneralScalarExpression("POWER", Array[V2Expression](l.get, r.get))) | ||
| } else { | ||
| None | ||
| } | ||
| case Sqrt(child) => generateExpression(child) | ||
| .map(v => new GeneralScalarExpression("SQRT", Array[V2Expression](v))) | ||
| case Floor(child) => generateExpression(child) | ||
| .map(v => new GeneralScalarExpression("FLOOR", Array[V2Expression](v))) | ||
| case Ceil(child) => generateExpression(child) | ||
| .map(v => new GeneralScalarExpression("CEIL", Array[V2Expression](v))) | ||
| case WidthBucket(value, minValue, maxValue, numBucket) => | ||
| val v = generateExpression(value) | ||
| val min = generateExpression(minValue) | ||
| val max = generateExpression(maxValue) | ||
| val n = generateExpression(numBucket) | ||
|
||
| if (v.isDefined && min.isDefined && max.isDefined && n.isDefined) { | ||
| Some(new GeneralScalarExpression("WIDTH_BUCKET", | ||
| Array[V2Expression](v.get, min.get, max.get, n.get))) | ||
| } else { | ||
| None | ||
| } | ||
| case and: And => | ||
| // AND expects predicate | ||
| val l = generateExpression(and.left, true) | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
are they in SQL standard or widely supported by many databases?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. They are in SQL standard and widely supported by many databases.
I updated the description of PR to describe these mainstream databases.