wuchong commented on a change in pull request #8867: [FLINK-12956][jdbc] Introduce upsert table sink for JDBC URL: https://github.com/apache/flink/pull/8867#discussion_r300300615
########## File path: flink-connectors/flink-jdbc/src/main/java/org/apache/flink/api/java/io/jdbc/JDBCUpsertTableSink.java ########## @@ -0,0 +1,193 @@ +/* + * 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.api.java.io.jdbc; + +import org.apache.flink.api.common.typeinfo.TypeInformation; +import org.apache.flink.api.common.typeinfo.Types; +import org.apache.flink.api.java.tuple.Tuple2; +import org.apache.flink.api.java.typeutils.RowTypeInfo; +import org.apache.flink.api.java.typeutils.TupleTypeInfo; +import org.apache.flink.streaming.api.datastream.DataStream; +import org.apache.flink.streaming.api.datastream.DataStreamSink; +import org.apache.flink.table.api.TableSchema; +import org.apache.flink.table.api.ValidationException; +import org.apache.flink.table.sinks.TableSink; +import org.apache.flink.table.sinks.UpsertStreamTableSink; +import org.apache.flink.table.utils.TableConnectorUtils; +import org.apache.flink.types.Row; + +import java.util.Arrays; + +import static org.apache.flink.api.java.io.jdbc.AbstractJDBCOutputFormat.DEFAULT_FLUSH_INTERVAL_MILLS; +import static org.apache.flink.api.java.io.jdbc.AbstractJDBCOutputFormat.DEFAULT_FLUSH_MAX_SIZE; +import static org.apache.flink.api.java.io.jdbc.JDBCUpsertOutputFormat.DEFAULT_MAX_RETRY_TIMES; + +/** + * An upsert {@link UpsertStreamTableSink} for JDBC. + */ +public class JDBCUpsertTableSink implements UpsertStreamTableSink<Row> { + + private final TableSchema schema; + private final JDBCOptions options; + private final int flushMaxSize; + private final long flushIntervalMills; + private final int maxRetryTime; + + private String[] keyFields; + private boolean isAppendOnly; + + private JDBCUpsertTableSink( + TableSchema schema, + JDBCOptions options, + int flushMaxSize, + long flushIntervalMills, + int maxRetryTime) { + this.schema = schema; + this.options = options; + this.flushMaxSize = flushMaxSize; + this.flushIntervalMills = flushIntervalMills; + this.maxRetryTime = maxRetryTime; + } + + private JDBCUpsertOutputFormat newFormat() { + if (!isAppendOnly && (keyFields == null || keyFields.length == 0)) { + throw new UnsupportedOperationException("JDBCUpsertTableSink can not support "); Review comment: can not support upsert without keys? ---------------------------------------------------------------- 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: [email protected] With regards, Apache Git Services
