-
Notifications
You must be signed in to change notification settings - Fork 28.1k
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
[SPARK-37839][SQL][FOLLOWUP] Check overflow when DS V2 partial aggregate push-down AVG
#35320
Changes from 3 commits
6e4b283
2722942
3f32494
15c5707
1bbd955
2836ab8
a285d2e
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 |
---|---|---|
|
@@ -19,7 +19,8 @@ package org.apache.spark.sql.execution.datasources.v2 | |
|
||
import scala.collection.mutable | ||
|
||
import org.apache.spark.sql.catalyst.expressions.{Alias, AliasHelper, And, Attribute, AttributeReference, Cast, Divide, DivideDTInterval, DivideYMInterval, EqualTo, Expression, If, IntegerLiteral, Literal, NamedExpression, PredicateHelper, ProjectionOverSchema, SortOrder, SubqueryExpression} | ||
import org.apache.spark.sql.catalyst.analysis.DecimalPrecision | ||
import org.apache.spark.sql.catalyst.expressions.{Alias, AliasHelper, And, Attribute, AttributeReference, Cast, CheckOverflowInSum, Divide, DivideDTInterval, DivideYMInterval, EqualTo, Expression, If, IntegerLiteral, Literal, NamedExpression, PredicateHelper, ProjectionOverSchema, SortOrder, SubqueryExpression} | ||
import org.apache.spark.sql.catalyst.expressions.aggregate | ||
import org.apache.spark.sql.catalyst.expressions.aggregate.AggregateExpression | ||
import org.apache.spark.sql.catalyst.optimizer.CollapseProject | ||
|
@@ -32,7 +33,7 @@ import org.apache.spark.sql.connector.expressions.filter.Predicate | |
import org.apache.spark.sql.connector.read.{Scan, ScanBuilder, SupportsPushDownAggregates, SupportsPushDownFilters, V1Scan} | ||
import org.apache.spark.sql.execution.datasources.DataSourceStrategy | ||
import org.apache.spark.sql.sources | ||
import org.apache.spark.sql.types.{DataType, DayTimeIntervalType, LongType, StructType, YearMonthIntervalType} | ||
import org.apache.spark.sql.types.{DataType, DayTimeIntervalType, DecimalType, LongType, StructType, YearMonthIntervalType} | ||
import org.apache.spark.sql.util.SchemaUtils._ | ||
|
||
object V2ScanRelationPushDown extends Rule[LogicalPlan] with PredicateHelper with AliasHelper { | ||
|
@@ -140,14 +141,18 @@ object V2ScanRelationPushDown extends Rule[LogicalPlan] with PredicateHelper wit | |
val count = aggregate.Count(avg.child).toAggregateExpression(isDistinct) | ||
// Closely follow `Average.evaluateExpression` | ||
cloud-fan marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't need this comment now |
||
avg.dataType match { | ||
case dt: DecimalType if avg.failOnError => | ||
addCastIfNeeded(DecimalPrecision.decimalAndDecimal()( | ||
Divide( | ||
CheckOverflowInSum(sum, dt, false), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. shall we cast it to |
||
addCastIfNeeded(count, dt), failOnError = false)), avg.dataType) | ||
case _: YearMonthIntervalType => | ||
If(EqualTo(count, Literal(0L)), | ||
Literal(null, YearMonthIntervalType()), DivideYMInterval(sum, count)) | ||
case _: DayTimeIntervalType => | ||
If(EqualTo(count, Literal(0L)), | ||
Literal(null, DayTimeIntervalType()), DivideDTInterval(sum, count)) | ||
case _ => | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we need to check ansi mode in this case as well, as avg(long) can also overflow |
||
// TODO deal with the overflow issue | ||
Divide(addCastIfNeeded(sum, avg.dataType), | ||
addCastIfNeeded(count, avg.dataType), false) | ||
} | ||
|
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.
unnecessary change now