Github user tdas commented on a diff in the pull request:

    https://github.com/apache/spark/pull/13957#discussion_r69053315
  
    --- Diff: 
examples/src/main/scala/org/apache/spark/examples/sql/streaming/EventTimeWindow.scala
 ---
    @@ -0,0 +1,114 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one or more
    + * contributor license agreements.  See the NOTICE file distributed with
    + * this work for additional information regarding copyright ownership.
    + * The ASF licenses this file to You under the Apache License, Version 2.0
    + * (the "License"); you may not use this file except in compliance with
    + * the License.  You may obtain a copy of the License at
    + *
    + *    http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +
    +// scalastyle:off println
    +package org.apache.spark.examples.sql.streaming
    +
    +import org.apache.spark.sql.SparkSession
    +import org.apache.spark.sql.functions._
    +import org.apache.spark.sql.types.{DoubleType, TimestampType}
    +
    +/**
    + * Computes the average signal from IoT device readings over a sliding 
window of
    + * configurable duration. The readings are received over the network and 
must be
    + * UTF8-encoded and separated by '\n'.
    + *
    + * A single reading should take the format
    + * <device name (string)>, <reading (double)>
    + *
    + * Usage: EventTimeWindow <hostname> <port> <window duration>
    + *   <slide duration>
    + * <hostname> and <port> describe the TCP server that Structured Streaming 
would connect to
    + * receive data.
    + * <window duration> gives the size of window, specified as integer number 
of seconds, minutes,
    + * or days, e.g. "1 minute", "2 seconds"
    + * <slide duration> gives the amount of time successive windows are offset 
from one another,
    + * given in the same units as above
    + * (<window duration> and <slide duration> must be enclosed by quotes to 
ensure that
    + * they are processed as individual arguments)
    + *
    + * To run this on your local machine, you need to first run a Netcat server
    + *    `$ nc -lk 9999`
    + * and then run the example
    + *    `$ bin/run-example sql.streaming.EventTimeWindow
    + *    localhost 9999 <window duration> <slide duration>`
    + *
    + * Type device readings in the format given above into Netcat.
    + *
    + * An example sequence of device readings:
    + * dev0,7.0
    + * dev1,8.0
    + * dev0,5.0
    + * dev1,3.0
    + */
    +object EventTimeWindow {
    +
    +  def main(args: Array[String]) {
    +    if (args.length < 4) {
    +      System.err.println("Usage: EventTimeWindow <hostname> <port> <window 
duration>" +
    +        " <slide duration>")
    +      System.exit(1)
    +    }
    +
    +    val host = args(0)
    +    val port = args(1).toInt
    +    val windowSize = args(2)
    +    val slideSize = args(3)
    +
    +    val spark = SparkSession
    +      .builder
    +      .appName("EventTimeWindow")
    +      .getOrCreate()
    +
    +    // Create DataFrame representing the stream of input readings from 
connection to host:port
    +    val lines = spark.readStream
    +      .format("socket")
    +      .option("host", host)
    +      .option("port", port)
    +      .option("includeTimestamp", true)
    +      .load()
    +
    +    // Split the readings into their individual components
    +    val splitLines = lines.select(
    +      split(lines.col("value"), ",").alias("pieces"),
    --- End diff --
    
    as i said offline this is very complex example. rather just do streaming 
windowed word count. 



---
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 [email protected] or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to