-
Notifications
You must be signed in to change notification settings - Fork 28.5k
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-20876][SQL]If the input parameter is float type for ceil or floor,the result is not we expected #18103
Conversation
953d207
to
c9331e3
Compare
ok to test |
1 similar comment
ok to test |
Test build #77345 has finished for PR 18103 at commit
|
case DoubleType => f(input.asInstanceOf[Double]).toLong | ||
case DecimalType.Fixed(precision, scale) => input.asInstanceOf[Decimal].floor | ||
case DecimalType.Fixed(_, _) => input.asInstanceOf[Decimal].floor | ||
} | ||
|
||
override def doGenCode(ctx: CodegenContext, ev: ExprCode): ExprCode = { |
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.
You also need to fix this code path.
|
||
val doublePi: Double = 3.1415 | ||
val floatPi: Float = 3.1415f | ||
val longPi: Long = 31415926535897912L |
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.
Moving the related test cases from operators.sql here. You can hit the bug I mentioned above.
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.
yes, actually, i have done it as #18082
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.
@gatorsmile I closed the PR #18082 temporarily
@@ -232,12 +232,13 @@ case class Ceil(child: Expression) extends UnaryMathExpression(math.ceil, "CEIL" | |||
} | |||
|
|||
override def inputTypes: Seq[AbstractDataType] = | |||
Seq(TypeCollection(LongType, DoubleType, DecimalType)) | |||
Seq(TypeCollection(DoubleType, DecimalType, LongType, FloatType)) |
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 need to add FloatType
, I think. Type coersion will promote it to DoubleType
.
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.
yes, it will promote it to DoubleType, but must move LongType to end
Test build #77444 has finished for PR 18103 at commit
|
Could you remove the sql statements from opterators.sql after you moving them to mathExpressionSuite? |
LGTM except one comment. |
Test build #77450 has started for PR 18103 at commit |
… is not we expected
Test build #77458 has finished for PR 18103 at commit
|
Thanks! Merging to master. |
Could you open another PR to backport the fix to 2.2? Thanks! |
What changes were proposed in this pull request?
spark-sql>SELECT ceil(cast(12345.1233 as float));
spark-sql>12345
For this case, the result we expected is
12346
spark-sql>SELECT floor(cast(-12345.1233 as float));
spark-sql>-12345
For this case, the result we expected is
-12346
Because in
Ceil
orFloor
,inputTypes
has no FloatType, so it is converted to LongType.How was this patch tested?
After the modification:
spark-sql>SELECT ceil(cast(12345.1233 as float));
spark-sql>12346
spark-sql>SELECT floor(cast(-12345.1233 as float));
spark-sql>-12346