title: Aws Athena / Presto - nest two tables
body: <p>I'd like to use aws athena to nest two parquet tables such that:</p>
  <p>Table A</p>
  <pre><code>|document_id| name|
  +-----------+-----+
  |          1|  aaa|
  |          2|  bbb|
  </code></pre>
  <p>Table B</p>
  <pre><code>|   topic_id| name|document_id|
  +-----------+-----+-----------+
  |          1|  xxx|          1|
  |          2|  yyy|          2|
  |          3|  zzz|          2|
  </code></pre>
  <p>Nest table B into table A to get something like</p>
  <pre><code>[
      {
          &quot;document_id&quot;: 1,
          &quot;name&quot;: &quot;aaa&quot;,
          &quot;topics&quot;: [
              {
                  &quot;topic_id&quot;: 1,
                  &quot;name&quot;: &quot;xxx&quot;
              }
          ]
      },
      {
          &quot;document_id&quot;: 2,
          &quot;name&quot;: &quot;bbb&quot;,
          &quot;topics&quot;: [
              {
                  &quot;topic_id&quot;: 2,
                  &quot;name&quot;: &quot;yyy&quot;
              },
              {
                  &quot;topic_id&quot;: 3,
                  &quot;name&quot;: &quot;zzz&quot;
              }
          ]
      }
  ]
  </code></pre>
  <p>Is it possible? Any ideas?</p>
  <p>Note: I got the example from <a href="https://stackoverflow.com/questions/49953820/merging-two-relational-pandas-dataframes-as-single-nested-json-output">this stakoverflow thread</a></p>