title: Count distinct values in a stream pipeline
body: <p>I have a pipeline that looks like</p>
  
  <pre><code>pipeline.apply(PubsubIO.read.subscription("some subscription"))
              .apply(Window.into(SlidingWindow.of(10 mins).every(20 seconds)
                              .triggering(AfterProcessingTime.pastFirstElementInPane()
                      .plusDelayOf(20 seconds))
                      .withAllowedLateness(Duration.ZERO)
                      .accumulatingFiredPanes()))
              .apply(RemoveDuplicates.create())
              .apply(Window.discardingFiredPanes()) // this is suggested in the warnings under https://cloud.google.com/dataflow/model/triggers#window-accumulation-modes
              .apply(Count.&lt;String&gt;globally().withoutDefaults())
  </code></pre>
  
  <p>This pipeline overcounts distinct values significantly (20x normal value). Initially, I was suspecting that the default trigger may have caused this issue. I have tweaked to use triggers that allow no lateness/discard fired panes/use processing time, all of which have similar overcount issues.</p>
  
  <p>I've also tried <code>ApproximateUnique.globally</code>: it failed during pipeline construction because of an exception that looks like
  <code>Default values are not supported in Combine.globally() if the output PCollection is not windowed by GlobalWindows.</code> There seems no way to add <code>withoutDefaults</code> to it (like we did with <code>Count.globally</code>).</p>
  
  <p>Is there a recommended way to do <code>COUNT(DISTINCT)</code> in dataflow/beam streaming pipeline with reasonable precision?</p>
  
  <p>P.S. I'm using Java Dataflow SDK 1.9.0.</p>