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 2019/12/05 07:06:22 UTC

[GitHub] [flink] JingsongLi commented on a change in pull request #10306: [FLINK-13943][table-api] Provide utility method to convert Flink table to Java List

JingsongLi commented on a change in pull request #10306: [FLINK-13943][table-api] Provide utility method to convert Flink table to Java List
URL: https://github.com/apache/flink/pull/10306#discussion_r354135147
 
 

 ##########
 File path: flink-table/flink-table-planner-blink/src/main/java/org/apache/flink/table/util/TableResultUtils.java
 ##########
 @@ -0,0 +1,172 @@
+/*
+ * 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.util;
+
+import org.apache.flink.annotation.Experimental;
+import org.apache.flink.api.common.ExecutionConfig;
+import org.apache.flink.api.common.JobExecutionResult;
+import org.apache.flink.api.common.accumulators.Accumulator;
+import org.apache.flink.api.common.accumulators.SerializedListAccumulator;
+import org.apache.flink.api.common.typeinfo.TypeInformation;
+import org.apache.flink.api.common.typeutils.TypeSerializer;
+import org.apache.flink.api.java.Utils;
+import org.apache.flink.streaming.api.datastream.DataStream;
+import org.apache.flink.streaming.api.datastream.DataStreamSink;
+import org.apache.flink.table.api.DataTypes;
+import org.apache.flink.table.api.Table;
+import org.apache.flink.table.api.TableEnvironment;
+import org.apache.flink.table.api.TableSchema;
+import org.apache.flink.table.api.internal.TableImpl;
+import org.apache.flink.table.runtime.types.LogicalTypeDataTypeConverter;
+import org.apache.flink.table.runtime.types.TypeInfoDataTypeConverter;
+import org.apache.flink.table.sinks.AppendStreamTableSink;
+import org.apache.flink.table.sinks.TableSink;
+import org.apache.flink.table.types.DataType;
+import org.apache.flink.table.types.logical.TimestampKind;
+import org.apache.flink.table.types.logical.TimestampType;
+import org.apache.flink.types.Row;
+import org.apache.flink.util.AbstractID;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * A collection of utilities for fetching table results.
+ *
+ * <p>NOTE: Methods in this utility class are experimental and can only be used for demonstration or testing
+ * small table results. Please DO NOT use them in production or on large tables.
+ *
+ * <p>We ought to put this class in the api module, but as converting high precision timestamp data type
+ * to type information is not possible in flink planner, we have to put this class in blink planner.
+ */
+@Experimental
+public class TableResultUtils {
+
+	/**
+	 * Convert Flink table to Java list.
+	 * This method is only applicable for small batch jobs and small finite append only stream jobs.
+	 *
+	 * @param table		Flink table to convert
+	 * @return			Converted Java list
+	 */
+	@SuppressWarnings("unchecked")
+	public static List<Row> tableResultToList(Table table) throws Exception {
 
 Review comment:
   Just `collect`?

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services