title: Google Dataflow - Apache Beam GroupByKey(): Duplicating/Slow
body: <p>I'm facing a situation with beam.GroupByKey(), I've loaded a file whose amount of lines is 42.854.</p>
  <p>Due to the business rules, I need to execute a GroupByKey(); However, After finishing its execution I noticed that I got almost the double of lines. As you can see below :</p>
  <p><a href="https://i.stack.imgur.com/gWl2R.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/gWl2R.png" alt="enter image description here" /></a></p>
  <p>Step before the GroupByKey():</p>
  <p><a href="https://i.stack.imgur.com/dAauJ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/dAauJ.png" alt="enter image description here" /></a></p>
  <p>Why am I having this behavior ?</p>
  <p>I'm not doing anything special in my pipeline:</p>
  <pre><code>with beam.Pipeline(runner, options=opts) as p:
  
      #LOAD FILE
      elements = p | 'Load File' &gt;&gt; beam.Create(fileRNS.values)
  
      #PREPARE VALUES (BULK INSERT)
      Script_Values = elements | 'Prepare Bulk Insert' &gt;&gt; beam.ParDo(Prepare_Bulk_Insert())  
              
      Grouped_Values = Script_Values | 'Grouping values' &gt;&gt; beam.GroupByKey()
  
      #BULK INSERT INTO POSTGRESQL
      Grouped_Values | 'Insert PostgreSQL' &gt;&gt; beam.ParDo(ExecuteInsert)  
      
  </code></pre>
  <p><strong>2021-02-09</strong></p>
  <p>When I debug, Prepare_Bulk_Insert() has the following content :</p>
  <p><a href="https://i.stack.imgur.com/iwHHZ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/iwHHZ.png" alt="enter image description here" /></a></p>
  <p>As you can see, the amount of elements is correct, I don't understand why GroupByKey() has its input with a higher amount of elements if I'm sending the correct amount.</p>
  <p>The Grouped_Values | 'Insert PostgreSQL' &gt;&gt; beam.ParDo(funcaoMap) has its input as follows:</p>
  <p><a href="https://i.stack.imgur.com/SazFa.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/SazFa.png" alt="enter image description here" /></a></p>
  <p>Double amount. =(</p>
  <p>Kind regards,
  Juliano Medeiros</p>