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 2022/11/06 22:10:21 UTC

[GitHub] [flink-connector-aws] hlteoh37 opened a new pull request, #15: [FLINK-29900][Connectors/DynamoDB] Implement Table API for DynamoDB sink

hlteoh37 opened a new pull request, #15:
URL: https://github.com/apache/flink-connector-aws/pull/15

   ## What is the purpose of the change
   - Implement Table API for DynamoDB sink
   
   ## Verifying this change
   
   
   ## Does this pull request potentially affect one of the following parts:
   * Dependencies (does it add or upgrade a dependency): yes, table API
   * The public API, i.e., is any changed class annotated with `@Public(Evolving)`: yes
   * The serializers: yes
   * The runtime per-record code paths (performance sensitive): yes
   * Anything that affects deployment or recovery: JobManager (and its components), Checkpointing, Kubernetes/Yarn, ZooKeeper: no
   
   ## Documentation
   * Does this pull request introduce a new feature? yes
   * If yes, how is the feature documented? 
   
   


-- 
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-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [flink-connector-aws] hlteoh37 commented on a diff in pull request #15: [FLINK-29900][Connectors/DynamoDB] Implement Table API for DynamoDB sink

Posted by GitBox <gi...@apache.org>.
hlteoh37 commented on code in PR #15:
URL: https://github.com/apache/flink-connector-aws/pull/15#discussion_r1024609732


##########
flink-connector-dynamodb/pom.xml:
##########
@@ -77,6 +77,22 @@ under the License.
 			<artifactId>dynamodb-enhanced</artifactId>
 		</dependency>
 
+		<!-- Table ecosystem -->
+		<dependency>
+			<groupId>org.apache.flink</groupId>
+			<artifactId>flink-table-api-java-bridge</artifactId>
+			<version>${flink.version}</version>
+			<scope>provided</scope>
+			<optional>true</optional>
+		</dependency>
+		<dependency>
+            <groupId>org.apache.flink</groupId>
+            <artifactId>flink-table-runtime</artifactId>
+            <version>${flink.version}</version>
+            <scope>provided</scope>
+            <optional>true</optional>
+        </dependency>

Review Comment:
   Addressed. Good spot



-- 
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-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [flink-connector-aws] dannycranmer commented on a diff in pull request #15: [FLINK-29900][Connectors/DynamoDB] Implement Table API for DynamoDB sink

Posted by GitBox <gi...@apache.org>.
dannycranmer commented on code in PR #15:
URL: https://github.com/apache/flink-connector-aws/pull/15#discussion_r1026589061


##########
flink-connector-dynamodb/src/main/java/org/apache/flink/connector/dynamodb/table/DynamoDbConfiguration.java:
##########
@@ -0,0 +1,44 @@
+/*
+ * 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.connector.dynamodb.table;
+
+import org.apache.flink.annotation.PublicEvolving;
+import org.apache.flink.configuration.ReadableConfig;
+
+import static org.apache.flink.connector.dynamodb.table.DynamoDbConnectorOptions.FAIL_ON_ERROR;
+import static org.apache.flink.connector.dynamodb.table.DynamoDbConnectorOptions.TABLE_NAME;
+
+/** DynamoDb specific configuration. */
+@PublicEvolving

Review Comment:
   Why is this not `@Internal`? I think the public contract is `DynamoDbConnectorOptions` and this is a helper class?



