write to two outputs at once in spark2
<p>I need to write to two outputs at once in spark2.
I tried something like this:</p>

<pre><code>    Dataset&lt;Row&gt; streamedData = spark.readStream().schema(getSchema())
            .json("src/test/data")
            .filter(x-&gt;{
                System.out.println("this is some fitler operation");
                return true;
            });

    StreamingQuery streamingQueury = streamedData
            .writeStream()
            .format("memory")
            .queryName("streameddata")
            .start();

    StreamingQuery streamingQueury2 = streamedData
            .writeStream()
            .format("console")
            .start();

    streamingQueury.awaitTermination(1000);
    streamingQueury2.awaitTermination(1000);
    streamingQueury.stop();
    streamingQueury2.stop();

    spark.sql("SELECT * FROM streameddata").show();
</code></pre>

<p>this will do what i need but it will execute whole chain two times what can be time consuming, i don't need to do all the transformations two times i just need to write it two times.</p>

<p>Is there a way for me?</p>

<p>Thanks</p>