[ 
https://issues.apache.org/jira/browse/BEAM-8511?focusedWorklogId=349542&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-349542
 ]

ASF GitHub Bot logged work on BEAM-8511:
----------------------------------------

                Author: ASF GitHub Bot
            Created on: 26/Nov/19 03:30
            Start Date: 26/Nov/19 03:30
    Worklog Time Spent: 10m 
      Work Description: cmachgodaddy commented on pull request #9899: 
[BEAM-8511] [WIP] KinesisIO.Read enhanced fanout
URL: https://github.com/apache/beam/pull/9899#discussion_r350483171
 
 

 ##########
 File path: 
sdks/java/io/kinesis2/src/main/java/org/apache/beam/sdk/io/kinesis2/KinesisRecord.java
 ##########
 @@ -0,0 +1,142 @@
+/*
+ * 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.beam.sdk.io.kinesis2;
+
+import static 
org.apache.commons.lang.builder.HashCodeBuilder.reflectionHashCode;
+
+import java.nio.ByteBuffer;
+import java.nio.charset.StandardCharsets;
+import org.apache.commons.lang.builder.EqualsBuilder;
+import org.apache.commons.lang.builder.ToStringBuilder;
+import org.joda.time.Instant;
+import software.amazon.kinesis.retrieval.KinesisClientRecord;
+import software.amazon.kinesis.retrieval.kpl.ExtendedSequenceNumber;
+
+/** {@link KinesisClientRecord} enhanced with utility methods. */
+public class KinesisRecord {
+
+  private Instant readTime;
+  private String streamName;
+  private String shardId;
+  private long subSequenceNumber;
+  private String sequenceNumber;
+  private Instant approximateArrivalTimestamp;
+  private ByteBuffer data;
+  private String partitionKey;
+
+  public KinesisRecord(KinesisClientRecord record, String streamName, String 
shardId) {
+    this(
+        record.data(),
+        record.sequenceNumber(),
+        record.subSequenceNumber(),
+        record.partitionKey(),
+        TimeUtil.toJoda(record.approximateArrivalTimestamp()),
+        Instant.now(),
+        streamName,
+        shardId);
+  }
+
+  public KinesisRecord(
+      ByteBuffer data,
+      String sequenceNumber,
+      long subSequenceNumber,
+      String partitionKey,
+      Instant approximateArrivalTimestamp,
+      Instant readTime,
+      String streamName,
+      String shardId) {
+    this.data = copyData(data);
+    this.sequenceNumber = sequenceNumber;
+    this.subSequenceNumber = subSequenceNumber;
+    this.partitionKey = partitionKey;
+    this.approximateArrivalTimestamp = approximateArrivalTimestamp;
+    this.readTime = readTime;
+    this.streamName = streamName;
+    this.shardId = shardId;
+  }
+
+  private ByteBuffer copyData(ByteBuffer data) {
+    data.rewind();
+    byte[] bytes = new byte[data.remaining()];
+    data.get(bytes);
+    return ByteBuffer.wrap(bytes);
+  }
+
+  public ExtendedSequenceNumber getExtendedSequenceNumber() {
+    return new ExtendedSequenceNumber(getSequenceNumber(), 
getSubSequenceNumber());
+  }
+
+  /** @return The unique identifier of the record based on its position in the 
stream. */
+  public byte[] getUniqueId() {
+    return 
getExtendedSequenceNumber().toString().getBytes(StandardCharsets.UTF_8);
+  }
+
+  public Instant getReadTime() {
+    return readTime;
+  }
+
+  public String getStreamName() {
+    return streamName;
+  }
+
+  public String getShardId() {
+    return shardId;
+  }
+
+  public byte[] getDataAsBytes() {
+    return getData().array();
+  }
+
+  @Override
+  public boolean equals(Object obj) {
+    return EqualsBuilder.reflectionEquals(this, obj);
+  }
+
+  @Override
+  public int hashCode() {
+    return reflectionHashCode(this);
+  }
+
+  @Override
+  public String toString() {
+    return ToStringBuilder.reflectionToString(this);
 
 Review comment:
   This is also new. any reason, @jfarr ?
 
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


Issue Time Tracking
-------------------

    Worklog Id:     (was: 349542)
    Time Spent: 2h 50m  (was: 2h 40m)

> Support for enhanced fan-out in KinesisIO.Read
> ----------------------------------------------
>
>                 Key: BEAM-8511
>                 URL: https://issues.apache.org/jira/browse/BEAM-8511
>             Project: Beam
>          Issue Type: New Feature
>          Components: io-java-kinesis
>            Reporter: Jonothan Farr
>            Assignee: Jonothan Farr
>            Priority: Major
>          Time Spent: 2h 50m
>  Remaining Estimate: 0h
>
> Add support for reading from an enhanced fan-out consumer using KinesisIO.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to