All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.apache.flink.table.client.gateway.local.CollectBatchTableSink Maven / Gradle / Ivy

/*
 * 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.client.gateway.local;

import org.apache.flink.api.common.ExecutionConfig;
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.TableConfig;
import org.apache.flink.table.sinks.BatchTableSink;
import org.apache.flink.table.sinks.TableSink;
import org.apache.flink.table.types.DataType;
import org.apache.flink.table.types.DataTypes;
import org.apache.flink.types.Row;

/**
 * Table sink for collecting the results locally all at once using accumulators.
 */
@Deprecated
public class CollectBatchTableSink implements BatchTableSink {

	private final String accumulatorName;
	private final TypeSerializer serializer;

	private String[] fieldNames;
	private DataType[] fieldTypes;

	public CollectBatchTableSink(String accumulatorName, TypeSerializer serializer) {
		this.accumulatorName = accumulatorName;
		this.serializer = serializer;
	}

	@Override
	public DataType getOutputType() {
		return DataTypes.createRowTypeV2(fieldTypes, fieldNames);
	}

	@Override
	public String[] getFieldNames() {
		return fieldNames;
	}

	@Override
	public DataType[] getFieldTypes() {
		return fieldTypes;
	}

	@Override
	public TableSink configure(String[] fieldNames, DataType[] fieldTypes) {
		final CollectBatchTableSink copy = new CollectBatchTableSink(accumulatorName, serializer);
		copy.fieldNames = fieldNames;
		copy.fieldTypes = fieldTypes;
		return copy;
	}

	@Override
	public DataStreamSink emitBoundedStream(
			DataStream boundedStream, TableConfig tableConfig, ExecutionConfig executionConfig) {
		return boundedStream
			.writeUsingOutputFormat(new Utils.CollectHelper<>(accumulatorName, serializer))
			.name("SQL Client Batch Collect Sink");
	}

	/**
	 * Returns the serializer for deserializing the collected result.
	 */
	public TypeSerializer getSerializer() {
		return serializer;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy