title: how to generate new column values for each group using a condition
body: <p>I have a dataframe in spark as follows: </p>
  
  <p><code>ID   Sales</code>   </p>
  
  
  
  <pre><code>1      0  
  1      0  
  1      5000  
  1      0    
  1      0
  1      2000
  1      0
  2      0
  2      0
  2      3000
  2      1000
  2      0
  2      0
  </code></pre>
  
  <p>Now, I 'd like to create a third column that will, for each ID, start with 0 and increase by 1 whenever a strictly positive value is encountered in the Sales column. Whenever the indicator is increased by 1, I'd like that number to repeat until another strictly positive value is encountered for the Sales column down the rows.  The resulting dataframe would be as follows:</p>
  
  <pre><code>ID   Sales  Indicator
  </code></pre>
  
  
  
  <pre><code>1      0      0  
  1      0      0
  1      5000   1
  1      0      1
  1      0      1
  1      2000   2
  1      0      2
  2      0      0
  2      0      0
  2      3000   1
  2      1000   2
  2      0      2
  2      0      2
  </code></pre>
  
  <p>How could I achieve this in an efficient way? Could we use mapPartitions for this? I looked into window functions but could not think of a way of doing it. Thank you very much. </p>