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-29468][SQL] Change Literal.sql to be correct for floats. #26114
Conversation
Test build #112060 has finished for PR 26114 at commit
|
I kept the new test suite even though the hive tests were revealed to also be relevant, since I think they're not quite the same thing (the hive tests don't verify the output can be re-parsed) and it's weird to rely only on hive module tests for a SQL core functionality. |
Test build #112077 has finished for PR 26114 at commit
|
shall we update the old test suite to do roundtrip? We can also move it to catalyst. |
Test build #112151 has finished for PR 26114 at commit
|
thanks, merging to master! |
@@ -370,7 +390,7 @@ case class Literal (value: Any, dataType: DataType) extends LeafExpression { | |||
case _ if v.isNaN => "'NaN'" | |||
case Float.PositiveInfinity => "'Infinity'" | |||
case Float.NegativeInfinity => "'-Infinity'" | |||
case _ => v | |||
case _ => s"'$v'" |
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.
No big deal but it could be just val castedValue = s"'$v'"
scala> s"'${Double.NaN}'"
res0: String = 'NaN'
scala> s"'${Float.NegativeInfinity}'"
res1: String = '-Infinity'
scala> s"'${Float.PositiveInfinity}'"
res2: String = 'Infinity'
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.
ah good catch!
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.
oh, that's smarter..
What changes were proposed in this pull request?
Change Literal.sql to output CAST('fpValue' AS FLOAT) instead of CAST(fpValue AS FLOAT) as the SQL for a floating point literal.
Why are the changes needed?
The old version doesn't work for very small floating point numbers; the value will fail to parse if it doesn't fit in a DECIMAL(38).
This doesn't apply to doubles because they have special literal syntax.
Does this PR introduce any user-facing change?
Not really.
How was this patch tested?
New unit tests.