Search in sources :

Example 1 with StreamingQueryException

use of org.apache.spark.sql.streaming.StreamingQueryException in project net.jgp.labs.spark by jgperrin.

the class ReadLinesFromMultipleFileStreams method start.

private void start() {
    log.debug("-> start()");
    SparkSession spark = SparkSession.builder().appName("Read lines over a file stream").master("local").getOrCreate();
    // @formatter:off
    Dataset<Row> df = spark.readStream().format("text").load(StreamingUtils.getInputDirectory());
    // @formatter:on
    StreamingQuery query = df.writeStream().outputMode(OutputMode.Update()).format("console").start();
    try {
        query.awaitTermination();
    } catch (StreamingQueryException e) {
        log.error("Exception while waiting for query to end {}.", e.getMessage(), e);
    }
    // In this case everything is a string
    df.show();
    df.printSchema();
}
Also used : SparkSession(org.apache.spark.sql.SparkSession) StreamingQuery(org.apache.spark.sql.streaming.StreamingQuery) Row(org.apache.spark.sql.Row) StreamingQueryException(org.apache.spark.sql.streaming.StreamingQueryException)

Example 2 with StreamingQueryException

use of org.apache.spark.sql.streaming.StreamingQueryException in project net.jgp.labs.spark by jgperrin.

the class ReadLinesFromFileStream method start.

private void start() {
    log.debug("-> start()");
    SparkSession spark = SparkSession.builder().appName("Read lines over a file stream").master("local").getOrCreate();
    Dataset<Row> df = spark.readStream().format("text").load(StreamingUtils.getInputDirectory());
    StreamingQuery query = df.writeStream().outputMode(OutputMode.Update()).format("console").start();
    try {
        query.awaitTermination();
    } catch (StreamingQueryException e) {
        log.error("Exception while waiting for query to end {}.", e.getMessage(), e);
    }
    // Never executed
    df.show();
    df.printSchema();
}
Also used : SparkSession(org.apache.spark.sql.SparkSession) StreamingQuery(org.apache.spark.sql.streaming.StreamingQuery) Row(org.apache.spark.sql.Row) StreamingQueryException(org.apache.spark.sql.streaming.StreamingQueryException)

Aggregations

Row (org.apache.spark.sql.Row)2 SparkSession (org.apache.spark.sql.SparkSession)2 StreamingQuery (org.apache.spark.sql.streaming.StreamingQuery)2 StreamingQueryException (org.apache.spark.sql.streaming.StreamingQueryException)2