Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
array_position deals with Column Type
  • Loading branch information
Chongguang LIU authored and Chongguang LIU committed Jun 18, 2018
commit e65611e451bf49b38850af84a89510ac8a749cbd
5 changes: 4 additions & 1 deletion sql/core/src/main/scala/org/apache/spark/sql/functions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3150,7 +3150,10 @@ object functions {
* @since 2.4.0
*/
def array_position(column: Column, value: Any): Column = withExpr {
ArrayPosition(column.expr, Literal(value))
value match {
case c: Column => ArrayPosition(column.expr, c.expr)
case _ => ArrayPosition(column.expr, Literal(value))
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -789,9 +789,9 @@ class DataFrameFunctionsSuite extends QueryTest with SharedSQLContext {

test("array position function") {
val df = Seq(
(Seq[Int](1, 2), "x"),
(Seq[Int](), "x")
).toDF("a", "b")
(Seq[Int](1, 2), "x", 1),
(Seq[Int](), "x", 1)
).toDF("a", "b", "c")

checkAnswer(
df.select(array_position(df("a"), 1)),
Expand All @@ -801,7 +801,10 @@ class DataFrameFunctionsSuite extends QueryTest with SharedSQLContext {
df.selectExpr("array_position(a, 1)"),
Seq(Row(1L), Row(0L))
)

checkAnswer(
df.select(array_position(df("a"), df("c"))),
Seq(Row(1L), Row(0L))
)
checkAnswer(
df.select(array_position(df("a"), null)),
Seq(Row(null), Row(null))
Expand Down