##########
flink-connector-dynamodb/src/main/java/org/apache/flink/connector/dynamodb/table/DynamoDbConnectorOptions.java:
##########
@@ -0,0 +1,46 @@
+/*
+ * 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.connector.dynamodb.table;
+
+import org.apache.flink.annotation.PublicEvolving;
+import org.apache.flink.configuration.ConfigOption;
+import org.apache.flink.configuration.ConfigOptions;
+import org.apache.flink.table.api.TableDescriptor;
+
+/** DynamoDb connector options. Made public for {@link TableDescriptor} to access it. */
+@PublicEvolving
+public class DynamoDbConnectorOptions {

Review Comment:
   How about the region, this is mandatory? 
   
   How about the "overwrite by partition key" as optional?



##########
flink-connector-dynamodb/src/main/java/org/apache/flink/connector/dynamodb/table/DynamoDbDynamicSinkFactory.java:
##########
@@ -0,0 +1,73 @@
+/*
+ * 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.connector.dynamodb.table;
+
+import org.apache.flink.annotation.Internal;
+import org.apache.flink.configuration.ConfigOption;
+import org.apache.flink.connector.base.table.AsyncDynamicTableSinkFactory;
+import org.apache.flink.table.catalog.ResolvedCatalogTable;
+import org.apache.flink.table.connector.sink.DynamicTableSink;
+import org.apache.flink.table.factories.FactoryUtil;
+
+import org.apache.flink.shaded.guava30.com.google.common.collect.ImmutableSet;
+
+import java.util.HashSet;
+import java.util.Properties;
+import java.util.Set;
+
+import static org.apache.flink.connector.dynamodb.table.DynamoDbConnectorOptions.TABLE_NAME;
+
+/** Factory for creating {@link DynamoDbDynamicSink}. */
+@Internal
+public class DynamoDbDynamicSinkFactory extends AsyncDynamicTableSinkFactory {
+
+    public static final String FACTORY_IDENTIFIER = "dynamodb";
+
+    @Override
+    public DynamicTableSink createDynamicTableSink(Context context) {
+        FactoryUtil.TableFactoryHelper factoryHelper =
+                FactoryUtil.createTableFactoryHelper(this, context);
+        ResolvedCatalogTable catalogTable = context.getCatalogTable();
+
+        FactoryUtil.validateFactoryOptions(this, factoryHelper.getOptions());
+
+        DynamoDbConfiguration dynamoDbConfiguration =
+                new DynamoDbConfiguration(factoryHelper.getOptions());
+
+        Properties dynamoDbClientProperties = new Properties();
+        dynamoDbClientProperties.putAll(catalogTable.getOptions());
+        return DynamoDbDynamicSink.builder()
+                .setTableName(dynamoDbConfiguration.getTableName())
+                .setFailOnError(dynamoDbConfiguration.getFailOnError())
+                .setPhysicalDataType(catalogTable.getResolvedSchema().toPhysicalRowDataType())
+                .setOverwriteByPartitionKeys(new HashSet<>(catalogTable.getPartitionKeys()))
+                .setDynamoDbClientProperties(dynamoDbClientProperties)
+                .build();
+    }
+
+    @Override
+    public String factoryIdentifier() {
+        return FACTORY_IDENTIFIER;
+    }
+
+    @Override
+    public Set<ConfigOption<?>> requiredOptions() {
+        return ImmutableSet.of(TABLE_NAME);

Review Comment:
   Region? Or are we keeping optional incase an endpoint URL is supplied? This is different to KDS https://github.com/apache/flink/blob/master/flink-connectors/flink-connector-aws-kinesis-streams/src/main/java/org/apache/flink/connector/kinesis/table/KinesisDynamicTableSinkFactory.java#L98



##########
flink-connector-dynamodb/src/main/java/org/apache/flink/connector/dynamodb/table/DynamoDbDynamicSink.java:
##########
@@ -0,0 +1,181 @@
+/*
+ * 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.connector.dynamodb.table;
+
+import org.apache.flink.annotation.Internal;
+import org.apache.flink.connector.base.table.sink.AsyncDynamicTableSink;
+import org.apache.flink.connector.base.table.sink.AsyncDynamicTableSinkBuilder;
+import org.apache.flink.connector.dynamodb.sink.DynamoDbSink;
+import org.apache.flink.connector.dynamodb.sink.DynamoDbSinkBuilder;
+import org.apache.flink.connector.dynamodb.sink.DynamoDbWriteRequest;
+import org.apache.flink.table.connector.ChangelogMode;
+import org.apache.flink.table.connector.sink.DynamicTableSink;
+import org.apache.flink.table.connector.sink.SinkV2Provider;
+import org.apache.flink.table.connector.sink.abilities.SupportsPartitioning;
+import org.apache.flink.table.data.RowData;
+import org.apache.flink.table.types.DataType;
+
+import javax.annotation.Nullable;
+
+import java.util.ArrayList;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Set;
+
+/**
+ * A {@link DynamicTableSink} that describes how to create a {@link DynamoDbSink} from a logical
+ * description.
+ */
+@Internal
+public class DynamoDbDynamicSink extends AsyncDynamicTableSink<DynamoDbWriteRequest>
+        implements SupportsPartitioning {
+
+    private final String tableName;
+    private final boolean failOnError;
+    private final Properties dynamoDbClientProperties;
+    private final DataType physicalDataType;
+    private final Set<String> overwriteByPartitionKeys;
+
+    protected DynamoDbDynamicSink(
+            @Nullable Integer maxBatchSize,
+            @Nullable Integer maxInFlightRequests,
+            @Nullable Integer maxBufferedRequests,
+            @Nullable Long maxBufferSizeInBytes,
+            @Nullable Long maxTimeInBufferMS,
+            String tableName,
+            boolean failOnError,
+            Properties dynamoDbClientProperties,
+            DataType physicalDataType,
+            Set<String> overwriteByPartitionKeys) {
+        super(
+                maxBatchSize,
+                maxInFlightRequests,
+                maxBufferedRequests,
+                maxBufferSizeInBytes,
+                maxTimeInBufferMS);
+        this.tableName = tableName;
+        this.failOnError = failOnError;
+        this.dynamoDbClientProperties = dynamoDbClientProperties;
+        this.physicalDataType = physicalDataType;
+        this.overwriteByPartitionKeys = overwriteByPartitionKeys;
+    }
+
+    @Override
+    public ChangelogMode getChangelogMode(ChangelogMode changelogMode) {
+        return ChangelogMode.upsert();
+    }
+
+    @Override
+    public SinkRuntimeProvider getSinkRuntimeProvider(Context context) {
+        DynamoDbSinkBuilder<RowData> builder =
+                DynamoDbSink.<RowData>builder()
+                        .setTableName(tableName)
+                        .setFailOnError(failOnError)
+                        .setOverwriteByPartitionKeys(new ArrayList<>(overwriteByPartitionKeys))
+                        .setDynamoDbProperties(dynamoDbClientProperties)
+                        .setElementConverter(new RowDataElementConverter(physicalDataType));
+
+        addAsyncOptionsToSinkBuilder(builder);
+
+        return SinkV2Provider.of(builder.build());
+    }
+
+    @Override
+    public DynamicTableSink copy() {
+        return new DynamoDbDynamicSink(
+                maxBatchSize,
+                maxInFlightRequests,
+                maxBufferedRequests,
+                maxBufferSizeInBytes,
+                maxTimeInBufferMS,
+                tableName,
+                failOnError,
+                dynamoDbClientProperties,
+                physicalDataType,
+                overwriteByPartitionKeys);
+    }
+
+    @Override
+    public String asSummaryString() {
+        return "DynamoDB";
+    }
+
+    @Override
+    public void applyStaticPartition(Map<String, String> partitions) {

Review Comment:
   When is this called vs `overwriteByPartitionKeys` passed via the builder?



##########
flink-connector-dynamodb/src/main/java/org/apache/flink/connector/dynamodb/table/converter/ArrayAttributeConverterProvider.java:
##########
@@ -0,0 +1,80 @@
+/*
+ * 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.connector.dynamodb.table.converter;
+
+import org.apache.flink.annotation.Internal;
+
+import software.amazon.awssdk.enhanced.dynamodb.AttributeConverter;
+import software.amazon.awssdk.enhanced.dynamodb.AttributeConverterProvider;
+import software.amazon.awssdk.enhanced.dynamodb.EnhancedType;
+
+import java.math.BigDecimal;
+import java.time.Instant;
+import java.time.LocalDate;
+import java.time.LocalDateTime;
+import java.time.LocalTime;
+
+/** Attribute converter provider for String Array. */
+@Internal
+public class ArrayAttributeConverterProvider implements AttributeConverterProvider {
+
+    private static final AttributeConverterProvider defaultAttributeConverterProvider =
+            AttributeConverterProvider.defaultProvider();
+
+    @Override
+    public <T> AttributeConverter<T> converterFor(EnhancedType<T> enhancedType) {

Review Comment:
   How do you propose we keep this method in sync between Flink types and `EnhancedType` https://github.com/aws/aws-sdk-java-v2/blob/master/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/EnhancedType.java ?



##########
flink-connector-dynamodb/src/main/java/org/apache/flink/connector/dynamodb/table/converter/ArrayAttributeConverterProvider.java:
##########
@@ -0,0 +1,80 @@
+/*
+ * 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.connector.dynamodb.table.converter;
+
+import org.apache.flink.annotation.Internal;
+
+import software.amazon.awssdk.enhanced.dynamodb.AttributeConverter;
+import software.amazon.awssdk.enhanced.dynamodb.AttributeConverterProvider;
+import software.amazon.awssdk.enhanced.dynamodb.EnhancedType;
+
+import java.math.BigDecimal;
+import java.time.Instant;
+import java.time.LocalDate;
+import java.time.LocalDateTime;
+import java.time.LocalTime;
+
+/** Attribute converter provider for String Array. */
+@Internal
+public class ArrayAttributeConverterProvider implements AttributeConverterProvider {
+
+    private static final AttributeConverterProvider defaultAttributeConverterProvider =
+            AttributeConverterProvider.defaultProvider();
+
+    @Override
+    public <T> AttributeConverter<T> converterFor(EnhancedType<T> enhancedType) {
+        if (enhancedType.equals(EnhancedType.of(String[].class))) {
+            return (AttributeConverter<T>) getArrayAttributeConverter(String.class, enhancedType);
+        } else if (enhancedType.equals(EnhancedType.of(Boolean[].class))) {
+            return (AttributeConverter<T>) getArrayAttributeConverter(Boolean.class, enhancedType);
+        } else if (enhancedType.equals(EnhancedType.of(BigDecimal[].class))) {
+            return (AttributeConverter<T>)
+                    getArrayAttributeConverter(BigDecimal.class, enhancedType);
+        } else if (enhancedType.equals(EnhancedType.of(Byte[].class))) {
+            return (AttributeConverter<T>) getArrayAttributeConverter(Byte.class, enhancedType);
+        } else if (enhancedType.equals(EnhancedType.of(Short[].class))) {
+            return (AttributeConverter<T>) getArrayAttributeConverter(Short.class, enhancedType);
+        } else if (enhancedType.equals(EnhancedType.of(Integer[].class))) {
+            return (AttributeConverter<T>) getArrayAttributeConverter(Integer.class, enhancedType);
+        } else if (enhancedType.equals(EnhancedType.of(Long[].class))) {
+            return (AttributeConverter<T>) getArrayAttributeConverter(Long.class, enhancedType);
+        } else if (enhancedType.equals(EnhancedType.of(Float[].class))) {
+            return (AttributeConverter<T>) getArrayAttributeConverter(Float.class, enhancedType);
+        } else if (enhancedType.equals(EnhancedType.of(LocalDate[].class))) {
+            return (AttributeConverter<T>)
+                    getArrayAttributeConverter(LocalDate.class, enhancedType);
+        } else if (enhancedType.equals(EnhancedType.of(LocalTime[].class))) {
+            return (AttributeConverter<T>)
+                    getArrayAttributeConverter(LocalTime.class, enhancedType);
+        } else if (enhancedType.equals(EnhancedType.of(LocalDateTime[].class))) {
+            return (AttributeConverter<T>)
+                    getArrayAttributeConverter(LocalDateTime.class, enhancedType);
+        } else if (enhancedType.equals(EnhancedType.of(Instant[].class))) {
+            return (AttributeConverter<T>) getArrayAttributeConverter(Instant.class, enhancedType);
+        }
+        return null;

Review Comment:
   What happens in this failure mode? Should we throw an exception here?
   
   As discussed, you missed `Double`



##########
flink-connector-dynamodb/src/main/java/org/apache/flink/connector/dynamodb/table/RowDataToAttributeValueConverter.java:
##########
@@ -0,0 +1,109 @@
+/*
+ * 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.connector.dynamodb.table;
+
+import org.apache.flink.annotation.Internal;
+import org.apache.flink.connector.dynamodb.table.converter.ArrayAttributeConverterProvider;
+import org.apache.flink.table.api.DataTypes;
+import org.apache.flink.table.data.RowData;
+import org.apache.flink.table.data.conversion.DataStructureConverters;
+import org.apache.flink.table.types.DataType;
+import org.apache.flink.table.types.KeyValueDataType;
+
+import software.amazon.awssdk.enhanced.dynamodb.AttributeConverterProvider;
+import software.amazon.awssdk.enhanced.dynamodb.EnhancedType;
+import software.amazon.awssdk.enhanced.dynamodb.TableSchema;
+import software.amazon.awssdk.enhanced.dynamodb.mapper.StaticTableSchema;
+import software.amazon.awssdk.services.dynamodb.model.AttributeValue;
+
+import java.io.Serializable;
+import java.util.List;
+import java.util.Map;
+
+import static org.apache.flink.table.data.RowData.createFieldGetter;
+
+/** Converts from Flink Table API internal type of {@link RowData} to {@link AttributeValue}. */
+@Internal
+public class RowDataToAttributeValueConverter implements Serializable {

Review Comment:
   nit: You _could_ create this class lazily in `RowDataElementConverter` so this does not need to be serialised/serializable. 



##########
flink-connector-dynamodb/src/main/java/org/apache/flink/connector/dynamodb/table/DynamoDbConnectorOptions.java:
##########
@@ -0,0 +1,46 @@
+/*
+ * 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.connector.dynamodb.table;
+
+import org.apache.flink.annotation.PublicEvolving;
+import org.apache.flink.configuration.ConfigOption;
+import org.apache.flink.configuration.ConfigOptions;
+import org.apache.flink.table.api.TableDescriptor;
+
+/** DynamoDb connector options. Made public for {@link TableDescriptor} to access it. */
+@PublicEvolving
+public class DynamoDbConnectorOptions {
+
+    private DynamoDbConnectorOptions() {
+        // private constructor to prevent initialization of static class
+    }

Review Comment:
   nit: Constructors should go below fields



##########
flink-connector-dynamodb/src/main/java/org/apache/flink/connector/dynamodb/table/RowDataElementConverter.java:
##########
@@ -0,0 +1,68 @@
+/*
+ * 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.connector.dynamodb.table;
+
+import org.apache.flink.annotation.Internal;
+import org.apache.flink.api.connector.sink2.SinkWriter;
+import org.apache.flink.connector.base.sink.writer.ElementConverter;
+import org.apache.flink.connector.dynamodb.sink.DynamoDbWriteRequest;
+import org.apache.flink.connector.dynamodb.sink.DynamoDbWriteRequestType;
+import org.apache.flink.table.api.TableException;
+import org.apache.flink.table.data.RowData;
+import org.apache.flink.table.types.DataType;
+
+/**
+ * Implementation of an {@link ElementConverter} for the DynamoDb Table sink. The element converter
+ * maps the Flink internal type of {@link RowData} to a {@link DynamoDbWriteRequest} to be used by
+ * the DynamoDb sink.
+ */
+@Internal
+public class RowDataElementConverter implements ElementConverter<RowData, DynamoDbWriteRequest> {
+
+    private final DataType physicalDataType;
+    private final RowDataToAttributeValueConverter rowDataToAttributeValueConverter;
+
+    public RowDataElementConverter(DataType physicalDataType) {
+        this.physicalDataType = physicalDataType;
+        this.rowDataToAttributeValueConverter =
+                new RowDataToAttributeValueConverter(physicalDataType);
+    }

Review Comment:
   For `DynamoDbBeanElementConverter` I create the table schema here to fail fast. Currently you do not create the schema until consuming data, what happens if table invalid?  https://github.com/apache/flink-connector-aws/blob/main/flink-connector-dynamodb/src/main/java/org/apache/flink/connector/dynamodb/sink/DynamoDbBeanElementConverter.java#L52



##########
flink-connector-dynamodb/src/main/java/org/apache/flink/connector/dynamodb/table/RowDataToAttributeValueConverter.java:
##########
@@ -0,0 +1,109 @@
+/*
+ * 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.connector.dynamodb.table;
+
+import org.apache.flink.annotation.Internal;
+import org.apache.flink.connector.dynamodb.table.converter.ArrayAttributeConverterProvider;
+import org.apache.flink.table.api.DataTypes;
+import org.apache.flink.table.data.RowData;
+import org.apache.flink.table.data.conversion.DataStructureConverters;
+import org.apache.flink.table.types.DataType;
+import org.apache.flink.table.types.KeyValueDataType;
+
+import software.amazon.awssdk.enhanced.dynamodb.AttributeConverterProvider;
+import software.amazon.awssdk.enhanced.dynamodb.EnhancedType;
+import software.amazon.awssdk.enhanced.dynamodb.TableSchema;
+import software.amazon.awssdk.enhanced.dynamodb.mapper.StaticTableSchema;
+import software.amazon.awssdk.services.dynamodb.model.AttributeValue;
+
+import java.io.Serializable;
+import java.util.List;
+import java.util.Map;
+
+import static org.apache.flink.table.data.RowData.createFieldGetter;
+
+/** Converts from Flink Table API internal type of {@link RowData} to {@link AttributeValue}. */
+@Internal
+public class RowDataToAttributeValueConverter implements Serializable {
+    private static final long serialVersionUID = 1L;
+
+    private final DataType physicalDataType;
+    private transient TableSchema<RowData> tableSchema;
+
+    public RowDataToAttributeValueConverter(DataType physicalDataType) {
+        this.physicalDataType = physicalDataType;
+        this.tableSchema = createTableSchema();
+    }
+
+    public Map<String, AttributeValue> convertRowData(RowData row) {
+        if (tableSchema == null) {
+            tableSchema = createTableSchema();
+        }
+        return tableSchema.itemToMap(row, false);
+    }
+
+    private StaticTableSchema<RowData> createTableSchema() {

Review Comment:
   This is neat!



-- 
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-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [flink-connector-aws] dannycranmer merged pull request #15: [FLINK-29900][Connectors/DynamoDB] Implement Table API for DynamoDB sink

Posted by GitBox <gi...@apache.org>.
dannycranmer merged PR #15:
URL: https://github.com/apache/flink-connector-aws/pull/15


-- 
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-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [flink-connector-aws] dannycranmer commented on a diff in pull request #15: [FLINK-29900][Connectors/DynamoDB] Implement Table API for DynamoDB sink

Posted by GitBox <gi...@apache.org>.
dannycranmer commented on code in PR #15:
URL: https://github.com/apache/flink-connector-aws/pull/15#discussion_r1028269038


##########
flink-connector-dynamodb/src/test/java/org/apache/flink/connector/dynamodb/sink/examples/example_dynamodb.sql:
##########
@@ -0,0 +1,50 @@
+

Review Comment:
   Missing copyright header



##########
flink-connector-dynamodb/src/test/java/org/apache/flink/connector/dynamodb/table/DynamoDbDynamicSinkFactoryTest.java:
##########
@@ -0,0 +1,267 @@
+package org.apache.flink.connector.dynamodb.table;
+
+import org.apache.flink.api.connector.sink2.Sink;
+import org.apache.flink.connector.dynamodb.sink.DynamoDbSink;
+import org.apache.flink.table.api.DataTypes;
+import org.apache.flink.table.api.ValidationException;
+import org.apache.flink.table.catalog.Column;
+import org.apache.flink.table.catalog.ResolvedSchema;
+import org.apache.flink.table.connector.ChangelogMode;
+import org.apache.flink.table.connector.sink.SinkV2Provider;
+import org.apache.flink.table.data.RowData;
+import org.apache.flink.table.factories.TableOptionsBuilder;
+import org.apache.flink.table.factories.TestFormatFactory;
+import org.apache.flink.table.runtime.connector.sink.SinkRuntimeProviderContext;
+
+import org.apache.flink.shaded.guava30.com.google.common.collect.ImmutableMap;
+
+import org.junit.jupiter.api.Test;
+
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Set;
+
+import static org.apache.flink.connector.base.table.AsyncSinkConnectorOptions.FLUSH_BUFFER_SIZE;
+import static org.apache.flink.connector.base.table.AsyncSinkConnectorOptions.FLUSH_BUFFER_TIMEOUT;
+import static org.apache.flink.connector.base.table.AsyncSinkConnectorOptions.MAX_BATCH_SIZE;
+import static org.apache.flink.connector.base.table.AsyncSinkConnectorOptions.MAX_BUFFERED_REQUESTS;
+import static org.apache.flink.connector.base.table.AsyncSinkConnectorOptions.MAX_IN_FLIGHT_REQUESTS;
+import static org.apache.flink.connector.dynamodb.table.DynamoDbConnectorOptions.FAIL_ON_ERROR;
+import static org.apache.flink.connector.dynamodb.table.DynamoDbConnectorOptions.TABLE_NAME;
+import static org.apache.flink.table.factories.utils.FactoryMocks.createTableSink;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
+
+/** Test for {@link DynamoDbDynamicSink} created by {@link DynamoDbDynamicSinkFactory}. */
+public class DynamoDbDynamicSinkFactoryTest {
+
+    private static final String DYNAMO_DB_TABLE_NAME = "TestDynamoDBTable";
+
+    @Test
+    void testGoodPartitionedTableSink() {
+        ResolvedSchema sinkSchema =
+                ResolvedSchema.of(
+                        Column.physical("partition_key", DataTypes.STRING()),
+                        Column.physical("sort_key", DataTypes.BIGINT()),
+                        Column.physical("payload", DataTypes.STRING()),
+                        Column.physical("some_char_array", DataTypes.ARRAY(DataTypes.CHAR(1))),
+                        Column.physical(
+                                "some_varchar_array", DataTypes.ARRAY(DataTypes.VARCHAR(1))),
+                        Column.physical("some_string_array", DataTypes.ARRAY(DataTypes.STRING())),
+                        Column.physical("some_boolean_array", DataTypes.ARRAY(DataTypes.BOOLEAN())),
+                        Column.physical(
+                                "some_decimal_array", DataTypes.ARRAY(DataTypes.DECIMAL(1, 1))),
+                        Column.physical("some_tinyint_array", DataTypes.ARRAY(DataTypes.TINYINT())),
+                        Column.physical(
+                                "some_smallint_array", DataTypes.ARRAY(DataTypes.SMALLINT())),
+                        Column.physical("some_int_array", DataTypes.ARRAY(DataTypes.INT())),
+                        Column.physical("some_bigint_array", DataTypes.ARRAY(DataTypes.BIGINT())),
+                        Column.physical("some_float_array", DataTypes.ARRAY(DataTypes.FLOAT())),
+                        Column.physical("some_date_array", DataTypes.ARRAY(DataTypes.DATE())),
+                        Column.physical("some_time_array", DataTypes.ARRAY(DataTypes.TIME())),
+                        Column.physical(
+                                "some_timestamp_array", DataTypes.ARRAY(DataTypes.TIMESTAMP())),
+                        Column.physical(
+                                "some_timestamp_ltz_array",
+                                DataTypes.ARRAY(DataTypes.TIMESTAMP_LTZ())),
+                        Column.physical(
+                                "some_map", DataTypes.MAP(DataTypes.STRING(), DataTypes.BIGINT())));
+        Map<String, String> sinkOptions = defaultSinkOptions().build();
+        List<String> partitionKeys = Collections.singletonList("partition_key");
+
+        // Construct actual sink
+        DynamoDbDynamicSink actualSink =
+                (DynamoDbDynamicSink) createTableSink(sinkSchema, partitionKeys, sinkOptions);
+
+        // Construct expected sink
+        Properties dynamoDbClientProperties = new Properties();
+        dynamoDbClientProperties.putAll(sinkOptions);
+        DynamoDbDynamicSink expectedSink =
+                (DynamoDbDynamicSink)
+                        DynamoDbDynamicSink.builder()
+                                .setTableName(DYNAMO_DB_TABLE_NAME)
+                                .setOverwriteByPartitionKeys(new HashSet<>(partitionKeys))
+                                .setDynamoDbClientProperties(dynamoDbClientProperties)
+                                .setPhysicalDataType(sinkSchema.toPhysicalRowDataType())
+                                .build();
+
+        assertThat(actualSink).usingRecursiveComparison().isEqualTo(expectedSink);
+        assertThat(actualSink.getChangelogMode(ChangelogMode.insertOnly()))
+                .isEqualTo(ChangelogMode.upsert());

Review Comment:
   ok, but what I was hinting at is that if we pass in `insertOnly`, maybe we should throw an error if we receive any delete requests. Scope creep alert



##########
flink-connector-dynamodb/src/test/java/org/apache/flink/connector/dynamodb/sink/examples/example_dynamodb_static_partitions.sql:
##########
@@ -0,0 +1,50 @@
+

Review Comment:
   Missing copyright header



##########
flink-sql-connector-dynamodb/pom.xml:
##########
@@ -77,12 +77,16 @@ under the License.
 									<include>org.apache.httpcomponents:*</include>
 									<include>io.netty:*</include>
 									<include>commons-logging:commons-logging</include>
+									<include>commons-codec:commons-codec</include>
 								</includes>
 							</artifactSet>
 							<relocations>
 								<relocation>
 									<pattern>software.amazon</pattern>
 									<shadedPattern>org.apache.flink.connector.dynamodb.shaded.software.amazon</shadedPattern>
+									<excludes>
+										<exclude>software.amazon.awssdk.enhanced.**</exclude>
+									</excludes>

Review Comment:
   Ah, we had this issue for EFO too. I added a custom `execution.interceptors` for this https://github.com/apache/flink/commit/a330d4331b2af710b6531c55f427c4b14f037d78



-- 
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-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [flink-connector-aws] hlteoh37 commented on a diff in pull request #15: [FLINK-29900][Connectors/DynamoDB] Implement Table API for DynamoDB sink

Posted by GitBox <gi...@apache.org>.
hlteoh37 commented on code in PR #15:
URL: https://github.com/apache/flink-connector-aws/pull/15#discussion_r1026723923


##########
flink-connector-dynamodb/src/test/java/org/apache/flink/connector/dynamodb/table/DynamoDbDynamicSinkFactoryTest.java:
##########
@@ -0,0 +1,267 @@
+package org.apache.flink.connector.dynamodb.table;
+
+import org.apache.flink.api.connector.sink2.Sink;
+import org.apache.flink.connector.dynamodb.sink.DynamoDbSink;
+import org.apache.flink.table.api.DataTypes;
+import org.apache.flink.table.api.ValidationException;
+import org.apache.flink.table.catalog.Column;
+import org.apache.flink.table.catalog.ResolvedSchema;
+import org.apache.flink.table.connector.ChangelogMode;
+import org.apache.flink.table.connector.sink.SinkV2Provider;
+import org.apache.flink.table.data.RowData;
+import org.apache.flink.table.factories.TableOptionsBuilder;
+import org.apache.flink.table.factories.TestFormatFactory;
+import org.apache.flink.table.runtime.connector.sink.SinkRuntimeProviderContext;
+
+import org.apache.flink.shaded.guava30.com.google.common.collect.ImmutableMap;
+
+import org.junit.jupiter.api.Test;
+
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Set;
+
+import static org.apache.flink.connector.base.table.AsyncSinkConnectorOptions.FLUSH_BUFFER_SIZE;
+import static org.apache.flink.connector.base.table.AsyncSinkConnectorOptions.FLUSH_BUFFER_TIMEOUT;
+import static org.apache.flink.connector.base.table.AsyncSinkConnectorOptions.MAX_BATCH_SIZE;
+import static org.apache.flink.connector.base.table.AsyncSinkConnectorOptions.MAX_BUFFERED_REQUESTS;
+import static org.apache.flink.connector.base.table.AsyncSinkConnectorOptions.MAX_IN_FLIGHT_REQUESTS;
+import static org.apache.flink.connector.dynamodb.table.DynamoDbConnectorOptions.FAIL_ON_ERROR;
+import static org.apache.flink.connector.dynamodb.table.DynamoDbConnectorOptions.TABLE_NAME;
+import static org.apache.flink.table.factories.utils.FactoryMocks.createTableSink;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
+
+/** Test for {@link DynamoDbDynamicSink} created by {@link DynamoDbDynamicSinkFactory}. */
+public class DynamoDbDynamicSinkFactoryTest {
+
+    private static final String DYNAMO_DB_TABLE_NAME = "TestDynamoDBTable";
+
+    @Test
+    void testGoodPartitionedTableSink() {
+        ResolvedSchema sinkSchema =
+                ResolvedSchema.of(
+                        Column.physical("partition_key", DataTypes.STRING()),
+                        Column.physical("sort_key", DataTypes.BIGINT()),
+                        Column.physical("payload", DataTypes.STRING()),
+                        Column.physical("some_char_array", DataTypes.ARRAY(DataTypes.CHAR(1))),
+                        Column.physical(
+                                "some_varchar_array", DataTypes.ARRAY(DataTypes.VARCHAR(1))),
+                        Column.physical("some_string_array", DataTypes.ARRAY(DataTypes.STRING())),
+                        Column.physical("some_boolean_array", DataTypes.ARRAY(DataTypes.BOOLEAN())),
+                        Column.physical(
+                                "some_decimal_array", DataTypes.ARRAY(DataTypes.DECIMAL(1, 1))),
+                        Column.physical("some_tinyint_array", DataTypes.ARRAY(DataTypes.TINYINT())),
+                        Column.physical(
+                                "some_smallint_array", DataTypes.ARRAY(DataTypes.SMALLINT())),
+                        Column.physical("some_int_array", DataTypes.ARRAY(DataTypes.INT())),
+                        Column.physical("some_bigint_array", DataTypes.ARRAY(DataTypes.BIGINT())),
+                        Column.physical("some_float_array", DataTypes.ARRAY(DataTypes.FLOAT())),
+                        Column.physical("some_date_array", DataTypes.ARRAY(DataTypes.DATE())),
+                        Column.physical("some_time_array", DataTypes.ARRAY(DataTypes.TIME())),
+                        Column.physical(
+                                "some_timestamp_array", DataTypes.ARRAY(DataTypes.TIMESTAMP())),
+                        Column.physical(
+                                "some_timestamp_ltz_array",
+                                DataTypes.ARRAY(DataTypes.TIMESTAMP_LTZ())),
+                        Column.physical(
+                                "some_map", DataTypes.MAP(DataTypes.STRING(), DataTypes.BIGINT())));

Review Comment:
   ok done



-- 
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-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [flink-connector-aws] hlteoh37 commented on a diff in pull request #15: [FLINK-29900][Connectors/DynamoDB] Implement Table API for DynamoDB sink

Posted by GitBox <gi...@apache.org>.
hlteoh37 commented on code in PR #15:
URL: https://github.com/apache/flink-connector-aws/pull/15#discussion_r1026733354


##########
flink-connector-dynamodb/src/test/java/org/apache/flink/connector/dynamodb/table/DynamoDbDynamicSinkFactoryTest.java:
##########
@@ -0,0 +1,267 @@
+package org.apache.flink.connector.dynamodb.table;

Review Comment:
   added



-- 
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-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [flink-connector-aws] hlteoh37 commented on a diff in pull request #15: [FLINK-29900][Connectors/DynamoDB] Implement Table API for DynamoDB sink

Posted by GitBox <gi...@apache.org>.
hlteoh37 commented on code in PR #15:
URL: https://github.com/apache/flink-connector-aws/pull/15#discussion_r1024629827


##########
flink-connector-dynamodb/src/main/java/org/apache/flink/connector/dynamodb/table/RowDataElementConverter.java:
##########
@@ -0,0 +1,50 @@
+package org.apache.flink.connector.dynamodb.table;
+
+import org.apache.flink.api.connector.sink2.SinkWriter;
+import org.apache.flink.connector.base.sink.writer.ElementConverter;
+import org.apache.flink.connector.dynamodb.sink.DynamoDbWriteRequest;
+import org.apache.flink.connector.dynamodb.sink.DynamoDbWriteRequestType;
+import org.apache.flink.table.api.TableException;
+import org.apache.flink.table.data.RowData;
+import org.apache.flink.table.types.DataType;
+
+/** Implementation of an {@link ElementConverter} specific for DynamoDb sink. */

Review Comment:
   done



##########
flink-connector-dynamodb/src/main/java/org/apache/flink/connector/dynamodb/table/DynamoDbDynamicSink.java:
##########
@@ -0,0 +1,198 @@
+package org.apache.flink.connector.dynamodb.table;
+
+import org.apache.flink.annotation.Internal;
+import org.apache.flink.connector.base.table.sink.AsyncDynamicTableSink;
+import org.apache.flink.connector.base.table.sink.AsyncDynamicTableSinkBuilder;
+import org.apache.flink.connector.dynamodb.sink.DynamoDbSink;
+import org.apache.flink.connector.dynamodb.sink.DynamoDbSinkBuilder;
+import org.apache.flink.connector.dynamodb.sink.DynamoDbWriteRequest;
+import org.apache.flink.table.connector.ChangelogMode;
+import org.apache.flink.table.connector.sink.DynamicTableSink;
+import org.apache.flink.table.connector.sink.SinkV2Provider;
+import org.apache.flink.table.connector.sink.abilities.SupportsPartitioning;
+import org.apache.flink.table.data.RowData;
+import org.apache.flink.table.types.DataType;
+
+import javax.annotation.Nullable;
+
+import java.util.ArrayList;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Properties;
+import java.util.Set;
+
+/**
+ * A {@link DynamicTableSink} that describes how to create a {@link DynamoDbSink} from a logical
+ * description.
+ */
+@Internal
+public class DynamoDbDynamicSink extends AsyncDynamicTableSink<DynamoDbWriteRequest>
+        implements SupportsPartitioning {
+
+    private final String destinationTableName;
+    private final boolean failOnError;
+    private final Properties dynamoDbClientProperties;
+    private final DataType physicalDataType;
+    private final Set<String> overwriteByPartitionKeys;
+
+    protected DynamoDbDynamicSink(
+            @Nullable Integer maxBatchSize,
+            @Nullable Integer maxInFlightRequests,
+            @Nullable Integer maxBufferedRequests,
+            @Nullable Long maxBufferSizeInBytes,
+            @Nullable Long maxTimeInBufferMS,
+            String destinationTableName,
+            boolean failOnError,
+            Properties dynamoDbClientProperties,
+            DataType physicalDataType,
+            Set<String> overwriteByPartitionKeys) {
+        super(
+                maxBatchSize,
+                maxInFlightRequests,
+                maxBufferedRequests,
+                maxBufferSizeInBytes,
+                maxTimeInBufferMS);
+        this.destinationTableName = destinationTableName;
+        this.failOnError = failOnError;
+        this.dynamoDbClientProperties = dynamoDbClientProperties;
+        this.physicalDataType = physicalDataType;
+        this.overwriteByPartitionKeys = overwriteByPartitionKeys;
+    }
+
+    @Override
+    public ChangelogMode getChangelogMode(ChangelogMode changelogMode) {
+        // TODO: We can support consuming from CDC streams here
+        return ChangelogMode.insertOnly();
+    }
+
+    @Override
+    public SinkRuntimeProvider getSinkRuntimeProvider(Context context) {
+        DynamoDbSinkBuilder<RowData> builder =
+                DynamoDbSink.<RowData>builder()
+                        .setDestinationTableName(destinationTableName)
+                        .setFailOnError(failOnError)
+                        .setOverwriteByPartitionKeys(new ArrayList<>(overwriteByPartitionKeys))
+                        .setDynamoDbProperties(dynamoDbClientProperties)
+                        .setElementConverter(new RowDataElementConverter(physicalDataType));
+
+        addAsyncOptionsToSinkBuilder(builder);
+
+        // TODO: check if parallelism needed here
+        return SinkV2Provider.of(builder.build());
+    }
+
+    @Override
+    public DynamicTableSink copy() {
+        return new DynamoDbDynamicSink(
+                maxBatchSize,
+                maxInFlightRequests,
+                maxBufferedRequests,
+                maxBufferSizeInBytes,
+                maxTimeInBufferMS,
+                destinationTableName,
+                failOnError,
+                dynamoDbClientProperties,
+                physicalDataType,
+                overwriteByPartitionKeys);
+    }
+
+    @Override
+    public String asSummaryString() {
+        // TODO: check when this is called/returned
+        return "DynamoDB";
+    }
+
+    @Override
+    public void applyStaticPartition(Map<String, String> partitions) {
+        this.overwriteByPartitionKeys.addAll(partitions.keySet());
+    }
+
+    public static DynamoDbDynamicTableSinkBuilder builder() {
+        return new DynamoDbDynamicTableSinkBuilder();
+    }
+
+    @Override
+    public boolean equals(Object o) {
+        if (this == o) {
+            return true;
+        }
+        if (o == null || getClass() != o.getClass()) {
+            return false;
+        }
+        if (!super.equals(o)) {
+            return false;
+        }
+        DynamoDbDynamicSink that = (DynamoDbDynamicSink) o;
+        return failOnError == that.failOnError
+                && Objects.equals(destinationTableName, that.destinationTableName)
+                && Objects.equals(dynamoDbClientProperties, that.dynamoDbClientProperties)
+                && Objects.equals(physicalDataType, that.physicalDataType)
+                && Objects.equals(overwriteByPartitionKeys, that.overwriteByPartitionKeys);
+    }
+
+    @Override
+    public int hashCode() {
+        return Objects.hash(
+                super.hashCode(),
+                destinationTableName,
+                failOnError,
+                dynamoDbClientProperties,
+                physicalDataType,
+                overwriteByPartitionKeys);
+    }

Review Comment:
   Yep, these were only used for tests. Removed and improved tests.



##########
flink-connector-dynamodb/src/main/java/org/apache/flink/connector/dynamodb/table/RowDataElementConverter.java:
##########
@@ -0,0 +1,50 @@
+package org.apache.flink.connector.dynamodb.table;
+
+import org.apache.flink.api.connector.sink2.SinkWriter;
+import org.apache.flink.connector.base.sink.writer.ElementConverter;
+import org.apache.flink.connector.dynamodb.sink.DynamoDbWriteRequest;
+import org.apache.flink.connector.dynamodb.sink.DynamoDbWriteRequestType;
+import org.apache.flink.table.api.TableException;
+import org.apache.flink.table.data.RowData;
+import org.apache.flink.table.types.DataType;
+
+/** Implementation of an {@link ElementConverter} specific for DynamoDb sink. */
+public class RowDataElementConverter implements ElementConverter<RowData, DynamoDbWriteRequest> {
+
+    private final DataType physicalDataType;
+    private final RowDataToAttributeValueConverter rowDataToAttributeValueConverter;
+
+    public RowDataElementConverter(DataType physicalDataType) {
+        this.physicalDataType = physicalDataType;
+        this.rowDataToAttributeValueConverter =
+                new RowDataToAttributeValueConverter(physicalDataType);
+    }
+
+    @Override
+    public DynamoDbWriteRequest apply(RowData element, SinkWriter.Context context) {
+        switch (element.getRowKind()) {
+            case INSERT:
+            case UPDATE_AFTER:
+                return getPutRequest(element);
+            case UPDATE_BEFORE:
+            case DELETE:
+                return getDeleteRequest(element);
+            default:
+                throw new TableException("Unsupported message kind: " + element.getRowKind());
+        }
+    }
+
+    private DynamoDbWriteRequest getPutRequest(RowData row) {
+        return DynamoDbWriteRequest.builder()
+                .setType(DynamoDbWriteRequestType.PUT)
+                .setItem(rowDataToAttributeValueConverter.convertRowData(row))
+                .build();
+    }
+
+    private DynamoDbWriteRequest getDeleteRequest(RowData row) {
+        return DynamoDbWriteRequest.builder()
+                .setType(DynamoDbWriteRequestType.DELETE)
+                .setItem(rowDataToAttributeValueConverter.convertRowData(row))
+                .build();
+    }

Review Comment:
   Ok, done!



##########
flink-connector-dynamodb/src/main/java/org/apache/flink/connector/dynamodb/table/RowDataToAttributeValueConverter.java:
##########
@@ -0,0 +1,72 @@
+package org.apache.flink.connector.dynamodb.table;
+
+import org.apache.flink.table.api.DataTypes;
+import org.apache.flink.table.data.RowData;
+import org.apache.flink.table.data.conversion.DataStructureConverters;
+import org.apache.flink.table.types.DataType;
+
+import software.amazon.awssdk.enhanced.dynamodb.TableSchema;
+import software.amazon.awssdk.enhanced.dynamodb.mapper.StaticTableSchema;
+import software.amazon.awssdk.services.dynamodb.model.AttributeValue;
+
+import java.io.Serializable;
+import java.util.List;
+import java.util.Map;
+
+import static org.apache.flink.table.data.RowData.createFieldGetter;
+
+/** Converts from {@link RowData} to {@link AttributeValue}. */
+public class RowDataToAttributeValueConverter implements Serializable {
+    private static final long serialVersionUID = 1L;
+
+    private final DataType physicalDataType;
+    private transient TableSchema<RowData> tableSchema;
+
+    public RowDataToAttributeValueConverter(DataType physicalDataType) {
+        this.physicalDataType = physicalDataType;
+        this.tableSchema = createTableSchema();
+    }
+
+    private StaticTableSchema<RowData> createTableSchema() {
+        List<DataTypes.Field> fields = DataType.getFields(physicalDataType);
+        StaticTableSchema.Builder<RowData> builder = TableSchema.builder(RowData.class);
+        for (int i = 0; i < fields.size(); i++) {
+            DataTypes.Field field = fields.get(i);
+            RowData.FieldGetter fieldGetter =
+                    createFieldGetter(field.getDataType().getLogicalType(), i);
+
+            builder =
+                    addAttribute(
+                            builder, field.getDataType().getConversionClass(), field, fieldGetter);
+        }
+        return builder.build();
+    }
+
+    private <T> StaticTableSchema.Builder<RowData> addAttribute(
+            StaticTableSchema.Builder<RowData> builder,
+            Class<T> convertedClass,
+            DataTypes.Field field,
+            RowData.FieldGetter fieldGetter) {
+
+        return builder.addAttribute(
+                convertedClass,
+                a ->
+                        a.name(field.getName())
+                                .getter(
+                                        rowData ->
+                                                (T)
+                                                        DataStructureConverters.getConverter(
+                                                                        field.getDataType())
+                                                                .toExternal(
+                                                                        fieldGetter.getFieldOrNull(
+                                                                                rowData)))
+                                .setter(((rowData, t) -> {})));
+    }

Review Comment:
   :O Can't think of a nice way to simplify this...! It has 2 nested lambdas, probably why spotless went mad...



##########
flink-connector-dynamodb/src/main/java/org/apache/flink/connector/dynamodb/table/DynamoDbConfiguration.java:
##########
@@ -0,0 +1,24 @@
+package org.apache.flink.connector.dynamodb.table;
+
+import org.apache.flink.configuration.ReadableConfig;
+
+import static org.apache.flink.connector.dynamodb.table.DynamoDbConnectorOptions.FAIL_ON_ERROR;
+import static org.apache.flink.connector.dynamodb.table.DynamoDbConnectorOptions.TABLE_NAME;
+
+/** DynamoDb specific configuration. */
+public class DynamoDbConfiguration {

Review Comment:
   Done



##########
flink-connector-dynamodb/src/main/java/org/apache/flink/connector/dynamodb/table/RowDataToAttributeValueConverter.java:
##########
@@ -0,0 +1,72 @@
+package org.apache.flink.connector.dynamodb.table;
+
+import org.apache.flink.table.api.DataTypes;
+import org.apache.flink.table.data.RowData;
+import org.apache.flink.table.data.conversion.DataStructureConverters;
+import org.apache.flink.table.types.DataType;
+
+import software.amazon.awssdk.enhanced.dynamodb.TableSchema;
+import software.amazon.awssdk.enhanced.dynamodb.mapper.StaticTableSchema;
+import software.amazon.awssdk.services.dynamodb.model.AttributeValue;
+
+import java.io.Serializable;
+import java.util.List;
+import java.util.Map;
+
+import static org.apache.flink.table.data.RowData.createFieldGetter;
+
+/** Converts from {@link RowData} to {@link AttributeValue}. */
+public class RowDataToAttributeValueConverter implements Serializable {
+    private static final long serialVersionUID = 1L;
+
+    private final DataType physicalDataType;
+    private transient TableSchema<RowData> tableSchema;
+
+    public RowDataToAttributeValueConverter(DataType physicalDataType) {
+        this.physicalDataType = physicalDataType;
+        this.tableSchema = createTableSchema();
+    }
+
+    private StaticTableSchema<RowData> createTableSchema() {
+        List<DataTypes.Field> fields = DataType.getFields(physicalDataType);
+        StaticTableSchema.Builder<RowData> builder = TableSchema.builder(RowData.class);
+        for (int i = 0; i < fields.size(); i++) {
+            DataTypes.Field field = fields.get(i);
+            RowData.FieldGetter fieldGetter =
+                    createFieldGetter(field.getDataType().getLogicalType(), i);
+
+            builder =
+                    addAttribute(
+                            builder, field.getDataType().getConversionClass(), field, fieldGetter);
+        }
+        return builder.build();
+    }
+
+    private <T> StaticTableSchema.Builder<RowData> addAttribute(
+            StaticTableSchema.Builder<RowData> builder,
+            Class<T> convertedClass,
+            DataTypes.Field field,
+            RowData.FieldGetter fieldGetter) {
+
+        return builder.addAttribute(
+                convertedClass,
+                a ->
+                        a.name(field.getName())
+                                .getter(
+                                        rowData ->
+                                                (T)
+                                                        DataStructureConverters.getConverter(
+                                                                        field.getDataType())
+                                                                .toExternal(
+                                                                        fieldGetter.getFieldOrNull(
+                                                                                rowData)))
+                                .setter(((rowData, t) -> {})));
+    }
+
+    public Map<String, AttributeValue> convertRowData(RowData row) {

Review Comment:
   done



##########
flink-connector-dynamodb/src/main/java/org/apache/flink/connector/dynamodb/table/DynamoDbConfiguration.java:
##########
@@ -0,0 +1,24 @@
+package org.apache.flink.connector.dynamodb.table;

Review Comment:
   Done. Thanks for flagging



##########
flink-connector-dynamodb/src/main/java/org/apache/flink/connector/dynamodb/table/RowDataElementConverter.java:
##########
@@ -0,0 +1,50 @@
+package org.apache.flink.connector.dynamodb.table;
+
+import org.apache.flink.api.connector.sink2.SinkWriter;
+import org.apache.flink.connector.base.sink.writer.ElementConverter;
+import org.apache.flink.connector.dynamodb.sink.DynamoDbWriteRequest;
+import org.apache.flink.connector.dynamodb.sink.DynamoDbWriteRequestType;
+import org.apache.flink.table.api.TableException;
+import org.apache.flink.table.data.RowData;
+import org.apache.flink.table.types.DataType;
+
+/** Implementation of an {@link ElementConverter} specific for DynamoDb sink. */
+public class RowDataElementConverter implements ElementConverter<RowData, DynamoDbWriteRequest> {
+
+    private final DataType physicalDataType;
+    private final RowDataToAttributeValueConverter rowDataToAttributeValueConverter;
+
+    public RowDataElementConverter(DataType physicalDataType) {
+        this.physicalDataType = physicalDataType;
+        this.rowDataToAttributeValueConverter =
+                new RowDataToAttributeValueConverter(physicalDataType);
+    }
+
+    @Override
+    public DynamoDbWriteRequest apply(RowData element, SinkWriter.Context context) {
+        switch (element.getRowKind()) {
+            case INSERT:
+            case UPDATE_AFTER:
+                return getPutRequest(element);
+            case UPDATE_BEFORE:

Review Comment:
   Good spot. This was leftover from initial rough-cut implementation. `UPDATE_BEFORE` doesn't really make sense in the context of DDB sink since we have partition keys. Changed this to unsupported. Also specified that we only support `ChangelogMode.upsert()`.
   



-- 
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-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [flink-connector-aws] dannycranmer commented on a diff in pull request #15: [FLINK-29900][Connectors/DynamoDB] Implement Table API for DynamoDB sink

Posted by GitBox <gi...@apache.org>.
dannycranmer commented on code in PR #15:
URL: https://github.com/apache/flink-connector-aws/pull/15#discussion_r1026618568


##########
flink-connector-dynamodb/src/main/java/org/apache/flink/connector/dynamodb/table/RowDataToAttributeValueConverter.java:
##########
@@ -0,0 +1,72 @@
+package org.apache.flink.connector.dynamodb.table;
+
+import org.apache.flink.table.api.DataTypes;
+import org.apache.flink.table.data.RowData;
+import org.apache.flink.table.data.conversion.DataStructureConverters;
+import org.apache.flink.table.types.DataType;
+
+import software.amazon.awssdk.enhanced.dynamodb.TableSchema;
+import software.amazon.awssdk.enhanced.dynamodb.mapper.StaticTableSchema;
+import software.amazon.awssdk.services.dynamodb.model.AttributeValue;
+
+import java.io.Serializable;
+import java.util.List;
+import java.util.Map;
+
+import static org.apache.flink.table.data.RowData.createFieldGetter;
+
+/** Converts from {@link RowData} to {@link AttributeValue}. */
+public class RowDataToAttributeValueConverter implements Serializable {
+    private static final long serialVersionUID = 1L;
+
+    private final DataType physicalDataType;
+    private transient TableSchema<RowData> tableSchema;
+
+    public RowDataToAttributeValueConverter(DataType physicalDataType) {
+        this.physicalDataType = physicalDataType;
+        this.tableSchema = createTableSchema();
+    }
+
+    private StaticTableSchema<RowData> createTableSchema() {
+        List<DataTypes.Field> fields = DataType.getFields(physicalDataType);
+        StaticTableSchema.Builder<RowData> builder = TableSchema.builder(RowData.class);
+        for (int i = 0; i < fields.size(); i++) {
+            DataTypes.Field field = fields.get(i);
+            RowData.FieldGetter fieldGetter =
+                    createFieldGetter(field.getDataType().getLogicalType(), i);
+
+            builder =
+                    addAttribute(
+                            builder, field.getDataType().getConversionClass(), field, fieldGetter);
+        }
+        return builder.build();
+    }
+
+    private <T> StaticTableSchema.Builder<RowData> addAttribute(
+            StaticTableSchema.Builder<RowData> builder,
+            Class<T> convertedClass,
+            DataTypes.Field field,
+            RowData.FieldGetter fieldGetter) {
+
+        return builder.addAttribute(
+                convertedClass,
+                a ->
+                        a.name(field.getName())
+                                .getter(
+                                        rowData ->
+                                                (T)
+                                                        DataStructureConverters.getConverter(
+                                                                        field.getDataType())
+                                                                .toExternal(
+                                                                        fieldGetter.getFieldOrNull(
+                                                                                rowData)))
+                                .setter(((rowData, t) -> {})));
+    }

Review Comment:
   You _could_ extract the lambdas, but it is a nit



-- 
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-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [flink-connector-aws] hlteoh37 commented on a diff in pull request #15: [FLINK-29900][Connectors/DynamoDB] Implement Table API for DynamoDB sink

Posted by GitBox <gi...@apache.org>.
hlteoh37 commented on code in PR #15:
URL: https://github.com/apache/flink-connector-aws/pull/15#discussion_r1026721301


##########
flink-connector-dynamodb/src/main/java/org/apache/flink/connector/dynamodb/table/DynamoDbConfiguration.java:
##########
@@ -0,0 +1,44 @@
+/*
+ * 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.connector.dynamodb.table;
+
+import org.apache.flink.annotation.PublicEvolving;
+import org.apache.flink.configuration.ReadableConfig;
+
+import static org.apache.flink.connector.dynamodb.table.DynamoDbConnectorOptions.FAIL_ON_ERROR;
+import static org.apache.flink.connector.dynamodb.table.DynamoDbConnectorOptions.TABLE_NAME;
+
+/** DynamoDb specific configuration. */
+@PublicEvolving

Review Comment:
   done.



##########
flink-connector-dynamodb/src/main/java/org/apache/flink/connector/dynamodb/table/RowDataElementConverter.java:
##########
@@ -0,0 +1,68 @@
+/*
+ * 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.connector.dynamodb.table;
+
+import org.apache.flink.annotation.Internal;
+import org.apache.flink.api.connector.sink2.SinkWriter;
+import org.apache.flink.connector.base.sink.writer.ElementConverter;
+import org.apache.flink.connector.dynamodb.sink.DynamoDbWriteRequest;
+import org.apache.flink.connector.dynamodb.sink.DynamoDbWriteRequestType;
+import org.apache.flink.table.api.TableException;
+import org.apache.flink.table.data.RowData;
+import org.apache.flink.table.types.DataType;
+
+/**
+ * Implementation of an {@link ElementConverter} for the DynamoDb Table sink. The element converter
+ * maps the Flink internal type of {@link RowData} to a {@link DynamoDbWriteRequest} to be used by
+ * the DynamoDb sink.
+ */
+@Internal
+public class RowDataElementConverter implements ElementConverter<RowData, DynamoDbWriteRequest> {
+
+    private final DataType physicalDataType;
+    private final RowDataToAttributeValueConverter rowDataToAttributeValueConverter;
+
+    public RowDataElementConverter(DataType physicalDataType) {
+        this.physicalDataType = physicalDataType;
+        this.rowDataToAttributeValueConverter =
+                new RowDataToAttributeValueConverter(physicalDataType);
+    }

Review Comment:
   we do the same here! Its in the constructor of the `RowDataToAttributeValueConverter`



##########
flink-connector-dynamodb/src/main/java/org/apache/flink/connector/dynamodb/table/DynamoDbDynamicSinkFactory.java:
##########
@@ -0,0 +1,73 @@
+/*
+ * 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.connector.dynamodb.table;
+
+import org.apache.flink.annotation.Internal;
+import org.apache.flink.configuration.ConfigOption;
+import org.apache.flink.connector.base.table.AsyncDynamicTableSinkFactory;
+import org.apache.flink.table.catalog.ResolvedCatalogTable;
+import org.apache.flink.table.connector.sink.DynamicTableSink;
+import org.apache.flink.table.factories.FactoryUtil;
+
+import org.apache.flink.shaded.guava30.com.google.common.collect.ImmutableSet;
+
+import java.util.HashSet;
+import java.util.Properties;
+import java.util.Set;
+
+import static org.apache.flink.connector.dynamodb.table.DynamoDbConnectorOptions.TABLE_NAME;
+
+/** Factory for creating {@link DynamoDbDynamicSink}. */
+@Internal
+public class DynamoDbDynamicSinkFactory extends AsyncDynamicTableSinkFactory {
+
+    public static final String FACTORY_IDENTIFIER = "dynamodb";
+
+    @Override
+    public DynamicTableSink createDynamicTableSink(Context context) {
+        FactoryUtil.TableFactoryHelper factoryHelper =
+                FactoryUtil.createTableFactoryHelper(this, context);
+        ResolvedCatalogTable catalogTable = context.getCatalogTable();
+
+        FactoryUtil.validateFactoryOptions(this, factoryHelper.getOptions());
+
+        DynamoDbConfiguration dynamoDbConfiguration =
+                new DynamoDbConfiguration(factoryHelper.getOptions());
+
+        Properties dynamoDbClientProperties = new Properties();
+        dynamoDbClientProperties.putAll(catalogTable.getOptions());
+        return DynamoDbDynamicSink.builder()
+                .setTableName(dynamoDbConfiguration.getTableName())
+                .setFailOnError(dynamoDbConfiguration.getFailOnError())
+                .setPhysicalDataType(catalogTable.getResolvedSchema().toPhysicalRowDataType())
+                .setOverwriteByPartitionKeys(new HashSet<>(catalogTable.getPartitionKeys()))
+                .setDynamoDbClientProperties(dynamoDbClientProperties)
+                .build();
+    }
+
+    @Override
+    public String factoryIdentifier() {
+        return FACTORY_IDENTIFIER;
+    }
+
+    @Override
+    public Set<ConfigOption<?>> requiredOptions() {
+        return ImmutableSet.of(TABLE_NAME);

Review Comment:
   Ok, added. We can followup with a way to make these AWS configs generalised



##########
flink-connector-dynamodb/src/main/java/org/apache/flink/connector/dynamodb/table/converter/ArrayAttributeConverterProvider.java:
##########
@@ -0,0 +1,80 @@
+/*
+ * 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.connector.dynamodb.table.converter;
+
+import org.apache.flink.annotation.Internal;
+
+import software.amazon.awssdk.enhanced.dynamodb.AttributeConverter;
+import software.amazon.awssdk.enhanced.dynamodb.AttributeConverterProvider;
+import software.amazon.awssdk.enhanced.dynamodb.EnhancedType;
+
+import java.math.BigDecimal;
+import java.time.Instant;
+import java.time.LocalDate;
+import java.time.LocalDateTime;
+import java.time.LocalTime;
+
+/** Attribute converter provider for String Array. */
+@Internal
+public class ArrayAttributeConverterProvider implements AttributeConverterProvider {
+
+    private static final AttributeConverterProvider defaultAttributeConverterProvider =
+            AttributeConverterProvider.defaultProvider();
+
+    @Override
+    public <T> AttributeConverter<T> converterFor(EnhancedType<T> enhancedType) {
+        if (enhancedType.equals(EnhancedType.of(String[].class))) {
+            return (AttributeConverter<T>) getArrayAttributeConverter(String.class, enhancedType);
+        } else if (enhancedType.equals(EnhancedType.of(Boolean[].class))) {
+            return (AttributeConverter<T>) getArrayAttributeConverter(Boolean.class, enhancedType);
+        } else if (enhancedType.equals(EnhancedType.of(BigDecimal[].class))) {
+            return (AttributeConverter<T>)
+                    getArrayAttributeConverter(BigDecimal.class, enhancedType);
+        } else if (enhancedType.equals(EnhancedType.of(Byte[].class))) {
+            return (AttributeConverter<T>) getArrayAttributeConverter(Byte.class, enhancedType);
+        } else if (enhancedType.equals(EnhancedType.of(Short[].class))) {
+            return (AttributeConverter<T>) getArrayAttributeConverter(Short.class, enhancedType);
+        } else if (enhancedType.equals(EnhancedType.of(Integer[].class))) {
+            return (AttributeConverter<T>) getArrayAttributeConverter(Integer.class, enhancedType);
+        } else if (enhancedType.equals(EnhancedType.of(Long[].class))) {
+            return (AttributeConverter<T>) getArrayAttributeConverter(Long.class, enhancedType);
+        } else if (enhancedType.equals(EnhancedType.of(Float[].class))) {
+            return (AttributeConverter<T>) getArrayAttributeConverter(Float.class, enhancedType);
+        } else if (enhancedType.equals(EnhancedType.of(LocalDate[].class))) {
+            return (AttributeConverter<T>)
+                    getArrayAttributeConverter(LocalDate.class, enhancedType);
+        } else if (enhancedType.equals(EnhancedType.of(LocalTime[].class))) {
+            return (AttributeConverter<T>)
+                    getArrayAttributeConverter(LocalTime.class, enhancedType);
+        } else if (enhancedType.equals(EnhancedType.of(LocalDateTime[].class))) {
+            return (AttributeConverter<T>)
+                    getArrayAttributeConverter(LocalDateTime.class, enhancedType);
+        } else if (enhancedType.equals(EnhancedType.of(Instant[].class))) {
+            return (AttributeConverter<T>) getArrayAttributeConverter(Instant.class, enhancedType);
+        }
+        return null;

Review Comment:
   Added support for `Double`



##########
flink-connector-dynamodb/src/main/java/org/apache/flink/connector/dynamodb/table/RowDataToAttributeValueConverter.java:
##########
@@ -0,0 +1,109 @@
+/*
+ * 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.connector.dynamodb.table;
+
+import org.apache.flink.annotation.Internal;
+import org.apache.flink.connector.dynamodb.table.converter.ArrayAttributeConverterProvider;
+import org.apache.flink.table.api.DataTypes;
+import org.apache.flink.table.data.RowData;
+import org.apache.flink.table.data.conversion.DataStructureConverters;
+import org.apache.flink.table.types.DataType;
+import org.apache.flink.table.types.KeyValueDataType;
+
+import software.amazon.awssdk.enhanced.dynamodb.AttributeConverterProvider;
+import software.amazon.awssdk.enhanced.dynamodb.EnhancedType;
+import software.amazon.awssdk.enhanced.dynamodb.TableSchema;
+import software.amazon.awssdk.enhanced.dynamodb.mapper.StaticTableSchema;
+import software.amazon.awssdk.services.dynamodb.model.AttributeValue;
+
+import java.io.Serializable;
+import java.util.List;
+import java.util.Map;
+
+import static org.apache.flink.table.data.RowData.createFieldGetter;
+
+/** Converts from Flink Table API internal type of {@link RowData} to {@link AttributeValue}. */
+@Internal
+public class RowDataToAttributeValueConverter implements Serializable {

Review Comment:
   done



##########
flink-connector-dynamodb/src/main/java/org/apache/flink/connector/dynamodb/table/DynamoDbDynamicSink.java:
##########
@@ -0,0 +1,181 @@
+/*
+ * 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.connector.dynamodb.table;
+
+import org.apache.flink.annotation.Internal;
+import org.apache.flink.connector.base.table.sink.AsyncDynamicTableSink;
+import org.apache.flink.connector.base.table.sink.AsyncDynamicTableSinkBuilder;
+import org.apache.flink.connector.dynamodb.sink.DynamoDbSink;
+import org.apache.flink.connector.dynamodb.sink.DynamoDbSinkBuilder;
+import org.apache.flink.connector.dynamodb.sink.DynamoDbWriteRequest;
+import org.apache.flink.table.connector.ChangelogMode;
+import org.apache.flink.table.connector.sink.DynamicTableSink;
+import org.apache.flink.table.connector.sink.SinkV2Provider;
+import org.apache.flink.table.connector.sink.abilities.SupportsPartitioning;
+import org.apache.flink.table.data.RowData;
+import org.apache.flink.table.types.DataType;
+
+import javax.annotation.Nullable;
+
+import java.util.ArrayList;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Set;
+
+/**
+ * A {@link DynamicTableSink} that describes how to create a {@link DynamoDbSink} from a logical
+ * description.
+ */
+@Internal
+public class DynamoDbDynamicSink extends AsyncDynamicTableSink<DynamoDbWriteRequest>
+        implements SupportsPartitioning {
+
+    private final String tableName;
+    private final boolean failOnError;
+    private final Properties dynamoDbClientProperties;
+    private final DataType physicalDataType;
+    private final Set<String> overwriteByPartitionKeys;
+
+    protected DynamoDbDynamicSink(
+            @Nullable Integer maxBatchSize,
+            @Nullable Integer maxInFlightRequests,
+            @Nullable Integer maxBufferedRequests,
+            @Nullable Long maxBufferSizeInBytes,
+            @Nullable Long maxTimeInBufferMS,
+            String tableName,
+            boolean failOnError,
+            Properties dynamoDbClientProperties,
+            DataType physicalDataType,
+            Set<String> overwriteByPartitionKeys) {
+        super(
+                maxBatchSize,
+                maxInFlightRequests,
+                maxBufferedRequests,
+                maxBufferSizeInBytes,
+                maxTimeInBufferMS);
+        this.tableName = tableName;
+        this.failOnError = failOnError;
+        this.dynamoDbClientProperties = dynamoDbClientProperties;
+        this.physicalDataType = physicalDataType;
+        this.overwriteByPartitionKeys = overwriteByPartitionKeys;
+    }
+
+    @Override
+    public ChangelogMode getChangelogMode(ChangelogMode changelogMode) {
+        return ChangelogMode.upsert();
+    }
+
+    @Override
+    public SinkRuntimeProvider getSinkRuntimeProvider(Context context) {
+        DynamoDbSinkBuilder<RowData> builder =
+                DynamoDbSink.<RowData>builder()
+                        .setTableName(tableName)
+                        .setFailOnError(failOnError)
+                        .setOverwriteByPartitionKeys(new ArrayList<>(overwriteByPartitionKeys))
+                        .setDynamoDbProperties(dynamoDbClientProperties)
+                        .setElementConverter(new RowDataElementConverter(physicalDataType));
+
+        addAsyncOptionsToSinkBuilder(builder);
+
+        return SinkV2Provider.of(builder.build());
+    }
+
+    @Override
+    public DynamicTableSink copy() {
+        return new DynamoDbDynamicSink(
+                maxBatchSize,
+                maxInFlightRequests,
+                maxBufferedRequests,
+                maxBufferSizeInBytes,
+                maxTimeInBufferMS,
+                tableName,
+                failOnError,
+                dynamoDbClientProperties,
+                physicalDataType,
+                overwriteByPartitionKeys);
+    }
+
+    @Override
+    public String asSummaryString() {
+        return "DynamoDB";
+    }
+
+    @Override
+    public void applyStaticPartition(Map<String, String> partitions) {

Review Comment:
   This is only called when user does `PARTITION` directly in the query. For example:
   ```
   CREATE TABLE dynamo (
                                  `pk` STRING,
                                  `ts` TIMESTAMP(3),
                                  `payload` STRING
   ) PARTITIONED BY ( pk )
       WITH (
           'connector' = 'dynamodb',
           'table-name' = 'TestDdbSink'
            'aws.region' = 'us-east-1'
           );
   
   INSERT INTO dynamo PARTITION (pk='some_static_partition') SELECT ts, payload FROM another_view
   ```
   
   In this function, we are also passed the value `some_static_partition`, but we can ignore it because it will be added to the `RowData` as per normal.



##########
flink-connector-dynamodb/src/main/java/org/apache/flink/connector/dynamodb/table/DynamoDbConnectorOptions.java:
##########
@@ -0,0 +1,46 @@
+/*
+ * 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.connector.dynamodb.table;
+
+import org.apache.flink.annotation.PublicEvolving;
+import org.apache.flink.configuration.ConfigOption;
+import org.apache.flink.configuration.ConfigOptions;
+import org.apache.flink.table.api.TableDescriptor;
+
+/** DynamoDb connector options. Made public for {@link TableDescriptor} to access it. */
+@PublicEvolving
+public class DynamoDbConnectorOptions {
+
+    private DynamoDbConnectorOptions() {
+        // private constructor to prevent initialization of static class
+    }

Review Comment:
   done
   



##########
flink-connector-dynamodb/src/main/java/org/apache/flink/connector/dynamodb/table/converter/ArrayAttributeConverterProvider.java:
##########
@@ -0,0 +1,80 @@
+/*
+ * 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.connector.dynamodb.table.converter;
+
+import org.apache.flink.annotation.Internal;
+
+import software.amazon.awssdk.enhanced.dynamodb.AttributeConverter;
+import software.amazon.awssdk.enhanced.dynamodb.AttributeConverterProvider;
+import software.amazon.awssdk.enhanced.dynamodb.EnhancedType;
+
+import java.math.BigDecimal;
+import java.time.Instant;
+import java.time.LocalDate;
+import java.time.LocalDateTime;
+import java.time.LocalTime;
+
+/** Attribute converter provider for String Array. */
+@Internal
+public class ArrayAttributeConverterProvider implements AttributeConverterProvider {
+
+    private static final AttributeConverterProvider defaultAttributeConverterProvider =
+            AttributeConverterProvider.defaultProvider();
+
+    @Override
+    public <T> AttributeConverter<T> converterFor(EnhancedType<T> enhancedType) {
+        if (enhancedType.equals(EnhancedType.of(String[].class))) {
+            return (AttributeConverter<T>) getArrayAttributeConverter(String.class, enhancedType);
+        } else if (enhancedType.equals(EnhancedType.of(Boolean[].class))) {
+            return (AttributeConverter<T>) getArrayAttributeConverter(Boolean.class, enhancedType);
+        } else if (enhancedType.equals(EnhancedType.of(BigDecimal[].class))) {
+            return (AttributeConverter<T>)
+                    getArrayAttributeConverter(BigDecimal.class, enhancedType);
+        } else if (enhancedType.equals(EnhancedType.of(Byte[].class))) {
+            return (AttributeConverter<T>) getArrayAttributeConverter(Byte.class, enhancedType);
+        } else if (enhancedType.equals(EnhancedType.of(Short[].class))) {
+            return (AttributeConverter<T>) getArrayAttributeConverter(Short.class, enhancedType);
+        } else if (enhancedType.equals(EnhancedType.of(Integer[].class))) {
+            return (AttributeConverter<T>) getArrayAttributeConverter(Integer.class, enhancedType);
+        } else if (enhancedType.equals(EnhancedType.of(Long[].class))) {
+            return (AttributeConverter<T>) getArrayAttributeConverter(Long.class, enhancedType);
+        } else if (enhancedType.equals(EnhancedType.of(Float[].class))) {
+            return (AttributeConverter<T>) getArrayAttributeConverter(Float.class, enhancedType);
+        } else if (enhancedType.equals(EnhancedType.of(LocalDate[].class))) {
+            return (AttributeConverter<T>)
+                    getArrayAttributeConverter(LocalDate.class, enhancedType);
+        } else if (enhancedType.equals(EnhancedType.of(LocalTime[].class))) {
+            return (AttributeConverter<T>)
+                    getArrayAttributeConverter(LocalTime.class, enhancedType);
+        } else if (enhancedType.equals(EnhancedType.of(LocalDateTime[].class))) {
+            return (AttributeConverter<T>)
+                    getArrayAttributeConverter(LocalDateTime.class, enhancedType);
+        } else if (enhancedType.equals(EnhancedType.of(Instant[].class))) {
+            return (AttributeConverter<T>) getArrayAttributeConverter(Instant.class, enhancedType);
+        }
+        return null;

Review Comment:
   This is not a failure mode! This is the expected interface for `ChainedAttributeConverterProvider`. If we return `null`, it will fall back to the next attribute converter provider.
   
   https://github.com/aws/aws-sdk-java-v2/blob/584ccb59e770177aeaa4c3b6bda4e24015b8ece9/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal/converter/ChainConverterProvider.java#L64-L69



##########
flink-connector-dynamodb/src/main/java/org/apache/flink/connector/dynamodb/table/DynamoDbConnectorOptions.java:
##########
@@ -0,0 +1,46 @@
+/*
+ * 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.connector.dynamodb.table;
+
+import org.apache.flink.annotation.PublicEvolving;
+import org.apache.flink.configuration.ConfigOption;
+import org.apache.flink.configuration.ConfigOptions;
+import org.apache.flink.table.api.TableDescriptor;
+
+/** DynamoDb connector options. Made public for {@link TableDescriptor} to access it. */
+@PublicEvolving
+public class DynamoDbConnectorOptions {

Review Comment:
   Added region as mandatory config. Not sure about the "overwrite by partiton key", since we can use the `PARTITION BY` SQL syntax instead!



##########
flink-connector-dynamodb/src/main/java/org/apache/flink/connector/dynamodb/table/converter/ArrayAttributeConverterProvider.java:
##########
@@ -0,0 +1,80 @@
+/*
+ * 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.connector.dynamodb.table.converter;
+
+import org.apache.flink.annotation.Internal;
+
+import software.amazon.awssdk.enhanced.dynamodb.AttributeConverter;
+import software.amazon.awssdk.enhanced.dynamodb.AttributeConverterProvider;
+import software.amazon.awssdk.enhanced.dynamodb.EnhancedType;
+
+import java.math.BigDecimal;
+import java.time.Instant;
+import java.time.LocalDate;
+import java.time.LocalDateTime;
+import java.time.LocalTime;
+
+/** Attribute converter provider for String Array. */
+@Internal
+public class ArrayAttributeConverterProvider implements AttributeConverterProvider {
+
+    private static final AttributeConverterProvider defaultAttributeConverterProvider =
+            AttributeConverterProvider.defaultProvider();
+
+    @Override
+    public <T> AttributeConverter<T> converterFor(EnhancedType<T> enhancedType) {

Review Comment:
   `EnhancedType` is just a wrapper class around the normal java `Class`, which is used to keep track of types even when Java erases them. It is not an enum / list of classes. Since it's `@SdkPublicApi` this is relatively safe behaviour to depend on. 
   
   But I think the spirit of your question is about changing support for types we depend on. e.g. we depend on the `AttributeConverterProvider.defaultProvider()` having support for the classes we have here (e.g. `Boolean`, or `BigDecimal` etc. 
   
   To combat this, I've added unit tests for each of these classes. They will fail if support is removed.
   
   
   



-- 
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-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [flink-connector-aws] hlteoh37 commented on a diff in pull request #15: [FLINK-29900][Connectors/DynamoDB] Implement Table API for DynamoDB sink

Posted by GitBox <gi...@apache.org>.
hlteoh37 commented on code in PR #15:
URL: https://github.com/apache/flink-connector-aws/pull/15#discussion_r1028423893


##########
flink-sql-connector-dynamodb/pom.xml:
##########
@@ -77,12 +77,16 @@ under the License.
 									<include>org.apache.httpcomponents:*</include>
 									<include>io.netty:*</include>
 									<include>commons-logging:commons-logging</include>
+									<include>commons-codec:commons-codec</include>
 								</includes>
 							</artifactSet>
 							<relocations>
 								<relocation>
 									<pattern>software.amazon</pattern>
 									<shadedPattern>org.apache.flink.connector.dynamodb.shaded.software.amazon</shadedPattern>
+									<excludes>
+										<exclude>software.amazon.awssdk.enhanced.**</exclude>
+									</excludes>

Review Comment:
   Ok! done the same!



-- 
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-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [flink-connector-aws] hlteoh37 commented on a diff in pull request #15: [FLINK-29900][Connectors/DynamoDB] Implement Table API for DynamoDB sink

Posted by GitBox <gi...@apache.org>.
hlteoh37 commented on code in PR #15:
URL: https://github.com/apache/flink-connector-aws/pull/15#discussion_r1029078032


##########
flink-sql-connector-dynamodb/pom.xml:
##########
@@ -77,6 +77,7 @@ under the License.
 									<include>org.apache.httpcomponents:*</include>
 									<include>io.netty:*</include>
 									<include>commons-logging:commons-logging</include>
+									<include>commons-codec:commons-codec</include>

Review Comment:
   Good spot. Updated notice file
   
   Used the following output from build
   
   1.15.2
   ```
   [INFO] --- maven-shade-plugin:3.2.4:shade (shade-flink) @ flink-sql-connector-dynamodb ---
   [INFO] Including org.apache.flink:flink-connector-dynamodb:jar:1.0.0-SNAPSHOT in the shaded jar.
   [INFO] Including org.apache.flink:flink-connector-base:jar:1.15.2 in the shaded jar.
   [INFO] Including org.apache.flink:flink-connector-aws-base:jar:1.15.2 in the shaded jar.
   [INFO] Including software.amazon.awssdk:netty-nio-client:jar:2.17.247 in the shaded jar.
   [INFO] Including io.netty:netty-codec-http:jar:4.1.77.Final in the shaded jar.
   [INFO] Including io.netty:netty-codec-http2:jar:4.1.77.Final in the shaded jar.
   [INFO] Including io.netty:netty-codec:jar:4.1.77.Final in the shaded jar.
   [INFO] Including io.netty:netty-transport:jar:4.1.77.Final in the shaded jar.
   [INFO] Including io.netty:netty-resolver:jar:4.1.77.Final in the shaded jar.
   [INFO] Including io.netty:netty-common:jar:4.1.77.Final in the shaded jar.
   [INFO] Including io.netty:netty-buffer:jar:4.1.77.Final in the shaded jar.
   [INFO] Including io.netty:netty-handler:jar:4.1.77.Final in the shaded jar.
   [INFO] Including io.netty:netty-transport-classes-epoll:jar:4.1.77.Final in the shaded jar.
   [INFO] Including io.netty:netty-transport-native-unix-common:jar:4.1.77.Final in the shaded jar.
   [INFO] Including org.reactivestreams:reactive-streams:jar:1.0.3 in the shaded jar.
   [INFO] Including software.amazon.awssdk:sts:jar:2.17.247 in the shaded jar.
   [INFO] Including software.amazon.awssdk:aws-query-protocol:jar:2.17.247 in the shaded jar.
   [INFO] Including software.amazon.awssdk:dynamodb:jar:2.17.247 in the shaded jar.
   [INFO] Including software.amazon.awssdk:aws-json-protocol:jar:2.17.247 in the shaded jar.
   [INFO] Including software.amazon.awssdk:third-party-jackson-core:jar:2.17.247 in the shaded jar.
   [INFO] Including software.amazon.awssdk:json-utils:jar:2.17.247 in the shaded jar.
   [INFO] Including software.amazon.awssdk:protocol-core:jar:2.17.247 in the shaded jar.
   [INFO] Including software.amazon.awssdk:profiles:jar:2.17.247 in the shaded jar.
   [INFO] Including software.amazon.awssdk:sdk-core:jar:2.17.247 in the shaded jar.
   [INFO] Including software.amazon.awssdk:auth:jar:2.17.247 in the shaded jar.
   [INFO] Including software.amazon.awssdk:http-client-spi:jar:2.17.247 in the shaded jar.
   [INFO] Including software.amazon.awssdk:regions:jar:2.17.247 in the shaded jar.
   [INFO] Including software.amazon.awssdk:annotations:jar:2.17.247 in the shaded jar.
   [INFO] Including software.amazon.awssdk:utils:jar:2.17.247 in the shaded jar.
   [INFO] Including software.amazon.awssdk:aws-core:jar:2.17.247 in the shaded jar.
   [INFO] Including software.amazon.awssdk:metrics-spi:jar:2.17.247 in the shaded jar.
   [INFO] Including software.amazon.awssdk:apache-client:jar:2.17.247 in the shaded jar.
   [INFO] Including org.apache.httpcomponents:httpclient:jar:4.5.13 in the shaded jar.
   [INFO] Including commons-logging:commons-logging:jar:1.2 in the shaded jar.
   [INFO] Including commons-codec:commons-codec:jar:1.11 in the shaded jar.
   [INFO] Including org.apache.httpcomponents:httpcore:jar:4.4.13 in the shaded jar.
   [INFO] Including software.amazon.awssdk:dynamodb-enhanced:jar:2.17.247 in the shaded jar.
   [INFO] Excluding software.amazon.eventstream:eventstream:jar:1.0.1 from the shaded jar.
   [INFO] Excluding org.apache.flink:flink-shaded-force-shading:jar:16.0 from the shaded jar.
   [INFO] Excluding org.slf4j:slf4j-api:jar:1.7.36 from the shaded jar.
   [INFO] No artifact matching filter io.netty:netty
   
   ```
   
   1.16.0
   ```
   [INFO] --- maven-shade-plugin:3.2.4:shade (shade-flink) @ flink-sql-connector-dynamodb ---
   [INFO] Including org.apache.flink:flink-connector-dynamodb:jar:1.0.0-SNAPSHOT in the shaded jar.
   [INFO] Including org.apache.flink:flink-connector-base:jar:1.16.0 in the shaded jar.
   [INFO] Including org.apache.flink:flink-connector-aws-base:jar:1.16.0 in the shaded jar.
   [INFO] Including software.amazon.awssdk:netty-nio-client:jar:2.17.247 in the shaded jar.
   [INFO] Including io.netty:netty-codec-http:jar:4.1.77.Final in the shaded jar.
   [INFO] Including io.netty:netty-codec-http2:jar:4.1.77.Final in the shaded jar.
   [INFO] Including io.netty:netty-codec:jar:4.1.77.Final in the shaded jar.
   [INFO] Including io.netty:netty-transport:jar:4.1.77.Final in the shaded jar.
   [INFO] Including io.netty:netty-resolver:jar:4.1.77.Final in the shaded jar.
   [INFO] Including io.netty:netty-common:jar:4.1.77.Final in the shaded jar.
   [INFO] Including io.netty:netty-buffer:jar:4.1.77.Final in the shaded jar.
   [INFO] Including io.netty:netty-handler:jar:4.1.77.Final in the shaded jar.
   [INFO] Including io.netty:netty-transport-classes-epoll:jar:4.1.77.Final in the shaded jar.
   [INFO] Including io.netty:netty-transport-native-unix-common:jar:4.1.77.Final in the shaded jar.
   [INFO] Including org.reactivestreams:reactive-streams:jar:1.0.3 in the shaded jar.
   [INFO] Including software.amazon.awssdk:sts:jar:2.17.247 in the shaded jar.
   [INFO] Including software.amazon.awssdk:aws-query-protocol:jar:2.17.247 in the shaded jar.
   [INFO] Including software.amazon.awssdk:dynamodb:jar:2.17.247 in the shaded jar.
   [INFO] Including software.amazon.awssdk:aws-json-protocol:jar:2.17.247 in the shaded jar.
   [INFO] Including software.amazon.awssdk:third-party-jackson-core:jar:2.17.247 in the shaded jar.
   [INFO] Including software.amazon.awssdk:json-utils:jar:2.17.247 in the shaded jar.
   [INFO] Including software.amazon.awssdk:protocol-core:jar:2.17.247 in the shaded jar.
   [INFO] Including software.amazon.awssdk:profiles:jar:2.17.247 in the shaded jar.
   [INFO] Including software.amazon.awssdk:sdk-core:jar:2.17.247 in the shaded jar.
   [INFO] Including software.amazon.awssdk:auth:jar:2.17.247 in the shaded jar.
   [INFO] Including software.amazon.awssdk:http-client-spi:jar:2.17.247 in the shaded jar.
   [INFO] Including software.amazon.awssdk:regions:jar:2.17.247 in the shaded jar.
   [INFO] Including software.amazon.awssdk:annotations:jar:2.17.247 in the shaded jar.
   [INFO] Including software.amazon.awssdk:utils:jar:2.17.247 in the shaded jar.
   [INFO] Including software.amazon.awssdk:aws-core:jar:2.17.247 in the shaded jar.
   [INFO] Including software.amazon.awssdk:metrics-spi:jar:2.17.247 in the shaded jar.
   [INFO] Including software.amazon.awssdk:apache-client:jar:2.17.247 in the shaded jar.
   [INFO] Including org.apache.httpcomponents:httpclient:jar:4.5.13 in the shaded jar.
   [INFO] Including commons-logging:commons-logging:jar:1.2 in the shaded jar.
   [INFO] Including commons-codec:commons-codec:jar:1.11 in the shaded jar.
   [INFO] Including org.apache.httpcomponents:httpcore:jar:4.4.13 in the shaded jar.
   [INFO] Including software.amazon.awssdk:dynamodb-enhanced:jar:2.17.247 in the shaded jar.
   [INFO] Excluding software.amazon.eventstream:eventstream:jar:1.0.1 from the shaded jar.
   [INFO] Excluding org.apache.flink:flink-shaded-force-shading:jar:16.0 from the shaded jar.
   [INFO] Excluding org.slf4j:slf4j-api:jar:1.7.36 from the shaded jar.
   [INFO] No artifact matching filter io.netty:netty
   
   ```



-- 
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-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [flink-connector-aws] dannycranmer commented on a diff in pull request #15: [FLINK-29900][Connectors/DynamoDB] Implement Table API for DynamoDB sink

Posted by GitBox <gi...@apache.org>.
dannycranmer commented on code in PR #15:
URL: https://github.com/apache/flink-connector-aws/pull/15#discussion_r1026625994


##########
flink-connector-dynamodb/src/test/java/org/apache/flink/connector/dynamodb/table/DynamoDbDynamicSinkFactoryTest.java:
##########
@@ -0,0 +1,267 @@
+package org.apache.flink.connector.dynamodb.table;

Review Comment:
   Missing copyright header



##########
flink-connector-dynamodb/src/test/java/org/apache/flink/connector/dynamodb/table/DynamoDbDynamicSinkFactoryTest.java:
##########
@@ -0,0 +1,267 @@
+package org.apache.flink.connector.dynamodb.table;
+
+import org.apache.flink.api.connector.sink2.Sink;
+import org.apache.flink.connector.dynamodb.sink.DynamoDbSink;
+import org.apache.flink.table.api.DataTypes;
+import org.apache.flink.table.api.ValidationException;
+import org.apache.flink.table.catalog.Column;
+import org.apache.flink.table.catalog.ResolvedSchema;
+import org.apache.flink.table.connector.ChangelogMode;
+import org.apache.flink.table.connector.sink.SinkV2Provider;
+import org.apache.flink.table.data.RowData;
+import org.apache.flink.table.factories.TableOptionsBuilder;
+import org.apache.flink.table.factories.TestFormatFactory;
+import org.apache.flink.table.runtime.connector.sink.SinkRuntimeProviderContext;
+
+import org.apache.flink.shaded.guava30.com.google.common.collect.ImmutableMap;
+
+import org.junit.jupiter.api.Test;
+
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Set;
+
+import static org.apache.flink.connector.base.table.AsyncSinkConnectorOptions.FLUSH_BUFFER_SIZE;
+import static org.apache.flink.connector.base.table.AsyncSinkConnectorOptions.FLUSH_BUFFER_TIMEOUT;
+import static org.apache.flink.connector.base.table.AsyncSinkConnectorOptions.MAX_BATCH_SIZE;
+import static org.apache.flink.connector.base.table.AsyncSinkConnectorOptions.MAX_BUFFERED_REQUESTS;
+import static org.apache.flink.connector.base.table.AsyncSinkConnectorOptions.MAX_IN_FLIGHT_REQUESTS;
+import static org.apache.flink.connector.dynamodb.table.DynamoDbConnectorOptions.FAIL_ON_ERROR;
+import static org.apache.flink.connector.dynamodb.table.DynamoDbConnectorOptions.TABLE_NAME;
+import static org.apache.flink.table.factories.utils.FactoryMocks.createTableSink;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
+
+/** Test for {@link DynamoDbDynamicSink} created by {@link DynamoDbDynamicSinkFactory}. */
+public class DynamoDbDynamicSinkFactoryTest {
+
+    private static final String DYNAMO_DB_TABLE_NAME = "TestDynamoDBTable";
+
+    @Test
+    void testGoodPartitionedTableSink() {
+        ResolvedSchema sinkSchema =
+                ResolvedSchema.of(
+                        Column.physical("partition_key", DataTypes.STRING()),
+                        Column.physical("sort_key", DataTypes.BIGINT()),
+                        Column.physical("payload", DataTypes.STRING()),
+                        Column.physical("some_char_array", DataTypes.ARRAY(DataTypes.CHAR(1))),
+                        Column.physical(
+                                "some_varchar_array", DataTypes.ARRAY(DataTypes.VARCHAR(1))),
+                        Column.physical("some_string_array", DataTypes.ARRAY(DataTypes.STRING())),
+                        Column.physical("some_boolean_array", DataTypes.ARRAY(DataTypes.BOOLEAN())),
+                        Column.physical(
+                                "some_decimal_array", DataTypes.ARRAY(DataTypes.DECIMAL(1, 1))),
+                        Column.physical("some_tinyint_array", DataTypes.ARRAY(DataTypes.TINYINT())),
+                        Column.physical(
+                                "some_smallint_array", DataTypes.ARRAY(DataTypes.SMALLINT())),
+                        Column.physical("some_int_array", DataTypes.ARRAY(DataTypes.INT())),
+                        Column.physical("some_bigint_array", DataTypes.ARRAY(DataTypes.BIGINT())),
+                        Column.physical("some_float_array", DataTypes.ARRAY(DataTypes.FLOAT())),
+                        Column.physical("some_date_array", DataTypes.ARRAY(DataTypes.DATE())),
+                        Column.physical("some_time_array", DataTypes.ARRAY(DataTypes.TIME())),
+                        Column.physical(
+                                "some_timestamp_array", DataTypes.ARRAY(DataTypes.TIMESTAMP())),
+                        Column.physical(
+                                "some_timestamp_ltz_array",
+                                DataTypes.ARRAY(DataTypes.TIMESTAMP_LTZ())),
+                        Column.physical(
+                                "some_map", DataTypes.MAP(DataTypes.STRING(), DataTypes.BIGINT())));
+        Map<String, String> sinkOptions = defaultSinkOptions().build();
+        List<String> partitionKeys = Collections.singletonList("partition_key");
+
+        // Construct actual sink
+        DynamoDbDynamicSink actualSink =
+                (DynamoDbDynamicSink) createTableSink(sinkSchema, partitionKeys, sinkOptions);
+
+        // Construct expected sink
+        Properties dynamoDbClientProperties = new Properties();
+        dynamoDbClientProperties.putAll(sinkOptions);
+        DynamoDbDynamicSink expectedSink =
+                (DynamoDbDynamicSink)
+                        DynamoDbDynamicSink.builder()
+                                .setTableName(DYNAMO_DB_TABLE_NAME)
+                                .setOverwriteByPartitionKeys(new HashSet<>(partitionKeys))
+                                .setDynamoDbClientProperties(dynamoDbClientProperties)
+                                .setPhysicalDataType(sinkSchema.toPhysicalRowDataType())
+                                .build();
+
+        assertThat(actualSink).usingRecursiveComparison().isEqualTo(expectedSink);
+        assertThat(actualSink.getChangelogMode(ChangelogMode.insertOnly()))
+                .isEqualTo(ChangelogMode.upsert());

Review Comment:
   This seems odd, should we throw error here instead? Or support insertOnly to prevent deletion?
   



##########
flink-connector-dynamodb/src/test/java/org/apache/flink/connector/dynamodb/table/DynamoDbDynamicSinkFactoryTest.java:
##########
@@ -0,0 +1,267 @@
+package org.apache.flink.connector.dynamodb.table;
+
+import org.apache.flink.api.connector.sink2.Sink;
+import org.apache.flink.connector.dynamodb.sink.DynamoDbSink;
+import org.apache.flink.table.api.DataTypes;
+import org.apache.flink.table.api.ValidationException;
+import org.apache.flink.table.catalog.Column;
+import org.apache.flink.table.catalog.ResolvedSchema;
+import org.apache.flink.table.connector.ChangelogMode;
+import org.apache.flink.table.connector.sink.SinkV2Provider;
+import org.apache.flink.table.data.RowData;
+import org.apache.flink.table.factories.TableOptionsBuilder;
+import org.apache.flink.table.factories.TestFormatFactory;
+import org.apache.flink.table.runtime.connector.sink.SinkRuntimeProviderContext;
+
+import org.apache.flink.shaded.guava30.com.google.common.collect.ImmutableMap;
+
+import org.junit.jupiter.api.Test;
+
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Set;
+
+import static org.apache.flink.connector.base.table.AsyncSinkConnectorOptions.FLUSH_BUFFER_SIZE;
+import static org.apache.flink.connector.base.table.AsyncSinkConnectorOptions.FLUSH_BUFFER_TIMEOUT;
+import static org.apache.flink.connector.base.table.AsyncSinkConnectorOptions.MAX_BATCH_SIZE;
+import static org.apache.flink.connector.base.table.AsyncSinkConnectorOptions.MAX_BUFFERED_REQUESTS;
+import static org.apache.flink.connector.base.table.AsyncSinkConnectorOptions.MAX_IN_FLIGHT_REQUESTS;
+import static org.apache.flink.connector.dynamodb.table.DynamoDbConnectorOptions.FAIL_ON_ERROR;
+import static org.apache.flink.connector.dynamodb.table.DynamoDbConnectorOptions.TABLE_NAME;
+import static org.apache.flink.table.factories.utils.FactoryMocks.createTableSink;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
+
+/** Test for {@link DynamoDbDynamicSink} created by {@link DynamoDbDynamicSinkFactory}. */
+public class DynamoDbDynamicSinkFactoryTest {
+
+    private static final String DYNAMO_DB_TABLE_NAME = "TestDynamoDBTable";
+
+    @Test
+    void testGoodPartitionedTableSink() {
+        ResolvedSchema sinkSchema =
+                ResolvedSchema.of(
+                        Column.physical("partition_key", DataTypes.STRING()),
+                        Column.physical("sort_key", DataTypes.BIGINT()),
+                        Column.physical("payload", DataTypes.STRING()),
+                        Column.physical("some_char_array", DataTypes.ARRAY(DataTypes.CHAR(1))),
+                        Column.physical(
+                                "some_varchar_array", DataTypes.ARRAY(DataTypes.VARCHAR(1))),
+                        Column.physical("some_string_array", DataTypes.ARRAY(DataTypes.STRING())),
+                        Column.physical("some_boolean_array", DataTypes.ARRAY(DataTypes.BOOLEAN())),
+                        Column.physical(
+                                "some_decimal_array", DataTypes.ARRAY(DataTypes.DECIMAL(1, 1))),
+                        Column.physical("some_tinyint_array", DataTypes.ARRAY(DataTypes.TINYINT())),
+                        Column.physical(
+                                "some_smallint_array", DataTypes.ARRAY(DataTypes.SMALLINT())),
+                        Column.physical("some_int_array", DataTypes.ARRAY(DataTypes.INT())),
+                        Column.physical("some_bigint_array", DataTypes.ARRAY(DataTypes.BIGINT())),
+                        Column.physical("some_float_array", DataTypes.ARRAY(DataTypes.FLOAT())),
+                        Column.physical("some_date_array", DataTypes.ARRAY(DataTypes.DATE())),
+                        Column.physical("some_time_array", DataTypes.ARRAY(DataTypes.TIME())),
+                        Column.physical(
+                                "some_timestamp_array", DataTypes.ARRAY(DataTypes.TIMESTAMP())),
+                        Column.physical(
+                                "some_timestamp_ltz_array",
+                                DataTypes.ARRAY(DataTypes.TIMESTAMP_LTZ())),
+                        Column.physical(
+                                "some_map", DataTypes.MAP(DataTypes.STRING(), DataTypes.BIGINT())));

Review Comment:
   This would be more readable if extracted to a method, such as `createResolvedSchemaUsingAllDataTypes()`



##########
flink-connector-dynamodb/src/test/java/org/apache/flink/connector/dynamodb/table/RowDataElementConverterTest.java:
##########
@@ -0,0 +1,102 @@
+package org.apache.flink.connector.dynamodb.table;

Review Comment:
   Missing copyright header



##########
flink-connector-dynamodb/src/test/java/org/apache/flink/connector/dynamodb/table/RowDataElementConverterTest.java:
##########
@@ -0,0 +1,102 @@
+package org.apache.flink.connector.dynamodb.table;

Review Comment:
   Missing copyright header



-- 
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-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [flink-connector-aws] hlteoh37 commented on a diff in pull request #15: [FLINK-29900][Connectors/DynamoDB] Implement Table API for DynamoDB sink

Posted by GitBox <gi...@apache.org>.
hlteoh37 commented on code in PR #15:
URL: https://github.com/apache/flink-connector-aws/pull/15#discussion_r1026732902


##########
flink-sql-connector-dynamodb/pom.xml:
##########
@@ -77,12 +77,16 @@ under the License.
 									<include>org.apache.httpcomponents:*</include>
 									<include>io.netty:*</include>
 									<include>commons-logging:commons-logging</include>
+									<include>commons-codec:commons-codec</include>
 								</includes>
 							</artifactSet>
 							<relocations>
 								<relocation>
 									<pattern>software.amazon</pattern>
 									<shadedPattern>org.apache.flink.connector.dynamodb.shaded.software.amazon</shadedPattern>
+									<excludes>
+										<exclude>software.amazon.awssdk.enhanced.**</exclude>
+									</excludes>

Review Comment:
   We cannot shade these because EnhancedDynamoDB uses an additional interceptor in the AWS SDK chain. The ChainFactory resolves this a manner that the shade plugin doesn't handle properly.
   
   https://github.com/aws/aws-sdk-java-v2/blob/master/core/sdk-core/src/main/java/software/amazon/awssdk/core/interceptor/ClasspathInterceptorChainFactory.java#L42
   
   
   ```
   Caused by: java.lang.ClassNotFoundException: software.amazon.awssdk.enhanced.dynamodb.internal.ApplyUserAgentInterceptor
   	at java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:476)
   	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:589)
   	at org.apache.flink.util.FlinkUserCodeClassLoader.loadClassWithoutExceptionHandling(FlinkUserCodeClassLoader.java:68)
   	at org.apache.flink.util.ChildFirstClassLoader.loadClassWithoutExceptionHandling(ChildFirstClassLoader.java:74)
   	at org.apache.flink.util.FlinkUserCodeClassLoader.loadClass(FlinkUserCodeClassLoader.java:52)
   	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
   	at java.base/java.lang.Class.forName0(Native Method)
   	at java.base/java.lang.Class.forName(Class.java:315)
   	at org.apache.flink.streaming.connectors.dynamodb.shaded.software.amazon.awssdk.core.internal.util.ClassLoaderHelper.loadClass(ClassLoaderHelper.java:115)
   	at org.apache.flink.streaming.connectors.dynamodb.shaded.software.amazon.awssdk.core.internal.util.ClassLoaderHelper.loadClass(ClassLoaderHelper.java:74)
   	at org.apache.flink.streaming.connectors.dynamodb.shaded.software.amazon.awssdk.core.interceptor.ClasspathInterceptorChainFactory.createExecutionInterceptor(ClasspathInterceptorChainFactory.java:123)
   	... 37 more
   
   ```



-- 
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-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [flink-connector-aws] dannycranmer commented on a diff in pull request #15: [FLINK-29900][Connectors/DynamoDB] Implement Table API for DynamoDB sink

Posted by GitBox <gi...@apache.org>.
dannycranmer commented on code in PR #15:
URL: https://github.com/apache/flink-connector-aws/pull/15#discussion_r1029044391


##########
flink-sql-connector-dynamodb/pom.xml:
##########
@@ -77,6 +77,7 @@ under the License.
 									<include>org.apache.httpcomponents:*</include>
 									<include>io.netty:*</include>
 									<include>commons-logging:commons-logging</include>
+									<include>commons-codec:commons-codec</include>

Review Comment:
   Looks like we will need to update the notice file for this



-- 
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-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [flink-connector-aws] dannycranmer commented on a diff in pull request #15: [FLINK-29900][Connectors/DynamoDB] Implement Table API for DynamoDB sink

Posted by GitBox <gi...@apache.org>.
dannycranmer commented on code in PR #15:
URL: https://github.com/apache/flink-connector-aws/pull/15#discussion_r1021656848


##########
flink-connector-dynamodb/src/main/java/org/apache/flink/connector/dynamodb/table/DynamoDbConfiguration.java:
##########
@@ -0,0 +1,24 @@
+package org.apache.flink.connector.dynamodb.table;
+
+import org.apache.flink.configuration.ReadableConfig;
+
+import static org.apache.flink.connector.dynamodb.table.DynamoDbConnectorOptions.FAIL_ON_ERROR;
+import static org.apache.flink.connector.dynamodb.table.DynamoDbConnectorOptions.TABLE_NAME;
+
+/** DynamoDb specific configuration. */
+public class DynamoDbConfiguration {

Review Comment:
   Missing support annotation. Please make non-test classes have `@Internal/@PublicEvolving` annotation



##########
flink-connector-dynamodb/src/main/java/org/apache/flink/connector/dynamodb/table/DynamoDbConnectorOptions.java:
##########
@@ -0,0 +1,28 @@
+package org.apache.flink.connector.dynamodb.table;
+
+import org.apache.flink.configuration.ConfigOption;
+import org.apache.flink.configuration.ConfigOptions;
+
+/**
+ * Base options for the DynamoDb connector. Needs to be public so that the {@link
+ * org.apache.flink.table.api.TableDescriptor} can access it.

Review Comment:
   nit: add an import for TableDescriptor and simplify comment



##########
flink-connector-dynamodb/pom.xml:
##########
@@ -77,6 +77,22 @@ under the License.
 			<artifactId>dynamodb-enhanced</artifactId>
 		</dependency>
 
+		<!-- Table ecosystem -->
+		<dependency>
+			<groupId>org.apache.flink</groupId>
+			<artifactId>flink-table-api-java-bridge</artifactId>
+			<version>${flink.version}</version>
+			<scope>provided</scope>
+			<optional>true</optional>
+		</dependency>
+		<dependency>
+            <groupId>org.apache.flink</groupId>
+            <artifactId>flink-table-runtime</artifactId>
+            <version>${flink.version}</version>
+            <scope>provided</scope>
+            <optional>true</optional>
+        </dependency>

Review Comment:
   Formatting looks squiffy 



##########
flink-connector-dynamodb/src/main/java/org/apache/flink/connector/dynamodb/table/DynamoDbConnectorOptions.java:
##########
@@ -0,0 +1,28 @@
+package org.apache.flink.connector.dynamodb.table;
+
+import org.apache.flink.configuration.ConfigOption;
+import org.apache.flink.configuration.ConfigOptions;
+
+/**
+ * Base options for the DynamoDb connector. Needs to be public so that the {@link
+ * org.apache.flink.table.api.TableDescriptor} can access it.
+ */
+public class DynamoDbConnectorOptions {
+
+    private DynamoDbConnectorOptions() {
+        // private constructor to prevent initialization of static class
+    }
+
+    public static final ConfigOption<String> TABLE_NAME =
+            ConfigOptions.key("table")

Review Comment:
   Should we keep this consistent with the DataStream field? `destination-table-name` or rename both to `table-name`?



##########
flink-connector-dynamodb/src/main/java/org/apache/flink/connector/dynamodb/table/RowDataElementConverter.java:
##########
@@ -0,0 +1,50 @@
+package org.apache.flink.connector.dynamodb.table;
+
+import org.apache.flink.api.connector.sink2.SinkWriter;
+import org.apache.flink.connector.base.sink.writer.ElementConverter;
+import org.apache.flink.connector.dynamodb.sink.DynamoDbWriteRequest;
+import org.apache.flink.connector.dynamodb.sink.DynamoDbWriteRequestType;
+import org.apache.flink.table.api.TableException;
+import org.apache.flink.table.data.RowData;
+import org.apache.flink.table.types.DataType;
+
+/** Implementation of an {@link ElementConverter} specific for DynamoDb sink. */

Review Comment:
   Please elaborate here



##########
flink-connector-dynamodb/src/main/java/org/apache/flink/connector/dynamodb/table/DynamoDbConfiguration.java:
##########
@@ -0,0 +1,24 @@
+package org.apache.flink.connector.dynamodb.table;

Review Comment:
   Missing copyright, please check all other files too



##########
flink-connector-dynamodb/src/main/java/org/apache/flink/connector/dynamodb/table/DynamoDbDynamicSinkFactory.java:
##########
@@ -0,0 +1,53 @@
+package org.apache.flink.connector.dynamodb.table;
+
+import org.apache.flink.configuration.ConfigOption;
+import org.apache.flink.connector.base.table.AsyncDynamicTableSinkFactory;
+import org.apache.flink.table.catalog.ResolvedCatalogTable;
+import org.apache.flink.table.connector.sink.DynamicTableSink;
+import org.apache.flink.table.factories.FactoryUtil;
+
+import org.apache.flink.shaded.guava30.com.google.common.collect.ImmutableSet;
+
+import java.util.HashSet;
+import java.util.Properties;
+import java.util.Set;
+
+import static org.apache.flink.connector.dynamodb.table.DynamoDbConnectorOptions.TABLE_NAME;
+
+/** */

Review Comment:
   todo



##########
flink-connector-dynamodb/src/main/java/org/apache/flink/connector/dynamodb/table/RowDataElementConverter.java:
##########
@@ -0,0 +1,50 @@
+package org.apache.flink.connector.dynamodb.table;
+
+import org.apache.flink.api.connector.sink2.SinkWriter;
+import org.apache.flink.connector.base.sink.writer.ElementConverter;
+import org.apache.flink.connector.dynamodb.sink.DynamoDbWriteRequest;
+import org.apache.flink.connector.dynamodb.sink.DynamoDbWriteRequestType;
+import org.apache.flink.table.api.TableException;
+import org.apache.flink.table.data.RowData;
+import org.apache.flink.table.types.DataType;
+
+/** Implementation of an {@link ElementConverter} specific for DynamoDb sink. */
+public class RowDataElementConverter implements ElementConverter<RowData, DynamoDbWriteRequest> {
+
+    private final DataType physicalDataType;
+    private final RowDataToAttributeValueConverter rowDataToAttributeValueConverter;
+
+    public RowDataElementConverter(DataType physicalDataType) {
+        this.physicalDataType = physicalDataType;
+        this.rowDataToAttributeValueConverter =
+                new RowDataToAttributeValueConverter(physicalDataType);
+    }
+
+    @Override
+    public DynamoDbWriteRequest apply(RowData element, SinkWriter.Context context) {
+        switch (element.getRowKind()) {
+            case INSERT:
+            case UPDATE_AFTER:
+                return getPutRequest(element);
+            case UPDATE_BEFORE:

Review Comment:
   Why does `UPDATE_BEFORE` map to delete?



##########
flink-connector-dynamodb/src/main/java/org/apache/flink/connector/dynamodb/table/DynamoDbDynamicSink.java:
##########
@@ -0,0 +1,198 @@
+package org.apache.flink.connector.dynamodb.table;
+
+import org.apache.flink.annotation.Internal;
+import org.apache.flink.connector.base.table.sink.AsyncDynamicTableSink;
+import org.apache.flink.connector.base.table.sink.AsyncDynamicTableSinkBuilder;
+import org.apache.flink.connector.dynamodb.sink.DynamoDbSink;
+import org.apache.flink.connector.dynamodb.sink.DynamoDbSinkBuilder;
+import org.apache.flink.connector.dynamodb.sink.DynamoDbWriteRequest;
+import org.apache.flink.table.connector.ChangelogMode;
+import org.apache.flink.table.connector.sink.DynamicTableSink;
+import org.apache.flink.table.connector.sink.SinkV2Provider;
+import org.apache.flink.table.connector.sink.abilities.SupportsPartitioning;
+import org.apache.flink.table.data.RowData;
+import org.apache.flink.table.types.DataType;
+
+import javax.annotation.Nullable;
+
+import java.util.ArrayList;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Properties;
+import java.util.Set;
+
+/**
+ * A {@link DynamicTableSink} that describes how to create a {@link DynamoDbSink} from a logical
+ * description.
+ */
+@Internal
+public class DynamoDbDynamicSink extends AsyncDynamicTableSink<DynamoDbWriteRequest>
+        implements SupportsPartitioning {
+
+    private final String destinationTableName;
+    private final boolean failOnError;
+    private final Properties dynamoDbClientProperties;
+    private final DataType physicalDataType;
+    private final Set<String> overwriteByPartitionKeys;
+
+    protected DynamoDbDynamicSink(
+            @Nullable Integer maxBatchSize,
+            @Nullable Integer maxInFlightRequests,
+            @Nullable Integer maxBufferedRequests,
+            @Nullable Long maxBufferSizeInBytes,
+            @Nullable Long maxTimeInBufferMS,
+            String destinationTableName,
+            boolean failOnError,
+            Properties dynamoDbClientProperties,
+            DataType physicalDataType,
+            Set<String> overwriteByPartitionKeys) {
+        super(
+                maxBatchSize,
+                maxInFlightRequests,
+                maxBufferedRequests,
+                maxBufferSizeInBytes,
+                maxTimeInBufferMS);
+        this.destinationTableName = destinationTableName;
+        this.failOnError = failOnError;
+        this.dynamoDbClientProperties = dynamoDbClientProperties;
+        this.physicalDataType = physicalDataType;
+        this.overwriteByPartitionKeys = overwriteByPartitionKeys;
+    }
+
+    @Override
+    public ChangelogMode getChangelogMode(ChangelogMode changelogMode) {
+        // TODO: We can support consuming from CDC streams here
+        return ChangelogMode.insertOnly();
+    }
+
+    @Override
+    public SinkRuntimeProvider getSinkRuntimeProvider(Context context) {
+        DynamoDbSinkBuilder<RowData> builder =
+                DynamoDbSink.<RowData>builder()
+                        .setDestinationTableName(destinationTableName)
+                        .setFailOnError(failOnError)
+                        .setOverwriteByPartitionKeys(new ArrayList<>(overwriteByPartitionKeys))
+                        .setDynamoDbProperties(dynamoDbClientProperties)
+                        .setElementConverter(new RowDataElementConverter(physicalDataType));
+
+        addAsyncOptionsToSinkBuilder(builder);
+
+        // TODO: check if parallelism needed here
+        return SinkV2Provider.of(builder.build());
+    }
+
+    @Override
+    public DynamicTableSink copy() {
+        return new DynamoDbDynamicSink(
+                maxBatchSize,
+                maxInFlightRequests,
+                maxBufferedRequests,
+                maxBufferSizeInBytes,
+                maxTimeInBufferMS,
+                destinationTableName,
+                failOnError,
+                dynamoDbClientProperties,
+                physicalDataType,
+                overwriteByPartitionKeys);
+    }
+
+    @Override
+    public String asSummaryString() {
+        // TODO: check when this is called/returned
+        return "DynamoDB";
+    }
+
+    @Override
+    public void applyStaticPartition(Map<String, String> partitions) {
+        this.overwriteByPartitionKeys.addAll(partitions.keySet());
+    }
+
+    public static DynamoDbDynamicTableSinkBuilder builder() {
+        return new DynamoDbDynamicTableSinkBuilder();
+    }
+
+    @Override
+    public boolean equals(Object o) {
+        if (this == o) {
+            return true;
+        }
+        if (o == null || getClass() != o.getClass()) {
+            return false;
+        }
+        if (!super.equals(o)) {
+            return false;
+        }
+        DynamoDbDynamicSink that = (DynamoDbDynamicSink) o;
+        return failOnError == that.failOnError
+                && Objects.equals(destinationTableName, that.destinationTableName)
+                && Objects.equals(dynamoDbClientProperties, that.dynamoDbClientProperties)
+                && Objects.equals(physicalDataType, that.physicalDataType)
+                && Objects.equals(overwriteByPartitionKeys, that.overwriteByPartitionKeys);
+    }
+
+    @Override
+    public int hashCode() {
+        return Objects.hash(
+                super.hashCode(),
+                destinationTableName,
+                failOnError,
+                dynamoDbClientProperties,
+                physicalDataType,
+                overwriteByPartitionKeys);
+    }

Review Comment:
   Why are these needed? Please review https://flink.apache.org/contributing/code-style-and-quality-java.html#equals--hashcode and remove if we can



##########
flink-connector-dynamodb/src/main/java/org/apache/flink/connector/dynamodb/table/RowDataToAttributeValueConverter.java:
##########
@@ -0,0 +1,72 @@
+package org.apache.flink.connector.dynamodb.table;
+
+import org.apache.flink.table.api.DataTypes;
+import org.apache.flink.table.data.RowData;
+import org.apache.flink.table.data.conversion.DataStructureConverters;
+import org.apache.flink.table.types.DataType;
+
+import software.amazon.awssdk.enhanced.dynamodb.TableSchema;
+import software.amazon.awssdk.enhanced.dynamodb.mapper.StaticTableSchema;
+import software.amazon.awssdk.services.dynamodb.model.AttributeValue;
+
+import java.io.Serializable;
+import java.util.List;
+import java.util.Map;
+
+import static org.apache.flink.table.data.RowData.createFieldGetter;
+
+/** Converts from {@link RowData} to {@link AttributeValue}. */
+public class RowDataToAttributeValueConverter implements Serializable {
+    private static final long serialVersionUID = 1L;
+
+    private final DataType physicalDataType;
+    private transient TableSchema<RowData> tableSchema;
+
+    public RowDataToAttributeValueConverter(DataType physicalDataType) {
+        this.physicalDataType = physicalDataType;
+        this.tableSchema = createTableSchema();
+    }
+
+    private StaticTableSchema<RowData> createTableSchema() {
+        List<DataTypes.Field> fields = DataType.getFields(physicalDataType);
+        StaticTableSchema.Builder<RowData> builder = TableSchema.builder(RowData.class);
+        for (int i = 0; i < fields.size(); i++) {
+            DataTypes.Field field = fields.get(i);
+            RowData.FieldGetter fieldGetter =
+                    createFieldGetter(field.getDataType().getLogicalType(), i);
+
+            builder =
+                    addAttribute(
+                            builder, field.getDataType().getConversionClass(), field, fieldGetter);
+        }
+        return builder.build();
+    }
+
+    private <T> StaticTableSchema.Builder<RowData> addAttribute(
+            StaticTableSchema.Builder<RowData> builder,
+            Class<T> convertedClass,
+            DataTypes.Field field,
+            RowData.FieldGetter fieldGetter) {
+
+        return builder.addAttribute(
+                convertedClass,
+                a ->
+                        a.name(field.getName())
+                                .getter(
+                                        rowData ->
+                                                (T)
+                                                        DataStructureConverters.getConverter(
+                                                                        field.getDataType())
+                                                                .toExternal(
+                                                                        fieldGetter.getFieldOrNull(
+                                                                                rowData)))
+                                .setter(((rowData, t) -> {})));
+    }
+
+    public Map<String, AttributeValue> convertRowData(RowData row) {

Review Comment:
   nit: Public methods should typically go above private, for readability



##########
flink-connector-dynamodb/src/main/java/org/apache/flink/connector/dynamodb/table/RowDataToAttributeValueConverter.java:
##########
@@ -0,0 +1,72 @@
+package org.apache.flink.connector.dynamodb.table;
+
+import org.apache.flink.table.api.DataTypes;
+import org.apache.flink.table.data.RowData;
+import org.apache.flink.table.data.conversion.DataStructureConverters;
+import org.apache.flink.table.types.DataType;
+
+import software.amazon.awssdk.enhanced.dynamodb.TableSchema;
+import software.amazon.awssdk.enhanced.dynamodb.mapper.StaticTableSchema;
+import software.amazon.awssdk.services.dynamodb.model.AttributeValue;
+
+import java.io.Serializable;
+import java.util.List;
+import java.util.Map;
+
+import static org.apache.flink.table.data.RowData.createFieldGetter;
+
+/** Converts from {@link RowData} to {@link AttributeValue}. */
+public class RowDataToAttributeValueConverter implements Serializable {
+    private static final long serialVersionUID = 1L;
+
+    private final DataType physicalDataType;
+    private transient TableSchema<RowData> tableSchema;
+
+    public RowDataToAttributeValueConverter(DataType physicalDataType) {
+        this.physicalDataType = physicalDataType;
+        this.tableSchema = createTableSchema();
+    }
+
+    private StaticTableSchema<RowData> createTableSchema() {
+        List<DataTypes.Field> fields = DataType.getFields(physicalDataType);
+        StaticTableSchema.Builder<RowData> builder = TableSchema.builder(RowData.class);
+        for (int i = 0; i < fields.size(); i++) {
+            DataTypes.Field field = fields.get(i);
+            RowData.FieldGetter fieldGetter =
+                    createFieldGetter(field.getDataType().getLogicalType(), i);
+
+            builder =
+                    addAttribute(
+                            builder, field.getDataType().getConversionClass(), field, fieldGetter);
+        }
+        return builder.build();
+    }
+
+    private <T> StaticTableSchema.Builder<RowData> addAttribute(
+            StaticTableSchema.Builder<RowData> builder,
+            Class<T> convertedClass,
+            DataTypes.Field field,
+            RowData.FieldGetter fieldGetter) {
+
+        return builder.addAttribute(
+                convertedClass,
+                a ->
+                        a.name(field.getName())
+                                .getter(
+                                        rowData ->
+                                                (T)
+                                                        DataStructureConverters.getConverter(
+                                                                        field.getDataType())
+                                                                .toExternal(
+                                                                        fieldGetter.getFieldOrNull(
+                                                                                rowData)))
+                                .setter(((rowData, t) -> {})));
+    }

Review Comment:
   Yikes, spotless added some spots here :/ 



##########
flink-connector-dynamodb/src/main/java/org/apache/flink/connector/dynamodb/table/RowDataElementConverter.java:
##########
@@ -0,0 +1,50 @@
+package org.apache.flink.connector.dynamodb.table;
+
+import org.apache.flink.api.connector.sink2.SinkWriter;
+import org.apache.flink.connector.base.sink.writer.ElementConverter;
+import org.apache.flink.connector.dynamodb.sink.DynamoDbWriteRequest;
+import org.apache.flink.connector.dynamodb.sink.DynamoDbWriteRequestType;
+import org.apache.flink.table.api.TableException;
+import org.apache.flink.table.data.RowData;
+import org.apache.flink.table.types.DataType;
+
+/** Implementation of an {@link ElementConverter} specific for DynamoDb sink. */
+public class RowDataElementConverter implements ElementConverter<RowData, DynamoDbWriteRequest> {
+
+    private final DataType physicalDataType;
+    private final RowDataToAttributeValueConverter rowDataToAttributeValueConverter;
+
+    public RowDataElementConverter(DataType physicalDataType) {
+        this.physicalDataType = physicalDataType;
+        this.rowDataToAttributeValueConverter =
+                new RowDataToAttributeValueConverter(physicalDataType);
+    }
+
+    @Override
+    public DynamoDbWriteRequest apply(RowData element, SinkWriter.Context context) {
+        switch (element.getRowKind()) {
+            case INSERT:
+            case UPDATE_AFTER:
+                return getPutRequest(element);
+            case UPDATE_BEFORE:
+            case DELETE:
+                return getDeleteRequest(element);
+            default:
+                throw new TableException("Unsupported message kind: " + element.getRowKind());
+        }
+    }
+
+    private DynamoDbWriteRequest getPutRequest(RowData row) {
+        return DynamoDbWriteRequest.builder()
+                .setType(DynamoDbWriteRequestType.PUT)
+                .setItem(rowDataToAttributeValueConverter.convertRowData(row))
+                .build();
+    }
+
+    private DynamoDbWriteRequest getDeleteRequest(RowData row) {
+        return DynamoDbWriteRequest.builder()
+                .setType(DynamoDbWriteRequestType.DELETE)
+                .setItem(rowDataToAttributeValueConverter.convertRowData(row))
+                .build();
+    }

Review Comment:
   nit: I like this, however you could create the builder in the previous method
   
   ```
   @Override
       public DynamoDbWriteRequest apply(RowData element, SinkWriter.Context context) {
         var builder = DynamoDbWriteRequest.builder()
                   .setItem(rowDataToAttributeValueConverter.convertRowData(row));
       
           switch (element.getRowKind()) {
               case INSERT:
               case UPDATE_AFTER:
                   builder.setType(DynamoDbWriteRequestType.PUT);
               case UPDATE_BEFORE:
               case DELETE:
                   builder.setType(DynamoDbWriteRequestType.DELETE);
               default:
                   throw new TableException("Unsupported message kind: " + element.getRowKind());
           }
   
         return builder.build();
       }
   ```



##########
flink-connector-dynamodb/src/main/java/org/apache/flink/connector/dynamodb/table/DynamoDbDynamicSink.java:
##########
@@ -0,0 +1,198 @@
+package org.apache.flink.connector.dynamodb.table;
+
+import org.apache.flink.annotation.Internal;
+import org.apache.flink.connector.base.table.sink.AsyncDynamicTableSink;
+import org.apache.flink.connector.base.table.sink.AsyncDynamicTableSinkBuilder;
+import org.apache.flink.connector.dynamodb.sink.DynamoDbSink;
+import org.apache.flink.connector.dynamodb.sink.DynamoDbSinkBuilder;
+import org.apache.flink.connector.dynamodb.sink.DynamoDbWriteRequest;
+import org.apache.flink.table.connector.ChangelogMode;
+import org.apache.flink.table.connector.sink.DynamicTableSink;
+import org.apache.flink.table.connector.sink.SinkV2Provider;
+import org.apache.flink.table.connector.sink.abilities.SupportsPartitioning;
+import org.apache.flink.table.data.RowData;
+import org.apache.flink.table.types.DataType;
+
+import javax.annotation.Nullable;
+
+import java.util.ArrayList;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Properties;
+import java.util.Set;
+
+/**
+ * A {@link DynamicTableSink} that describes how to create a {@link DynamoDbSink} from a logical
+ * description.
+ */
+@Internal
+public class DynamoDbDynamicSink extends AsyncDynamicTableSink<DynamoDbWriteRequest>
+        implements SupportsPartitioning {
+
+    private final String destinationTableName;
+    private final boolean failOnError;
+    private final Properties dynamoDbClientProperties;
+    private final DataType physicalDataType;
+    private final Set<String> overwriteByPartitionKeys;
+
+    protected DynamoDbDynamicSink(
+            @Nullable Integer maxBatchSize,
+            @Nullable Integer maxInFlightRequests,
+            @Nullable Integer maxBufferedRequests,
+            @Nullable Long maxBufferSizeInBytes,
+            @Nullable Long maxTimeInBufferMS,
+            String destinationTableName,
+            boolean failOnError,
+            Properties dynamoDbClientProperties,
+            DataType physicalDataType,
+            Set<String> overwriteByPartitionKeys) {
+        super(
+                maxBatchSize,
+                maxInFlightRequests,
+                maxBufferedRequests,
+                maxBufferSizeInBytes,
+                maxTimeInBufferMS);
+        this.destinationTableName = destinationTableName;
+        this.failOnError = failOnError;
+        this.dynamoDbClientProperties = dynamoDbClientProperties;
+        this.physicalDataType = physicalDataType;
+        this.overwriteByPartitionKeys = overwriteByPartitionKeys;
+    }
+
+    @Override
+    public ChangelogMode getChangelogMode(ChangelogMode changelogMode) {
+        // TODO: We can support consuming from CDC streams here
+        return ChangelogMode.insertOnly();
+    }
+
+    @Override
+    public SinkRuntimeProvider getSinkRuntimeProvider(Context context) {
+        DynamoDbSinkBuilder<RowData> builder =
+                DynamoDbSink.<RowData>builder()
+                        .setDestinationTableName(destinationTableName)
+                        .setFailOnError(failOnError)
+                        .setOverwriteByPartitionKeys(new ArrayList<>(overwriteByPartitionKeys))
+                        .setDynamoDbProperties(dynamoDbClientProperties)
+                        .setElementConverter(new RowDataElementConverter(physicalDataType));
+
+        addAsyncOptionsToSinkBuilder(builder);
+
+        // TODO: check if parallelism needed here
+        return SinkV2Provider.of(builder.build());
+    }
+
+    @Override
+    public DynamicTableSink copy() {
+        return new DynamoDbDynamicSink(
+                maxBatchSize,
+                maxInFlightRequests,
+                maxBufferedRequests,
+                maxBufferSizeInBytes,
+                maxTimeInBufferMS,
+                destinationTableName,
+                failOnError,
+                dynamoDbClientProperties,
+                physicalDataType,
+                overwriteByPartitionKeys);
+    }
+
+    @Override
+    public String asSummaryString() {
+        // TODO: check when this is called/returned
+        return "DynamoDB";
+    }
+
+    @Override
+    public void applyStaticPartition(Map<String, String> partitions) {
+        this.overwriteByPartitionKeys.addAll(partitions.keySet());

Review Comment:
   nit: remove `this`



-- 
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-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [flink-connector-aws] dannycranmer commented on a diff in pull request #15: [FLINK-29900][Connectors/DynamoDB] Implement Table API for DynamoDB sink

Posted by GitBox <gi...@apache.org>.
dannycranmer commented on code in PR #15:
URL: https://github.com/apache/flink-connector-aws/pull/15#discussion_r1026638166


##########
flink-sql-connector-dynamodb/pom.xml:
##########
@@ -77,12 +77,16 @@ under the License.
 									<include>org.apache.httpcomponents:*</include>
 									<include>io.netty:*</include>
 									<include>commons-logging:commons-logging</include>
+									<include>commons-codec:commons-codec</include>
 								</includes>
 							</artifactSet>
 							<relocations>
 								<relocation>
 									<pattern>software.amazon</pattern>
 									<shadedPattern>org.apache.flink.connector.dynamodb.shaded.software.amazon</shadedPattern>
+									<excludes>
+										<exclude>software.amazon.awssdk.enhanced.**</exclude>
+									</excludes>

Review Comment:
   Why are these not relocated?



-- 
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-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [flink-connector-aws] hlteoh37 commented on a diff in pull request #15: [FLINK-29900][Connectors/DynamoDB] Implement Table API for DynamoDB sink

Posted by GitBox <gi...@apache.org>.
hlteoh37 commented on code in PR #15:
URL: https://github.com/apache/flink-connector-aws/pull/15#discussion_r1026762714


##########
flink-connector-dynamodb/src/test/java/org/apache/flink/connector/dynamodb/table/DynamoDbDynamicSinkFactoryTest.java:
##########
@@ -0,0 +1,267 @@
+package org.apache.flink.connector.dynamodb.table;
+
+import org.apache.flink.api.connector.sink2.Sink;
+import org.apache.flink.connector.dynamodb.sink.DynamoDbSink;
+import org.apache.flink.table.api.DataTypes;
+import org.apache.flink.table.api.ValidationException;
+import org.apache.flink.table.catalog.Column;
+import org.apache.flink.table.catalog.ResolvedSchema;
+import org.apache.flink.table.connector.ChangelogMode;
+import org.apache.flink.table.connector.sink.SinkV2Provider;
+import org.apache.flink.table.data.RowData;
+import org.apache.flink.table.factories.TableOptionsBuilder;
+import org.apache.flink.table.factories.TestFormatFactory;
+import org.apache.flink.table.runtime.connector.sink.SinkRuntimeProviderContext;
+
+import org.apache.flink.shaded.guava30.com.google.common.collect.ImmutableMap;
+
+import org.junit.jupiter.api.Test;
+
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Set;
+
+import static org.apache.flink.connector.base.table.AsyncSinkConnectorOptions.FLUSH_BUFFER_SIZE;
+import static org.apache.flink.connector.base.table.AsyncSinkConnectorOptions.FLUSH_BUFFER_TIMEOUT;
+import static org.apache.flink.connector.base.table.AsyncSinkConnectorOptions.MAX_BATCH_SIZE;
+import static org.apache.flink.connector.base.table.AsyncSinkConnectorOptions.MAX_BUFFERED_REQUESTS;
+import static org.apache.flink.connector.base.table.AsyncSinkConnectorOptions.MAX_IN_FLIGHT_REQUESTS;
+import static org.apache.flink.connector.dynamodb.table.DynamoDbConnectorOptions.FAIL_ON_ERROR;
+import static org.apache.flink.connector.dynamodb.table.DynamoDbConnectorOptions.TABLE_NAME;
+import static org.apache.flink.table.factories.utils.FactoryMocks.createTableSink;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
+
+/** Test for {@link DynamoDbDynamicSink} created by {@link DynamoDbDynamicSinkFactory}. */
+public class DynamoDbDynamicSinkFactoryTest {
+
+    private static final String DYNAMO_DB_TABLE_NAME = "TestDynamoDBTable";
+
+    @Test
+    void testGoodPartitionedTableSink() {
+        ResolvedSchema sinkSchema =
+                ResolvedSchema.of(
+                        Column.physical("partition_key", DataTypes.STRING()),
+                        Column.physical("sort_key", DataTypes.BIGINT()),
+                        Column.physical("payload", DataTypes.STRING()),
+                        Column.physical("some_char_array", DataTypes.ARRAY(DataTypes.CHAR(1))),
+                        Column.physical(
+                                "some_varchar_array", DataTypes.ARRAY(DataTypes.VARCHAR(1))),
+                        Column.physical("some_string_array", DataTypes.ARRAY(DataTypes.STRING())),
+                        Column.physical("some_boolean_array", DataTypes.ARRAY(DataTypes.BOOLEAN())),
+                        Column.physical(
+                                "some_decimal_array", DataTypes.ARRAY(DataTypes.DECIMAL(1, 1))),
+                        Column.physical("some_tinyint_array", DataTypes.ARRAY(DataTypes.TINYINT())),
+                        Column.physical(
+                                "some_smallint_array", DataTypes.ARRAY(DataTypes.SMALLINT())),
+                        Column.physical("some_int_array", DataTypes.ARRAY(DataTypes.INT())),
+                        Column.physical("some_bigint_array", DataTypes.ARRAY(DataTypes.BIGINT())),
+                        Column.physical("some_float_array", DataTypes.ARRAY(DataTypes.FLOAT())),
+                        Column.physical("some_date_array", DataTypes.ARRAY(DataTypes.DATE())),
+                        Column.physical("some_time_array", DataTypes.ARRAY(DataTypes.TIME())),
+                        Column.physical(
+                                "some_timestamp_array", DataTypes.ARRAY(DataTypes.TIMESTAMP())),
+                        Column.physical(
+                                "some_timestamp_ltz_array",
+                                DataTypes.ARRAY(DataTypes.TIMESTAMP_LTZ())),
+                        Column.physical(
+                                "some_map", DataTypes.MAP(DataTypes.STRING(), DataTypes.BIGINT())));
+        Map<String, String> sinkOptions = defaultSinkOptions().build();
+        List<String> partitionKeys = Collections.singletonList("partition_key");
+
+        // Construct actual sink
+        DynamoDbDynamicSink actualSink =
+                (DynamoDbDynamicSink) createTableSink(sinkSchema, partitionKeys, sinkOptions);
+
+        // Construct expected sink
+        Properties dynamoDbClientProperties = new Properties();
+        dynamoDbClientProperties.putAll(sinkOptions);
+        DynamoDbDynamicSink expectedSink =
+                (DynamoDbDynamicSink)
+                        DynamoDbDynamicSink.builder()
+                                .setTableName(DYNAMO_DB_TABLE_NAME)
+                                .setOverwriteByPartitionKeys(new HashSet<>(partitionKeys))
+                                .setDynamoDbClientProperties(dynamoDbClientProperties)
+                                .setPhysicalDataType(sinkSchema.toPhysicalRowDataType())
+                                .build();
+
+        assertThat(actualSink).usingRecursiveComparison().isEqualTo(expectedSink);
+        assertThat(actualSink.getChangelogMode(ChangelogMode.insertOnly()))
+                .isEqualTo(ChangelogMode.upsert());

Review Comment:
   The interface for `getChangelogMode()` says :
   > When writing a dynamic table, the content can always be considered as a changelog (finite or infinite) for which all changes are written out continuously until the changelog is exhausted. The given ChangelogMode indicates the set of changes that the sink accepts during runtime.
   
   I take this to mean that this method should return the mode that the sink supports. As such, we ignore the "requested" changelog mode given by the table planner.



-- 
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-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org