Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -1394,8 +1394,14 @@ case class ArrayPosition(left: Expression, right: Expression)
TypeUtils.getInterpretedOrdering(right.dataType)

override def dataType: DataType = LongType
override def inputTypes: Seq[AbstractDataType] =
Seq(ArrayType, left.dataType.asInstanceOf[ArrayType].elementType)

override def inputTypes: Seq[AbstractDataType] = {
val elementType = left.dataType match {
case t: ArrayType => t.elementType
case _ => AnyDataType
}
Seq(ArrayType, elementType)
}

override def checkInputDataTypes(): TypeCheckResult = {
super.checkInputDataTypes() match {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -708,6 +708,11 @@ class DataFrameFunctionsSuite extends QueryTest with SharedSQLContext {
df.selectExpr("array_position(array(1, null), array(1, null)[0])"),
Seq(Row(1L), Row(1L))
)

val e = intercept[AnalysisException] {
Seq(("a string element", "a")).toDF().selectExpr("array_position(_1, _2)")
}
assert(e.message.contains("argument 1 requires array type, however, '`_1`' is of string type"))
}

test("element_at function") {
Expand Down