com.alibaba.ververica.connectors.odps.sink.OdpsDynamicTableSink 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 com.alibaba.ververica.connectors.odps.sink;
import org.apache.flink.configuration.ReadableConfig;
import org.apache.flink.table.api.TableSchema;
import org.apache.flink.table.connector.ChangelogMode;
import org.apache.flink.table.connector.sink.DynamicTableSink;
import org.apache.flink.table.connector.sink.SinkFunctionProvider;
import org.apache.flink.table.types.DataType;
import com.alibaba.ververica.connectors.common.sink.OutputFormatSinkFunction;
import com.alibaba.ververica.connectors.odps.OdpsOptions;
/**
* A DynamicTableSink to write upsert stream to an Odps table.
*/
public class OdpsDynamicTableSink implements DynamicTableSink {
private final DataType rowType;
private final TableSchema tableSchema;
private final ReadableConfig config;
public OdpsDynamicTableSink(TableSchema tableSchema, DataType rowType, ReadableConfig config) {
this.tableSchema = tableSchema;
this.rowType = rowType;
this.config = config;
}
@Override
public ChangelogMode getChangelogMode(ChangelogMode changelogMode) {
return changelogMode;
}
@Override
public SinkRuntimeProvider getSinkRuntimeProvider(Context context) {
return SinkFunctionProvider.of(new OutputFormatSinkFunction<>(
new OdpsDynamicOutputFormat(
tableSchema,
context.createDataStructureConverter(rowType),
config)));
}
@Override
public DynamicTableSink copy() {
return new OdpsDynamicTableSink(tableSchema, rowType, config);
}
@Override
public String asSummaryString() {
return "ODPS Sink - table: " + config.get(OdpsOptions.TABLE_NAME);
}
}