You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by GitBox <gi...@apache.org> on 2022/01/25 12:19:30 UTC
[GitHub] [spark] beliefer opened a new pull request #35320: [SPARK-37839][SQL] Check overflow when DS V2 partial aggregate push-down `AVG`
beliefer opened a new pull request #35320:
URL: https://github.com/apache/spark/pull/35320
### What changes were proposed in this pull request?
https://github.com/apache/spark/pull/35130 supports partial aggregate push-down `AVG` for DS V2.
The behavior doesn't consistent with `Average` if occurs overflow in ansi mode.
This PR closely follows the implement of `Average` to respect overflow in ansi mode.
### Why are the changes needed?
Make the behavior consistent with `Average` if occurs overflow in ansi mode.
### Does this PR introduce _any_ user-facing change?
'Yes'.
Users could see the exception about overflow throws in ansi mode.
### How was this patch tested?
New tests.
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] cloud-fan commented on a change in pull request #35320: [SPARK-37839][SQL][FOLLOWUP] Check overflow when DS V2 partial aggregate push-down `AVG`
Posted by GitBox <gi...@apache.org>.
cloud-fan commented on a change in pull request #35320:
URL: https://github.com/apache/spark/pull/35320#discussion_r839088830
##########
File path: sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/v2/V2ScanRelationPushDown.scala
##########
@@ -139,17 +139,11 @@ object V2ScanRelationPushDown extends Rule[LogicalPlan] with PredicateHelper wit
val sum = aggregate.Sum(avg.child).toAggregateExpression(isDistinct)
val count = aggregate.Count(avg.child).toAggregateExpression(isDistinct)
// Closely follow `Average.evaluateExpression`
Review comment:
We don't need this comment now
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] cloud-fan commented on pull request #35320: [SPARK-37839][SQL][FOLLOWUP] Check overflow when DS V2 partial aggregate push-down `AVG`
Posted by GitBox <gi...@apache.org>.
cloud-fan commented on pull request #35320:
URL: https://github.com/apache/spark/pull/35320#issuecomment-1084441727
thanks, merging to master/3.2!
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] cloud-fan closed pull request #35320: [SPARK-37839][SQL][FOLLOWUP] Check overflow when DS V2 partial aggregate push-down `AVG`
Posted by GitBox <gi...@apache.org>.
cloud-fan closed pull request #35320:
URL: https://github.com/apache/spark/pull/35320
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] beliefer commented on pull request #35320: [SPARK-37839][SQL][FOLLOWUP] Check overflow when DS V2 partial aggregate push-down `AVG`
Posted by GitBox <gi...@apache.org>.
beliefer commented on pull request #35320:
URL: https://github.com/apache/spark/pull/35320#issuecomment-1021902269
ping @huaxingao cc @cloud-fan
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] cloud-fan commented on a change in pull request #35320: [SPARK-37839][SQL][FOLLOWUP] Check overflow when DS V2 partial aggregate push-down `AVG`
Posted by GitBox <gi...@apache.org>.
cloud-fan commented on a change in pull request #35320:
URL: https://github.com/apache/spark/pull/35320#discussion_r838599900
##########
File path: sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/v2/V2ScanRelationPushDown.scala
##########
@@ -140,14 +141,18 @@ object V2ScanRelationPushDown extends Rule[LogicalPlan] with PredicateHelper wit
val count = aggregate.Count(avg.child).toAggregateExpression(isDistinct)
// Closely follow `Average.evaluateExpression`
Review comment:
Now I have a better idea: how about we just take `Average.evaluateExpression` and replace its sum/count attribute with new ones?
```
avg.evaluateExpression transform {
case a: Attribute if a.semanticEquals(avg.sum) => sum
case a: Attribute if a.semanticEquals(avg.count) => count
}
```
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] cloud-fan commented on a change in pull request #35320: [SPARK-37839][SQL][FOLLOWUP] Check overflow when DS V2 partial aggregate push-down `AVG`
Posted by GitBox <gi...@apache.org>.
cloud-fan commented on a change in pull request #35320:
URL: https://github.com/apache/spark/pull/35320#discussion_r838599900
##########
File path: sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/v2/V2ScanRelationPushDown.scala
##########
@@ -140,14 +141,18 @@ object V2ScanRelationPushDown extends Rule[LogicalPlan] with PredicateHelper wit
val count = aggregate.Count(avg.child).toAggregateExpression(isDistinct)
// Closely follow `Average.evaluateExpression`
Review comment:
Now I have a better idea: how about we just take `Average.evaluateExpression` and replace its sum/count attribute with new ones?
```
avg.evaluateExpression transform {
case a: Attribute if a.semanticEquals(avg.sum) => addCastIfNeeded(sum, avg.sum.dataType)
case a: Attribute if a.semanticEquals(avg.count) => addCastIfNeeded(count, avg.count.dataType)
}
```
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] cloud-fan commented on a change in pull request #35320: [SPARK-37839][SQL][FOLLOWUP] Check overflow when DS V2 partial aggregate push-down `AVG`
Posted by GitBox <gi...@apache.org>.
cloud-fan commented on a change in pull request #35320:
URL: https://github.com/apache/spark/pull/35320#discussion_r838416914
##########
File path: sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/v2/V2ScanRelationPushDown.scala
##########
@@ -132,14 +133,18 @@ object V2ScanRelationPushDown extends Rule[LogicalPlan] with PredicateHelper {
val count = aggregate.Count(avg.child).toAggregateExpression(isDistinct)
// Closely follow `Average.evaluateExpression`
avg.dataType match {
+ case dt: DecimalType =>
+ addCastIfNeeded(DecimalPrecision.decimalAndDecimal()(
+ Divide(
+ CheckOverflowInSum(sum, dt, !avg.failOnError),
Review comment:
Since we need to push down SUM, we can only do it if ansi mode is true, otherwise the JDBC database may throw error for sum overflow and change the behavior of Spark AVG.
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] cloud-fan commented on a change in pull request #35320: [SPARK-37839][SQL][FOLLOWUP] Check overflow when DS V2 partial aggregate push-down `AVG`
Posted by GitBox <gi...@apache.org>.
cloud-fan commented on a change in pull request #35320:
URL: https://github.com/apache/spark/pull/35320#discussion_r838570665
##########
File path: sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/v2/V2ScanRelationPushDown.scala
##########
@@ -140,14 +141,18 @@ object V2ScanRelationPushDown extends Rule[LogicalPlan] with PredicateHelper wit
val count = aggregate.Count(avg.child).toAggregateExpression(isDistinct)
// Closely follow `Average.evaluateExpression`
avg.dataType match {
+ case dt: DecimalType if avg.failOnError =>
+ addCastIfNeeded(DecimalPrecision.decimalAndDecimal()(
+ Divide(
+ CheckOverflowInSum(sum, dt, false),
+ 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 _ =>
Review comment:
I think we need to check ansi mode in this case as well, as avg(long) can also overflow
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] cloud-fan commented on a change in pull request #35320: [SPARK-37839][SQL][FOLLOWUP] Check overflow when DS V2 partial aggregate push-down `AVG`
Posted by GitBox <gi...@apache.org>.
cloud-fan commented on a change in pull request #35320:
URL: https://github.com/apache/spark/pull/35320#discussion_r839088673
##########
File path: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/DecimalPrecision.scala
##########
@@ -85,7 +85,7 @@ object DecimalPrecision extends TypeCoercionRule {
.orElse(nondecimalAndDecimal(conf.literalPickMinimumPrecision))
}
- private[catalyst] def decimalAndDecimal(): PartialFunction[Expression, Expression] = {
+ private[sql] def decimalAndDecimal(): PartialFunction[Expression, Expression] = {
Review comment:
unnecessary change now
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] cloud-fan edited a comment on pull request #35320: [SPARK-37839][SQL][FOLLOWUP] Check overflow when DS V2 partial aggregate push-down `AVG`
Posted by GitBox <gi...@apache.org>.
cloud-fan edited a comment on pull request #35320:
URL: https://github.com/apache/spark/pull/35320#issuecomment-1084441727
thanks, merging to master/3.3!
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] beliefer commented on a change in pull request #35320: [SPARK-37839][SQL][FOLLOWUP] Check overflow when DS V2 partial aggregate push-down `AVG`
Posted by GitBox <gi...@apache.org>.
beliefer commented on a change in pull request #35320:
URL: https://github.com/apache/spark/pull/35320#discussion_r839073771
##########
File path: sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/v2/V2ScanRelationPushDown.scala
##########
@@ -140,14 +141,18 @@ object V2ScanRelationPushDown extends Rule[LogicalPlan] with PredicateHelper wit
val count = aggregate.Count(avg.child).toAggregateExpression(isDistinct)
// Closely follow `Average.evaluateExpression`
Review comment:
Let me have a try.
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] cloud-fan commented on a change in pull request #35320: [SPARK-37839][SQL][FOLLOWUP] Check overflow when DS V2 partial aggregate push-down `AVG`
Posted by GitBox <gi...@apache.org>.
cloud-fan commented on a change in pull request #35320:
URL: https://github.com/apache/spark/pull/35320#discussion_r838595964
##########
File path: sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/v2/V2ScanRelationPushDown.scala
##########
@@ -140,14 +141,18 @@ object V2ScanRelationPushDown extends Rule[LogicalPlan] with PredicateHelper wit
val count = aggregate.Count(avg.child).toAggregateExpression(isDistinct)
// Closely follow `Average.evaluateExpression`
avg.dataType match {
+ case dt: DecimalType if avg.failOnError =>
+ addCastIfNeeded(DecimalPrecision.decimalAndDecimal()(
+ Divide(
+ CheckOverflowInSum(sum, dt, false),
Review comment:
shall we cast it to `avg.sumDataType`?
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] beliefer commented on pull request #35320: [SPARK-37839][SQL][FOLLOWUP] Check overflow when DS V2 partial aggregate push-down `AVG`
Posted by GitBox <gi...@apache.org>.
beliefer commented on pull request #35320:
URL: https://github.com/apache/spark/pull/35320#issuecomment-1085259320
@cloud-fan Thanks a lot!
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org