title: Merging records by 1+ common elements
body: <p>I have a hive table with the following schema:</p>
  <pre><code>int key1 # this is unique
  array&lt;int&gt; key2_list
  </code></pre>
  <p>Now I want to merge records here if their key2_lists have any common element(s). For example, if record A has (10, [1,3,5]) and B has (12, [1,2,4]), I want to merge it as ([10,12], [1,2,3,4,5]) or ([1,2,3,4,5]).</p>
  <p>If it is easier, the input table can have the following schema instead:</p>
  <pre><code>int key1
  int key2
  </code></pre>
  <p>I'd prefer to do this through Hive or SparkSQL.</p>