1

我需要在 spark2 中一次写入两个输出。我试过这样的事情:

    Dataset<Row> streamedData = spark.readStream().schema(getSchema())
            .json("src/test/data")
            .filter(x->{
                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();

这将做我需要的,但它会执行整个链两次,这可能很耗时,我不需要做所有的转换两次我只需要写两次。

我有办法吗?

谢谢

4

0 回答 0