Spark SQL - Create Map from Arrays via map_from_arrays Function

Kontext Kontext visibility 1,379 event 2022-07-09 access_time 2 years ago language English

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);

The above script creates a table from values with columns named as key and value

The result prints out two rows of MapType object. 

More from Kontext
copyright This page is subject to Site terms.
comment Comments
No comments yet.

Please log in or register to comment.

account_circle Log in person_add Register

Log in with external accounts