title: Spark SQL - aggregate columns into dictionary
body: <p>I have the following data frame:</p>
  <pre><code>spark.sql(&quot;&quot;&quot;
  SELECT id, color, cnt
  FROM ( 
    VALUES ('A','green', 5),
           ('A','yellow', 4),
           ('A','yellow',2),
           ('B','blue', 3),
           ('B','green',4),
           ('B','blue',1) 
  ) as T (id, color, cnt)
  &quot;&quot;&quot;)
  </code></pre>
  <p>and would like to aggregate it in such a way that for each <code>id</code> key I have a dictionary of counts and sums of <code>cnt</code> column. So the output would be:</p>
  <pre><code>+---+-----------------------------------------+
  | id|         color_cnt | color_sum           |
  +---+-----------------------------------------+
  |  B|{blue:2, green:1}  | {blue:4, green:4}   | 
  |  A|{green:1, yellow:2}| {green:5, yellow:6} |
  +---+-------------------+---------------------+
  </code></pre>
  <p>Are there any <strong>Spark SQL</strong> functions that would help me achieve what I need?
  Thanks!</p>