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/08/03 03:52:38 UTC
[GitHub] [spark] beliefer opened a new pull request, #37389: [SPARK-39963][SQL] Simplify the implementation of `SimplifyCasts`
beliefer opened a new pull request, #37389:
URL: https://github.com/apache/spark/pull/37389
### What changes were proposed in this pull request?
`SimplifyCasts` is a optimize rule used to removes `Cast` that are unnecessary because the input is already the correct type.
Currently, the implementation of `SimplifyCasts` seems a little redundant. `Cast.canUpCast` can completely cover the function of `isWiderCast`.
### Why are the changes needed?
Simplify the implementation of `SimplifyCasts`.
### Does this PR introduce _any_ user-facing change?
'No'.
Just update the inner implementation.
### How was this patch tested?
N/A
--
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] xkrogen commented on a diff in pull request #37389: [SPARK-39963][SQL] Simplify the implementation of `SimplifyCasts`
Posted by GitBox <gi...@apache.org>.
xkrogen commented on code in PR #37389:
URL: https://github.com/apache/spark/pull/37389#discussion_r936853437
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/expressions.scala:
##########
@@ -1036,12 +1036,8 @@ object SimplifyCasts extends Rule[LogicalPlan] {
// Returns whether the from DataType can be safely casted to the to DataType without losing
// any precision or range.
- private def isWiderCast(from: DataType, to: NumericType): Boolean = (from, to) match {
- case (from: NumericType, to: DecimalType) if to.isWiderThan(from) => true
- case (from: DecimalType, to: NumericType) if from.isTighterThan(to) => true
- case (from: IntegralType, to: IntegralType) => Cast.canUpCast(from, to)
- case _ => from == to
Review Comment:
This refactor changes the behavior when `from` is non-numeric and `from == to`. Previously returns true, now false. Is this intentional?
To preserve behavior, and be more Scala-idiomatic by using pattern matching instead of `isInstanceOf`, I would suggest:
```scala
private def isWiderCast(from: DataType, to: NumericType): Boolean = from match {
case NumericType => Cast.canUpCast(from, to)
case _ => from == to
}
```
--
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 #37389: [SPARK-39963][SQL] Simplify the implementation of `SimplifyCasts`
Posted by GitBox <gi...@apache.org>.
beliefer commented on PR #37389:
URL: https://github.com/apache/spark/pull/37389#issuecomment-1203551031
ping @gengliangwang @MaxGekk @dongjoon-hyun cc @cloud-fan @viirya
--
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 #37389: [SPARK-39963][SQL] Simplify `SimplifyCasts.isWiderCast`
Posted by GitBox <gi...@apache.org>.
cloud-fan commented on PR #37389:
URL: https://github.com/apache/spark/pull/37389#issuecomment-1206302474
thanks, merging to master!
--
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] xkrogen commented on a diff in pull request #37389: [SPARK-39963][SQL] Simplify the implementation of `SimplifyCasts`
Posted by GitBox <gi...@apache.org>.
xkrogen commented on code in PR #37389:
URL: https://github.com/apache/spark/pull/37389#discussion_r936853437
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/expressions.scala:
##########
@@ -1036,12 +1036,8 @@ object SimplifyCasts extends Rule[LogicalPlan] {
// Returns whether the from DataType can be safely casted to the to DataType without losing
// any precision or range.
- private def isWiderCast(from: DataType, to: NumericType): Boolean = (from, to) match {
- case (from: NumericType, to: DecimalType) if to.isWiderThan(from) => true
- case (from: DecimalType, to: NumericType) if from.isTighterThan(to) => true
- case (from: IntegralType, to: IntegralType) => Cast.canUpCast(from, to)
- case _ => from == to
Review Comment:
This refactor changes the behavior when `from` is non-numeric and `from == to`. Previously returns true, now false. Is this intentional?
To preserve behavior, and be more Scala-idiomatic by using pattern matching instead of `isInstanceOf`, I would suggest:
```scala
private def isWiderCast(from: DataType, to: NumericType): Boolean = from match {
case NumericType => Cast.canUpCast(from, to)
case _ => from == to
}
```
--
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 #37389: [SPARK-39963][SQL] Simplify `SimplifyCasts.isWiderCast`
Posted by GitBox <gi...@apache.org>.
cloud-fan closed pull request #37389: [SPARK-39963][SQL] Simplify `SimplifyCasts.isWiderCast`
URL: https://github.com/apache/spark/pull/37389
--
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] dongjoon-hyun commented on a diff in pull request #37389: [SPARK-39963][SQL] Simplify `SimplifyCasts.isWiderCast`
Posted by GitBox <gi...@apache.org>.
dongjoon-hyun commented on code in PR #37389:
URL: https://github.com/apache/spark/pull/37389#discussion_r937246252
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/expressions.scala:
##########
@@ -1036,12 +1036,8 @@ object SimplifyCasts extends Rule[LogicalPlan] {
// Returns whether the from DataType can be safely casted to the to DataType without losing
// any precision or range.
- private def isWiderCast(from: DataType, to: NumericType): Boolean = (from, to) match {
- case (from: NumericType, to: DecimalType) if to.isWiderThan(from) => true
- case (from: DecimalType, to: NumericType) if from.isTighterThan(to) => true
- case (from: IntegralType, to: IntegralType) => Cast.canUpCast(from, to)
- case _ => from == to
Review Comment:
Do we have an existing test coverage for the case discussed in this thread?
--
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 #37389: [SPARK-39963][SQL] Simplify `SimplifyCasts.isWiderCast`
Posted by GitBox <gi...@apache.org>.
beliefer commented on PR #37389:
URL: https://github.com/apache/spark/pull/37389#issuecomment-1204640816
> Thank you for pinging me, @beliefer . Could you rebase to the `master` branch once more? SparkR failure is fixed.
Thank you for the reminder.
--
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 #37389: [SPARK-39963][SQL] Simplify `SimplifyCasts.isWiderCast`
Posted by GitBox <gi...@apache.org>.
cloud-fan commented on PR #37389:
URL: https://github.com/apache/spark/pull/37389#issuecomment-1206302144
thanks, merging to master!
--
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] dongjoon-hyun commented on pull request #37389: [SPARK-39963][SQL] Simplify `SimplifyCasts.isWiderCast`
Posted by GitBox <gi...@apache.org>.
dongjoon-hyun commented on PR #37389:
URL: https://github.com/apache/spark/pull/37389#issuecomment-1204618840
Thank you for pinging me, @beliefer . Could you rebase to the `master` branch once more? SparkR failure is fixed.
--
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 diff in pull request #37389: [SPARK-39963][SQL] Simplify the implementation of `SimplifyCasts`
Posted by GitBox <gi...@apache.org>.
beliefer commented on code in PR #37389:
URL: https://github.com/apache/spark/pull/37389#discussion_r937238487
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/expressions.scala:
##########
@@ -1036,12 +1036,8 @@ object SimplifyCasts extends Rule[LogicalPlan] {
// Returns whether the from DataType can be safely casted to the to DataType without losing
// any precision or range.
- private def isWiderCast(from: DataType, to: NumericType): Boolean = (from, to) match {
- case (from: NumericType, to: DecimalType) if to.isWiderThan(from) => true
- case (from: DecimalType, to: NumericType) if from.isTighterThan(to) => true
- case (from: IntegralType, to: IntegralType) => Cast.canUpCast(from, to)
- case _ => from == to
Review Comment:
Previously, when `from` is non-numeric, `from == to` must be false.
--
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 diff in pull request #37389: [SPARK-39963][SQL] Simplify `SimplifyCasts.isWiderCast`
Posted by GitBox <gi...@apache.org>.
beliefer commented on code in PR #37389:
URL: https://github.com/apache/spark/pull/37389#discussion_r937257705
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/expressions.scala:
##########
@@ -1036,12 +1036,8 @@ object SimplifyCasts extends Rule[LogicalPlan] {
// Returns whether the from DataType can be safely casted to the to DataType without losing
// any precision or range.
- private def isWiderCast(from: DataType, to: NumericType): Boolean = (from, to) match {
- case (from: NumericType, to: DecimalType) if to.isWiderThan(from) => true
- case (from: DecimalType, to: NumericType) if from.isTighterThan(to) => true
- case (from: IntegralType, to: IntegralType) => Cast.canUpCast(from, to)
- case _ => from == to
Review Comment:
Previously, the existing test cases does't cover the case discussed above.
So, let's add one.
--
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 #37389: [SPARK-39963][SQL] Simplify `SimplifyCasts.isWiderCast`
Posted by GitBox <gi...@apache.org>.
beliefer commented on PR #37389:
URL: https://github.com/apache/spark/pull/37389#issuecomment-1207131840
@cloud-fan @dongjoon-hyun @viirya @gengliangwang Thank you !
@xkrogen Thank you for you comments.
--
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