-
Notifications
You must be signed in to change notification settings - Fork 28.9k
[SPARK-15776][SQL] Divide Expression inside Aggregation function is casted to wrong type #13651
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
Changes from all commits
df08eea
bce5ea7
659f17c
ff3aa3b
3735411
8fc6ba7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -213,15 +213,14 @@ case class Multiply(left: Expression, right: Expression) | |
| case class Divide(left: Expression, right: Expression) | ||
| extends BinaryArithmetic with NullIntolerant { | ||
|
|
||
| override def inputType: AbstractDataType = NumericType | ||
| override def inputType: AbstractDataType = TypeCollection(DoubleType, DecimalType) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we should also cleanup the
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't we add a dedicated expression for integral division? We currently support
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. +1
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. +1
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @hvanhovell Thanks for the catch. I will try to test hive behavior more, like how
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like div is from mysql (see http://dev.mysql.com/doc/refman/5.7/en/arithmetic-functions.html).
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shall we use
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Float is casted to Double. |
||
|
|
||
| override def symbol: String = "/" | ||
| override def decimalMethod: String = "$div" | ||
| override def nullable: Boolean = true | ||
|
|
||
| private lazy val div: (Any, Any) => Any = dataType match { | ||
| case ft: FractionalType => ft.fractional.asInstanceOf[Fractional[Any]].div | ||
| case it: IntegralType => it.integral.asInstanceOf[Integral[Any]].quot | ||
| } | ||
|
|
||
| override def eval(input: InternalRow): Any = { | ||
|
|
||
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.
We can simplify this:
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.
Seems
case d: Divide if d.dataType.isInstanceOf[IntegralType]is not equivalent with the code that we have at here?(also , let's avoid of unnecessary changes)