viirya commented on a change in pull request #33681: URL: https://github.com/apache/spark/pull/33681#discussion_r684968316
########## File path: examples/src/main/java/org/apache/spark/examples/sql/streaming/JavaStructuredComplexSessionization.java ########## @@ -0,0 +1,461 @@ +/* + * 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. + */ +package org.apache.spark.examples.sql.streaming; + +import java.io.Serializable; +import java.sql.Timestamp; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.Iterator; +import java.util.List; +import java.util.Spliterator; +import java.util.Spliterators; +import java.util.stream.Collectors; +import java.util.stream.Stream; +import java.util.stream.StreamSupport; + +import org.apache.spark.api.java.function.FlatMapGroupsWithStateFunction; +import org.apache.spark.api.java.function.MapFunction; +import org.apache.spark.sql.Dataset; +import org.apache.spark.sql.Encoders; +import org.apache.spark.sql.Row; +import org.apache.spark.sql.SparkSession; +import org.apache.spark.sql.streaming.GroupState; +import org.apache.spark.sql.streaming.GroupStateTimeout; +import org.apache.spark.sql.streaming.OutputMode; +import org.apache.spark.sql.streaming.StreamingQuery; +import org.apache.spark.sql.types.StructType; + +import static org.apache.spark.sql.types.DataTypes.StringType; +import static org.apache.spark.sql.types.DataTypes.TimestampType; +import static org.apache.spark.sql.functions.*; + +/** + * Sessionize events in UTF8 encoded, '\n' delimited text received from the network. + * Each line composes an event, and the line should match to the json format. + * <p> + * The schema of the event is following: + * - user_id: String + * - event_type: String + * - timestamp: Long + * <p> + * The supported types are following: + * - NEW_EVENT + * - CLOSE_SESSION + * <p> + * This example focuses to demonstrate the complex sessionization which uses two conditions + * on closing session; conditions are following: + * - No further event is provided for the user ID within 5 seconds + * - An event having CLOSE_SESSION as event_type is provided for the user ID + * <p> + * Usage: StructuredComplexSessionization <hostname> <port> + * <hostname> and <port> describe the TCP server that Structured Streaming + * would connect to receive data. + * <p> + * 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.StructuredComplexSessionization Review comment: StructuredComplexSessionization -> JavaStructuredComplexSessionization? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
