GitHub user lw-lin opened a pull request: https://github.com/apache/spark/pull/12725
[SPARK-14942][SQL][Streaming] First construct a batch then run the batch for continuous queries ## Problem Currently in `StreamExecution`, we first run the batch, then construct the next: ```scala if (dataAvailable) runBatch() constructNextBatch() ``` This is good if we run batches ASAP, where data would get processed in the **very next batch**: ![1](https://cloud.githubusercontent.com/assets/15843379/14779964/2786e698-0b0d-11e6-9d2c-bb41513488b2.png) However, if we run batches at trigger like `ProcessTime("1 minute")`, data - such as _y_ below - may not get processed in the very next batch i.e. _batch 1_, but in _batch 2_: ![2](https://cloud.githubusercontent.com/assets/15843379/14779818/6f3bb064-0b0c-11e6-9f16-c1ce4897186b.png) ## What changes were proposed in this pull request? This patch reverse the order of `constructNextBatch()` and `runBatch()`. After this patch, data would get processed in the **very next batch**, i.e. _batch 1_: ![3](https://cloud.githubusercontent.com/assets/15843379/14779816/6f36ee62-0b0c-11e6-9e53-bc8397fade18.png) In addition, this patch alters when we do `currentBatchId += 1`: let's do that when the processing of the current batch of data is complete, so we won't bother passing `currentBatchId + 1` or `currentBatchId - 1` to states or sinks. ## How was this patch tested? This should be covered by existing test suits including stress tests. You can merge this pull request into a Git repository by running: $ git pull https://github.com/lw-lin/spark construct-before-run-3 Alternatively you can review and apply these changes as the patch at: https://github.com/apache/spark/pull/12725.patch To close this pull request, make a commit to your master/trunk branch with (at least) the following in the commit message: This closes #12725 ---- commit 8c8d73a85550349faafef1cbde1c7094d384809e Author: Liwei Lin <lwl...@gmail.com> Date: 2016-04-27T02:19:14Z constructNextBatch() before runBatch() ---- --- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. --- --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org