Kontext Copilot - An AI assistant for data analytics. Learn more
Expression of Interest
Spark SQL - element_at Function
insights Stats
warning Please login first to view stats information.
Kontext
Code Snippets & Tips
Code snippets and tips for various programming languages/frameworks. All code examples are under MIT or Apache 2.0 license unless specified otherwise.
Spark SQL function element_at(array, index)
returns element of array at given index. The index is 1-based (not 0-based).The function returns NULL if the index exceeds the length of the array and spark.sql.ansi.enabled
is set to false; otherwise it throws ArrayIndexOutOfBoundsException
for invalid indices.
element_at(map, key)
returns value for given key. The function returns NULL if the key is not contained in the map and spark.sql.ansi.enabled
is set to false; otherwise it throws NoSuchElementException
instead.
Code snippets
The following are some examples using this function in Spark SQL:
spark-sql> select element_at(array(1,2,3,4,5),1); element_at(array(1, 2, 3, 4, 5), 1) 1
For map
objects:
spark-sql> select element_at(map(1,'A',2,'B',3,'C',4,'D'),1); element_at(map(1, A, 2, B, 3, C, 4, D), 1) A
copyright
This page is subject to Site terms.
comment Comments
No comments yet.