You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by GitBox <gi...@apache.org> on 2018/10/04 01:53:48 UTC

[GitHub] hequn8128 commented on a change in pull request #6790: [FLINK-10487] fix invalid Flink SQL example and add runnable SQL example for Java API

hequn8128 commented on a change in pull request #6790: [FLINK-10487] fix invalid Flink SQL example and add runnable SQL example for Java API
URL: https://github.com/apache/flink/pull/6790#discussion_r222518000
 
 

 ##########
 File path: flink-examples/flink-examples-table/src/main/java/org/apache/flink/table/examples/java/StreamSQLExample.java
 ##########
 @@ -0,0 +1,103 @@
+/*
+ * 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.flink.table.examples.java;
+
+import org.apache.flink.streaming.api.datastream.DataStream;
+import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
+import org.apache.flink.table.api.Table;
+import org.apache.flink.table.api.TableEnvironment;
+import org.apache.flink.table.api.java.StreamTableEnvironment;
+
+import java.util.Arrays;
+
+/**
+ * Simple example for demonstrating the use of SQL on a Stream Table in Java.
+ *
+ * <p>This example shows how to:
+ *  - Convert DataStreams to Tables
+ *  - Register a Table under a name
+ *  - Run a StreamSQL query on the registered Table
+ *
+ */
+public class StreamSQLExample {
+
+	// *************************************************************************
+	//     PROGRAM
+	// *************************************************************************
+
+	public static void main(String[] args) throws Exception {
+
+		// set up execution environment
+		StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
+		StreamTableEnvironment tEnv = TableEnvironment.getTableEnvironment(env);
+
+		DataStream<Order> orderA = env.fromCollection(Arrays.asList(
+			new Order(1L, "beer", 3),
+			new Order(1L, "diaper", 4),
+			new Order(3L, "rubber", 2)));
+
+		DataStream<Order> orderB = env.fromCollection(Arrays.asList(
+			new Order(2L, "pen", 3),
+			new Order(2L, "rubber", 3),
+			new Order(4L, "beer", 1)));
+
+		// register the DataSet as table "WordCount"
+		Table tableA = tEnv.fromDataStream(orderA, "user, product, amount");
+		tEnv.registerDataStream("OrderB", orderB, "user, product, amount");
+
+		// run a SQL query on the Table and retrieve the result as a new Table
 
 Review comment:
   Change to "union the two tables" making it consistent to the comments in scala?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services