Skip to content
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

Closed
wants to merge 4 commits into from

Conversation

jose-torres
Copy link
Contributor

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.

@SparkQA
Copy link

SparkQA commented Oct 14, 2019

Test build #112060 has finished for PR 26114 at commit 11d5540.

  • This patch fails Spark unit tests.
  • This patch merges cleanly.
  • This patch adds the following public classes (experimental):
  • class LiteralParsingSuite extends QueryTest with SharedSparkSession

@jose-torres
Copy link
Contributor Author

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.

@SparkQA
Copy link

SparkQA commented Oct 15, 2019

Test build #112077 has finished for PR 26114 at commit 5839f90.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@cloud-fan
Copy link
Contributor

shall we update the old test suite to do roundtrip? We can also move it to catalyst.

@SparkQA
Copy link

SparkQA commented Oct 16, 2019

Test build #112151 has finished for PR 26114 at commit d3ad06a.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds the following public classes (experimental):
  • class ExpressionSQLBuilderSuite extends SparkFunSuite

@cloud-fan
Copy link
Contributor

thanks, merging to master!

@cloud-fan cloud-fan closed this in 5a482e7 Oct 16, 2019
@@ -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'"
Copy link
Member

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'

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah good catch!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh, that's smarter..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
6 participants