-
Notifications
You must be signed in to change notification settings - Fork 28.3k
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-8203] [SPARK-8204] [SQL] conditional function: least/greatest #6851
Conversation
@@ -134,4 +134,21 @@ class ConditionalExpressionSuite extends SparkFunSuite with ExpressionEvalHelper | |||
checkEvaluation(CaseKeyWhen(literalNull, Seq(c2, c5, c1, c6)), "c", row) | |||
} | |||
|
|||
test("greatest/least") { | |||
val row = create_row(1, 2, "a", "b", "c") |
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 need to test this for all data types.
Don't forget to implement the |
Test build #35027 has finished for PR 6851 at commit
|
Test build #36926 has finished for PR 6851 at commit
|
greatest((columnName +: columnNames).map(Column.apply): _*) | ||
|
||
/** | ||
* Computes hex value of the given column |
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.
Nit:
/**
- Computes hex value for the given column.
*
Can you rebase the code? |
Test build #36999 has finished for PR 6851 at commit
|
Test build #37001 has finished for PR 6851 at commit
|
retest this please. |
Test build #37011 has finished for PR 6851 at commit
|
retest this please. |
Test build #37012 has finished for PR 6851 at commit
|
* @since 1.5.0 | ||
*/ | ||
@scala.annotation.varargs | ||
def greatest(exprs: Column*): Column = Greatest(exprs.map(_.expr): _*) |
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.
Should we check that exprs
have at least two columns? Also for others, it's good to fail fast.
Test build #37117 has finished for PR 6851 at commit
|
cc @davies |
LGTM, merging this into master, thanks! |
@@ -312,3 +313,103 @@ case class CaseKeyWhen(key: Expression, branches: Seq[Expression]) extends CaseW | |||
}.mkString | |||
} | |||
} | |||
|
|||
case class Least(children: 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.
note: this should be Seq[Expression], not vararg
chenghao-intel zhichao-li qiansl127 Author: Daoyuan Wang <daoyuan.wang@intel.com> Closes apache#6851 from adrian-wang/udflg and squashes the following commits: 0f1bff2 [Daoyuan Wang] address comments from davis 7a6bdbb [Daoyuan Wang] add '.' for hex() c1f6824 [Daoyuan Wang] add codegen, test for all types ec625b0 [Daoyuan Wang] conditional function: least/greatest
@adrian-wang probably a sync problem. It was evidently merged into master. You can just close it too. |
Test build #37132 has finished for PR 6851 at commit
|
@@ -312,3 +313,103 @@ case class CaseKeyWhen(key: Expression, branches: Seq[Expression]) extends CaseW | |||
}.mkString | |||
} | |||
} | |||
|
|||
case class Least(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.
can you add scaladoc explaining the semantics of this expression? also do it for greatest.
@adrian-wang I found that happening quite a bit lately. Can you close the pr and just submit followup patches to address my comments? thanks. |
private lazy val ordering = TypeUtils.getOrdering(dataType) | ||
|
||
override def checkInputDataTypes(): TypeCheckResult = { | ||
if (children.map(_.dataType).distinct.count(_ != NullType) > 1) { |
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.
Why count against not NullType
? any reason 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.
i think the problem is that null literals are not converted into any non-null type when it happens in greatest.
@chenghao-intel @zhichao-li @qiansl127