title: Stop Structured Streaming query gracefully
body: <p>I'm using Spark 2.1 and trying to stop a Streaming query gracefully.</p>
  
  <p>Is <code>StreamingQuery.stop()</code> a graceful stop because I haven't seen any detailed information on this method in the <a href="https://spark.apache.org/docs/2.1.0/api/java/org/apache/spark/sql/streaming/StreamingQuery.html" rel="noreferrer">documentation</a>:</p>
  
  <blockquote>
    <p><code>void stop()</code>
    Stops the execution of this query if it is running. 
    This method blocks until the threads performing execution has stopped.
    Since: 2.0.0</p>
  </blockquote>
  
  <p>Whereas in the past Streaming world (DStreams) there is an <a href="http://spark.apache.org/docs/latest/api/scala/index.html#org.apache.spark.streaming.StreamingContext@stop(stopSparkContext:Boolean,stopGracefully:Boolean):Unit" rel="noreferrer">option to stop</a> the execution of the streams, with option of ensuring all received data has been processed:</p>
  
  <blockquote>
    <p><code>def stop(stopSparkContext: Boolean, stopGracefully: Boolean): Unit</code>
     Stop the execution of the streams, with option of ensuring all received data has been processed.</p>
    
    <p><code>stopSparkContext</code>
    if true, stops the associated SparkContext. The underlying SparkContext will be stopped regardless of whether this
    StreamingContext has been started.</p>
    
    <p><code>stopGracefully</code>
     if true, stops gracefully by waiting for the processing of all received data to be completed</p>
  </blockquote>
  
  <p>So the question is how to stop a Structured Streaming Query gracefully?</p>