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 @@ -1469,6 +1469,7 @@ case class ElementAt(left: Expression, right: Expression) extends GetMapValueUti
left.dataType match {
case _: ArrayType => IntegerType
case _: MapType => left.dataType.asInstanceOf[MapType].keyType
case _ => AnyDataType // no match for a wrong 'left' expression type
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW, normally, we prefer to

  override def inputTypes: Seq[AbstractDataType] = {
    val rightInputType = left.dataType match {
      case _: ArrayType => IntegerType
      case _: MapType => left.dataType.asInstanceOf[MapType].keyType
      case _ => AnyDataType // no match for a wrong 'left' expression type
    }
    Seq(TypeCollection(ArrayType, MapType), rightInputType)
  }

}
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -756,6 +756,12 @@ class DataFrameFunctionsSuite extends QueryTest with SharedSQLContext {
df.selectExpr("element_at(a, -1)"),
Seq(Row("3"), Row(""), Row(null))
)

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

test("concat function - arrays") {
Expand Down