Github user srowen commented on a diff in the pull request:
https://github.com/apache/spark/pull/18016#discussion_r116971067
--- Diff:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/parser/AstBuilder.scala
---
@@ -1337,12 +1337,14 @@ class AstBuilder(conf: SQLConf) extends
SqlBaseBaseVisitor[AnyRef] with Logging
/**
* Create an integral literal expression. The code selects the most
narrow integral type
* possible, either a BigDecimal, a Long or an Integer is returned.
+ * when the length of the getText is greater than 16. long to double
will be precision loss
+ * e.g:12345678901234567 => 1.2345678901234568e16
*/
override def visitIntegerLiteral(ctx: IntegerLiteralContext): Literal =
withOrigin(ctx) {
BigDecimal(ctx.getText) match {
case v if v.isValidInt =>
Literal(v.intValue())
- case v if v.isValidLong =>
+ case v if v.isValidLong && v.toString().length < 17 =>
--- End diff --
I think the question is, why is it a valid long but being used as a double
(?) elsewhere?
Also you can use methods on BigDecimal to query its precision and scale.
toString isn't the right approach
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]