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-8279][SQL]Add math function round #6938
Conversation
Jenkins, add to whitelist. |
ok to test |
Test build #35467 has finished for PR 6938 at commit
|
Test build #35469 has finished for PR 6938 at commit
|
duplicated with #6836? |
@chenghao-intel, Yep, not aware there are two JIRAs for |
@@ -312,3 +315,90 @@ case class Logarithm(left: Expression, right: Expression) | |||
""" | |||
} | |||
} | |||
|
|||
case class Round(children: Seq[Expression]) extends Expression { |
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.
Actually we support multiple constructors now in expression, see https://github.com/apache/spark/pull/6806/files#diff-d788f93e29b4d25cdd7d60328587678bR229
As most of issues that I raised is solved in #6836, do you mind jump there and give some comments? |
@chenghao-intel, I think the main difference between this and #6836 is whether to make |
Test build #35521 has finished for PR 6938 at commit
|
Yes, #6836 follows the Hive's |
Oh, I think there exists misunderstood of the Therefore, I preserve the dataType of |
Oh, sorry, you did use the |
Test build #35539 has finished for PR 6938 at commit
|
|
||
def children: Seq[Expression] = Seq(child, scale) | ||
|
||
def nullable: Boolean = true |
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.
depends on child.nullable || scala.nullable
?
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.
probably more than that, Hive support String
,Double.NaN
, Double.Infinity
as input, all of these would result in null result.
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.
OK, let's say if the both children are literals e.g. Literal(123.0, FloatType)
and Literal(1. IntegerType)
, still be nullable?
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.
it is not the end of the world to have nullable be more conservative, since it is technically correct to be nullable. however, if there is a way to do a more accurate way to determine nullability, we should do that.
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.
The nullable
will be great useful in the expression optimization, we'd better handle it properly.
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.
I mean nullable
is sometimes determined at runtime, a not null string, double.NaN is not null themselves, but would eval
to null
in Round
.
Test build #35555 has finished for PR 6938 at commit
|
Test build #35660 has finished for PR 6938 at commit
|
@chenghao-intel , refactored |
Test build #37221 has finished for PR 6938 at commit
|
override def left: Expression = child | ||
override def right: Expression = scale | ||
|
||
override def children: Seq[Expression] = Seq(child, scale) |
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.
i don't think you need this
|
||
// round_scale > current_scale would result in precision increase | ||
// and not allowed by o.a.s.s.types.Decimal.changePrecision, therefore null | ||
(0 to 7).foreach { i => |
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.
i -> scale
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.
I was also using i for array index here?
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.
ok - can you at least move bdResults closer to this loop?
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.
OK
OK I'm going to merge this. Please submit a patch to fix the minor comments. |
} | ||
} | ||
|
||
override def prettyName: String = "round" |
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 can remove this, since the expression is already named Round
Test build #37326 has finished for PR 6938 at commit
|
JIRA: https://issues.apache.org/jira/browse/SPARK-8279