hlteoh37 commented on code in PR #146:
URL: 
https://github.com/apache/flink-connector-aws/pull/146#discussion_r1671824937


##########
flink-connector-aws/flink-connector-dynamodb/src/main/java/org/apache/flink/connector/dynamodb/source/reader/DynamoDbStreamsRecordEmitter.java:
##########
@@ -0,0 +1,84 @@
+/*
+ * 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.source.reader;
+
+import org.apache.flink.annotation.Internal;
+import org.apache.flink.api.connector.source.SourceOutput;
+import org.apache.flink.connector.base.source.reader.RecordEmitter;
+import 
org.apache.flink.connector.dynamodb.source.serialization.DynamoDbStreamsDeserializationSchema;
+import 
org.apache.flink.connector.dynamodb.source.split.DynamoDbStreamsShardSplitState;
+import org.apache.flink.connector.dynamodb.source.split.StartingPosition;
+import org.apache.flink.util.Collector;
+
+import software.amazon.awssdk.services.dynamodb.model.Record;
+
+/**
+ * Emits record from the source into the Flink job graph. This serves as the 
interface between the
+ * source and the Flink job.
+ *
+ * @param <T> the data type being emitted into the Flink job graph
+ */
+@Internal
+public class DynamoDbStreamsRecordEmitter<T>
+        implements RecordEmitter<Record, T, DynamoDbStreamsShardSplitState> {
+
+    private final DynamoDbStreamsDeserializationSchema<T> 
deserializationSchema;
+    private final SourceOutputWrapper<T> sourceOutputWrapper = new 
SourceOutputWrapper<>();
+
+    public DynamoDbStreamsRecordEmitter(
+            DynamoDbStreamsDeserializationSchema<T> deserializationSchema) {
+        this.deserializationSchema = deserializationSchema;
+    }
+
+    @Override
+    public void emitRecord(
+            Record element, SourceOutput<T> output, 
DynamoDbStreamsShardSplitState splitState)
+            throws Exception {
+        sourceOutputWrapper.setSourceOutput(output);
+        sourceOutputWrapper.setTimestamp(
+                
element.dynamodb().approximateCreationDateTime().toEpochMilli());
+        deserializationSchema.deserialize(
+                element, splitState.getStreamArn(), splitState.getShardId(), 
sourceOutputWrapper);
+        splitState.setNextStartingPosition(
+                
StartingPosition.continueFromSequenceNumber(element.dynamodb().sequenceNumber()));
+    }
+
+    private static class SourceOutputWrapper<T> implements Collector<T> {
+        private SourceOutput<T> sourceOutput;
+        private long timestamp;
+
+        @Override
+        public void collect(T record) {
+            sourceOutput.collect(record, timestamp);
+        }
+
+        @Override
+        public void close() {
+            // no-op
+        }

Review Comment:
   Ok - happy to skip for now



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to