Spark SQL - Create Map from Arrays via map_from_arrays Function
Spark SQL function map_from_arrays(col1, col2)
returns a new map from two arrays. The two arrays can be two columns of a table. The two columns need to be array data type.
Code snippets
The following are some examples using this function in Spark SQL:
spark-sql> SELECT map_from_arrays(t.key, t.value) as map FROM VALUES > (array('a','b'),array(1,2)), > (array('a','b'),array(100,200)) > AS t(key, value); {"a":1,"b":2} {"a":100,"b":200}
The above script creates a table from values with columns named as key
and value
.
The result prints out two rows of MapType
object.
copyright
This page is subject to Site terms.
comment Comments
No comments yet.