dannycranmer commented on code in PR #1:
URL: 
https://github.com/apache/flink-connector-dynamodb/pull/1#discussion_r1013066455


##########
flink-connector-dynamodb/src/main/java/org/apache/flink/streaming/connectors/dynamodb/sink/InvalidRequestException.java:
##########
@@ -0,0 +1,26 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.streaming.connectors.dynamodb.sink;
+
+/** Exception is thrown if a DynamoDB request was invalid. */
+public class InvalidRequestException extends RuntimeException {

Review Comment:
   Missing `@PublicEvolving`



##########
flink-connector-dynamodb/src/main/java/org/apache/flink/streaming/connectors/dynamodb/util/DynamoDbSerializationUtil.java:
##########
@@ -0,0 +1,196 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.streaming.connectors.dynamodb.util;
+
+import org.apache.flink.annotation.Internal;
+import 
org.apache.flink.streaming.connectors.dynamodb.sink.DynamoDbWriteRequest;
+import 
org.apache.flink.streaming.connectors.dynamodb.sink.DynamoDbWriteRequestType;
+
+import software.amazon.awssdk.core.SdkBytes;
+import software.amazon.awssdk.services.dynamodb.model.AttributeValue;
+
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Serialization Utils for DynamoDb {@link AttributeValue}. This class is 
currently not
+ * serializable, see <a 
href="https://github.com/aws/aws-sdk-java-v2/issues/3143";>open issue</a>
+ */
+@Internal
+public class DynamoDbSerializationUtil {
+
+    public static void serializeWriteRequest(
+            DynamoDbWriteRequest dynamoDbWriteRequest, DataOutputStream out) 
throws IOException {
+        out.writeByte(dynamoDbWriteRequest.getType().toByteValue());
+        Map<String, AttributeValue> item = dynamoDbWriteRequest.getItem();
+        serializeItem(item, out);
+    }
+
+    public static DynamoDbWriteRequest deserializeWriteRequest(DataInputStream 
in)
+            throws IOException {
+        int writeRequestType = in.read();
+        DynamoDbWriteRequestType dynamoDbWriteRequestType =
+                DynamoDbWriteRequestType.fromByteValue((byte) 
writeRequestType);
+        Map<String, AttributeValue> item = deserializeItem(in);
+        return DynamoDbWriteRequest.builder()
+                .setType(dynamoDbWriteRequestType)
+                .setItem(item)
+                .build();
+    }
+
+    private static void serializeItem(Map<String, AttributeValue> item, 
DataOutputStream out)
+            throws IOException {
+        out.writeInt(item.size());
+        for (Map.Entry<String, AttributeValue> entry : item.entrySet()) {
+            out.writeUTF(entry.getKey());
+            AttributeValue value = entry.getValue();
+            serializeAttributeValue(value, out);
+        }
+    }
+
+    private static void serializeAttributeValue(AttributeValue value, 
DataOutputStream out)
+            throws IOException {
+        if (value.nul() != null) {
+            out.writeByte(DynamoDbType.NULL.toByteValue());
+        } else if (value.bool() != null) {
+            out.writeByte(DynamoDbType.BOOLEAN.toByteValue());
+            out.writeBoolean(value.bool());
+        } else if (value.s() != null) {
+            out.writeByte(DynamoDbType.STRING.toByteValue());
+            out.writeUTF(value.s());
+        } else if (value.n() != null) {
+            out.writeByte(DynamoDbType.NUMBER.toByteValue());
+            out.writeUTF(value.n());
+        } else if (value.b() != null) {
+            out.writeByte(DynamoDbType.BINARY.toByteValue());
+            out.writeInt(value.b().asByteArrayUnsafe().length);
+            out.write(value.b().asByteArrayUnsafe());

Review Comment:
   Does `asByteArrayUnsafe` result in a new byte array getting created? If so, 
can we extract to reduce this happening twice



##########
flink-connector-dynamodb/src/main/java/org/apache/flink/streaming/connectors/dynamodb/sink/DynamoDbSinkException.java:
##########
@@ -0,0 +1,48 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.streaming.connectors.dynamodb.sink;
+
+/** Exception is thrown when DynamoDb sink failed to write data. */
+public class DynamoDbSinkException extends RuntimeException {

Review Comment:
   I see the annotations were recently removed, why was this? 
https://github.com/apache/flink-connector-dynamodb/pull/1/commits/598373ace67c96e1e7fb466f60129f8475738bf9



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscr...@flink.apache.org

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

Reply via email to