Github user ueshin commented on a diff in the pull request:
https://github.com/apache/spark/pull/21053#discussion_r182327230
--- Diff:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/collectionOperations.scala
---
@@ -417,3 +417,106 @@ case class ArrayMax(child: Expression) extends
UnaryExpression with ImplicitCast
override def prettyName: String = "array_max"
}
+
+/**
+ * Returns the value of index `right` in Array `left` or the value for key
`right` in Map `left`.
+ */
+@ExpressionDescription(
+ usage = """
+ _FUNC_(array, index) - Returns element of array at given index. If
index < 0, accesses elements
+ from the last to the first. Returns NULL if the index exceeds the
length of the array.
+
+ _FUNC_(map, key) - Returns value for given key, or NULL if the key is
not contained in the map
+ """,
+ examples = """
+ Examples:
+ > SELECT _FUNC_(array(1, 2, 3), 2);
+ 2
+ > SELECT _FUNC_(map(1, 'a', 2, 'b'), 2);
+ "b"
+ """,
+ since = "2.4.0")
+case class ElementAt(left: Expression, right: Expression) extends
GetMapValueUtil {
+
+ override def dataType: DataType = left.dataType match {
+ case _: ArrayType => left.dataType.asInstanceOf[ArrayType].elementType
+ case _: MapType => left.dataType.asInstanceOf[MapType].valueType
+ }
--- End diff --
nit: how about:
```scala
override def dataType: DataType = left.dataType match {
case ArrayType(elementType, _) => elementType
case MapType(_, valueType, _) => valueType
}
```
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]