dannycranmer commented on code in PR #1: URL: https://github.com/apache/flink-connector-dynamodb/pull/1#discussion_r1001103974
########## flink-connector-dynamodb/src/main/java/org/apache/flink/streaming/connectors/dynamodb/sink/DynamoDbSinkWriter.java: ########## @@ -0,0 +1,176 @@ +/* + * 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.streaming.connectors.dynamodb.sink; + +import org.apache.flink.annotation.Internal; +import org.apache.flink.api.connector.sink2.Sink.InitContext; +import org.apache.flink.connector.base.sink.writer.AsyncSinkWriter; +import org.apache.flink.connector.base.sink.writer.BufferedRequestState; +import org.apache.flink.connector.base.sink.writer.ElementConverter; +import org.apache.flink.metrics.Counter; +import org.apache.flink.metrics.groups.SinkWriterMetricGroup; +import org.apache.flink.streaming.connectors.dynamodb.util.AWSDynamoDbUtil; +import org.apache.flink.streaming.connectors.dynamodb.util.DynamoDbExceptionUtils; +import org.apache.flink.util.CollectionUtil; + +import org.apache.flink.shaded.guava30.com.google.common.collect.ImmutableMap; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import software.amazon.awssdk.services.dynamodb.DynamoDbAsyncClient; +import software.amazon.awssdk.services.dynamodb.model.BatchWriteItemRequest; +import software.amazon.awssdk.services.dynamodb.model.BatchWriteItemResponse; +import software.amazon.awssdk.services.dynamodb.model.WriteRequest; + +import java.nio.charset.StandardCharsets; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.List; +import java.util.Properties; +import java.util.concurrent.CompletableFuture; +import java.util.function.Consumer; + +/** + * Sink writer created by {@link DynamoDbSink} to write to DynamoDB. More details on the operation + * of this sink writer may be found in the doc for {@link DynamoDbSink}. More details on the + * internals of this sink writer may be found in {@link AsyncSinkWriter}. + * + * <p>The {@link DynamoDbAsyncClient} used here may be configured in the standard way for the AWS + * SDK 2.x. e.g. the provision of {@code AWS_REGION}, {@code AWS_ACCESS_KEY_ID} and {@code + * AWS_SECRET_ACCESS_KEY} through environment variables etc. + */ +@Internal +class DynamoDbSinkWriter<InputT> extends AsyncSinkWriter<InputT, WriteRequest> { Review Comment: @nirtsruya sorry I might not have explained my idea well. I actually meant that here we would use your new type: - `class DynamoDbSinkWriter<InputT> extends AsyncSinkWriter<InputT, DynamoDbWriteRequest> {` Now we can modify `DynamoDbWriteRequest` later to support the conditional fields for non-batch mode. Inside `submitRequestEntries` we would convert `DynamoDbWriteRequest` into `WriteRequest` for batch or `PutItemRequest` for non batch. We would need to also convert `WriteRequest` back into `DynamoDbWriteRequest` for failed records (need to check we have all the required info). There will be a slight performance hit when we retry, as records are converted multiple times. But this allows us to evolve the connector to support batch/non-batch without having to duplicate all the classes as you explained -- 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. To unsubscribe, e-mail: issues-unsubscr...@flink.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org