title: Why does streaming query with update output mode print out all rows?
body: <p>I have three text files in my directory:</p>
  
  <p>a.txt</p>
  
  <pre><code>A B
  C D
  A E
  F
  </code></pre>
  
  <p>b.txt</p>
  
  <pre><code>A B
  C D
  A E
  </code></pre>
  
  <p>c.txt</p>
  
  <pre><code>A B
  C D
  A E
  G
  </code></pre>
  
  <p>I use the following streaming query:</p>
  
  <pre><code>val schema = new StructType().add("value", "string")
  val lines = spark
    .readStream
    .schema(schema)
    .option("maxFilesPerTrigger", 1)
    .text(...)
    .as[String]
  
  val wordCounts = lines.flatMap(_.split("\\s+")).groupBy("value").count()
  
  val query = wordCounts.writeStream
    .queryName("t")
    .outputMode("update") // &lt;-- output mode: update
    .format("memory")
    .start()
  
  while (true) {
    spark.sql("select * from t").show(truncate = false)
    println(new Date())
    Thread.sleep(1000)
  }
  </code></pre>
  
  <p>The query always outputs the following results:</p>
  
  <pre><code>+-----+-----+
  |value|count|
  +-----+-----+
  |A    |2    |
  |B    |1    |
  |C    |1    |
  |D    |1    |
  |E    |1    |
  |A    |4    |
  |B    |2    |
  |C    |2    |
  |D    |2    |
  |E    |2    |
  |G    |1    |
  |A    |6    |
  |B    |3    |
  |C    |3    |
  |D    |3    |
  |E    |3    |
  |F    |1    |
  +-----+-----+
  </code></pre>
  
  <p>It looks like each file's result is appended to the output result (as in <code>Append</code> output mode) and I'm not sure I understand what <code>update</code> mode means. How does <code>update</code> output mode work?</p>