Uh oh!
There was an error while loading. Please reload this page.
[SPARK-25416][SQL] ArrayPosition function may return incorrect result when right expression is implicitly down casted - #22407
[SPARK-25416][SQL] ArrayPosition function may return incorrect result when right expression is implicitly down casted#22407dilipbiswal wants to merge 3 commits into
Conversation
… right expression is implicitly down casted.
SparkQA
commented
Sep 12, 2018
Test build #96008 has finished for PR 22407 at commit
|
dilipbiswal
commented
Sep 13, 2018
retest this please |
SparkQA
commented
Sep 13, 2018
Test build #96014 has finished for PR 22407 at commit
|
gatorsmile
commented
Sep 13, 2018
cc @ueshin |
| case TypeCheckResult.TypeCheckSuccess => | ||
| (left.dataType, right.dataType) match { | ||
| case (ArrayType(e1, _), e2) if e1.sameType(e2) => | ||
| TypeUtils.checkForOrderingExpr(right.dataType, s"function $prettyName") |
There was a problem hiding this comment.
nit: we can use e1 or e2 instead of right.dataType?
| checkAnswer( | ||
| df.selectExpr("array_position(array(1.23D), 1)"), | ||
| Seq(Row(0L), Row(0L)) | ||
| ) |
There was a problem hiding this comment.
What about array_position(array(1.0D), 1)?
dilipbiswal
commented
Sep 13, 2018
ueshin
commented
Sep 13, 2018
@dilipbiswal Thanks! I'll take a look at it. |
SparkQA
commented
Sep 13, 2018
Test build #96024 has finished for PR 22407 at commit
|
dilipbiswal
commented
Sep 13, 2018
retest this please. |
SparkQA
commented
Sep 13, 2018
Test build #96028 has finished for PR 22407 at commit
|
SparkQA
commented
Sep 13, 2018
Test build #96027 has finished for PR 22407 at commit
|
dilipbiswal
commented
Sep 21, 2018
@ueshin Wenchen thought it may be risky to backport the fix to tighestCommonType. Given this, can this be looked at now ? |
ueshin
commented
Sep 21, 2018
ueshin
commented
Sep 21, 2018
Jenkins, retest this please. |
ueshin
commented
Sep 21, 2018
LGTM, pending Jenkins. |
SparkQA
commented
Sep 21, 2018
Test build #96421 has finished for PR 22407 at commit
|
| ) | ||
| checkAnswer( | ||
| df.selectExpr("array_position(array(1), 1.23D)"), |
There was a problem hiding this comment.
same problem here. The test doesn't read any column from df, so we should use OneRowRelation.
cloud-fan
commented
Sep 22, 2018
LGTM except one comment |
SparkQA
commented
Sep 22, 2018
Test build #96475 has finished for PR 22407 at commit
|
… when right expression is implicitly down casted ## What changes were proposed in this pull request? In ArrayPosition, we currently cast the right hand side expression to match the element type of the left hand side Array. This may result in down casting and may return wrong result or questionable result. Example : ```SQL spark-sql> select array_position(array(1), 1.34); 1 ``` ```SQL spark-sql> select array_position(array(1), 'foo'); null ``` We should safely coerce both left and right hand side expressions. ## How was this patch tested? Added tests in DataFrameFunctionsSuite Closes#22407 from dilipbiswal/SPARK-25416. Authored-by: Dilip Biswal <dbiswal@us.ibm.com> Signed-off-by: Wenchen Fan <wenchen@databricks.com> (cherry picked from commit bb49661) Signed-off-by: Wenchen Fan <wenchen@databricks.com>
cloud-fan
commented
Sep 24, 2018
thanks, merging to master/2.4! |
dilipbiswal
commented
Sep 24, 2018
@cloud-fan@ueshin Thank you very much !! |
What changes were proposed in this pull request?
In ArrayPosition, we currently cast the right hand side expression to match the element type of the left hand side Array. This may result in down casting and may return wrong result or questionable result.
Example :
We should safely coerce both left and right hand side expressions.
How was this patch tested?
Added tests in DataFrameFunctionsSuite