turboFei commented on a change in pull request #27150: SPARK-30471: Fix issue
when comparing String and IntegerType
URL: https://github.com/apache/spark/pull/27150#discussion_r365181628
##########
File path:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/TypeCoercion.scala
##########
@@ -142,6 +142,8 @@ object TypeCoercion {
case (n: DecimalType, s: StringType) => Some(DoubleType)
case (s: StringType, n: DecimalType) => Some(DoubleType)
+ case (l: StringType, r: IntegerType) => Some(DoubleType)
Review comment:
FYI:
When comparing StringType and IntegerType,
we can try cast them to Decimal(38, 0), there is no possibility overflow
occurred when casting this Integer to Decimal(38, 0), because the maxValue of
IntegerType(Long) in spark is little than 10^20.
If overflow occurred when casting string to Decimal(38, 0), we can ensure
that the abs of string value much greater than the Integer Value.
Then, we can cast them to DoubleType, the comparison should be accurate.
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]