[ 
https://issues.apache.org/jira/browse/BEAM-2863?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16320803#comment-16320803
 ] 

ASF GitHub Bot commented on BEAM-2863:
--------------------------------------

lukecwik closed pull request #4368: [BEAM-2863] Create an EncodedBoundedWindow 
allowing runners to pass around an encoded window instead of decoding each 
window.
URL: https://github.com/apache/beam/pull/4368
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git 
a/sdks/java/fn-execution/src/main/java/org/apache/beam/sdk/fn/windowing/EncodedBoundedWindow.java
 
b/sdks/java/fn-execution/src/main/java/org/apache/beam/sdk/fn/windowing/EncodedBoundedWindow.java
new file mode 100644
index 00000000000..97659e34f62
--- /dev/null
+++ 
b/sdks/java/fn-execution/src/main/java/org/apache/beam/sdk/fn/windowing/EncodedBoundedWindow.java
@@ -0,0 +1,94 @@
+/*
+ * 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.fn.windowing;
+
+import com.google.auto.value.AutoValue;
+import com.google.common.io.ByteStreams;
+import com.google.protobuf.ByteString;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import org.apache.beam.sdk.coders.AtomicCoder;
+import org.apache.beam.sdk.coders.CoderException;
+import org.apache.beam.sdk.transforms.windowing.BoundedWindow;
+import org.apache.beam.sdk.util.VarInt;
+import org.joda.time.Instant;
+
+/**
+ * An encoded {@link BoundedWindow} used within Runners to track window 
information without
+ * needing to decode the window.
+ *
+ * <p>This allows for Runners to not need to know window format during 
execution.
+ */
+@AutoValue
+public abstract class EncodedBoundedWindow extends BoundedWindow {
+  public static EncodedBoundedWindow forEncoding(ByteString encodedWindow) {
+    return new AutoValue_EncodedBoundedWindow(encodedWindow);
+  }
+
+  public abstract ByteString getEncodedWindow();
+
+  @Override
+  public Instant maxTimestamp() {
+    throw new UnsupportedOperationException("TODO: Add support for reading the 
timestamp from "
+        + "the encoded window.");
+  }
+
+  /**
+   * An {@link Coder} for {@link EncodedBoundedWindow}s.
+   *
+   * <p>This is a copy of {@code ByteStringCoder} to prevent a dependency on
+   * {@code beam-java-sdk-extensions-protobuf}.
+   */
+  public static class Coder extends AtomicCoder<EncodedBoundedWindow> {
+    public static final Coder INSTANCE = new Coder();
+
+    // prevent instantiation
+    private Coder() { }
+
+    @Override
+    public void encode(EncodedBoundedWindow value, OutputStream outStream)
+        throws CoderException, IOException {
+      VarInt.encode(value.getEncodedWindow().size(), outStream);
+      value.getEncodedWindow().writeTo(outStream);
+    }
+
+    @Override
+    public EncodedBoundedWindow decode(InputStream inStream) throws 
CoderException, IOException {
+      int size = VarInt.decodeInt(inStream);
+      ByteString encodedWindow = 
ByteString.readFrom(ByteStreams.limit(inStream, size));
+      return EncodedBoundedWindow.forEncoding(encodedWindow);
+    }
+
+    @Override
+    public boolean consistentWithEquals() {
+      return true;
+    }
+
+    @Override
+    public boolean isRegisterByteSizeObserverCheap(EncodedBoundedWindow value) 
{
+      return true;
+    }
+
+    @Override
+    protected long getEncodedElementByteSize(EncodedBoundedWindow value) 
throws Exception {
+      return VarInt.getLength(value.getEncodedWindow().size()) + 
value.getEncodedWindow().size();
+    }
+  }
+}
diff --git 
a/sdks/java/fn-execution/src/main/java/org/apache/beam/sdk/fn/windowing/package-info.java
 
b/sdks/java/fn-execution/src/main/java/org/apache/beam/sdk/fn/windowing/package-info.java
new file mode 100644
index 00000000000..9a91836c222
--- /dev/null
+++ 
b/sdks/java/fn-execution/src/main/java/org/apache/beam/sdk/fn/windowing/package-info.java
@@ -0,0 +1,22 @@
+/*
+ * 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.
+ */
+
+/**
+ * Common utilities related to windowing during execution of a pipeline.
+ */
+package org.apache.beam.sdk.fn.windowing;
diff --git 
a/sdks/java/fn-execution/src/test/java/org/apache/beam/sdk/fn/windowing/EncodedBoundedWindowTest.java
 
b/sdks/java/fn-execution/src/test/java/org/apache/beam/sdk/fn/windowing/EncodedBoundedWindowTest.java
new file mode 100644
index 00000000000..c3e4b11fdfc
--- /dev/null
+++ 
b/sdks/java/fn-execution/src/test/java/org/apache/beam/sdk/fn/windowing/EncodedBoundedWindowTest.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.beam.sdk.fn.windowing;
+
+import com.google.protobuf.ByteString;
+import org.apache.beam.sdk.fn.windowing.EncodedBoundedWindow.Coder;
+import org.apache.beam.sdk.testing.CoderProperties;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
+/** Tests for {@link EncodedBoundedWindow}. */
+@RunWith(JUnit4.class)
+public class EncodedBoundedWindowTest {
+  @Test
+  public void testCoder() throws Exception {
+    CoderProperties.coderSerializable(Coder.INSTANCE);
+    CoderProperties.coderConsistentWithEquals(Coder.INSTANCE,
+        EncodedBoundedWindow.forEncoding(ByteString.copyFrom(new byte[] {0x01, 
0x02, 0x03})),
+        EncodedBoundedWindow.forEncoding(ByteString.copyFrom(new byte[] {0x01, 
0x02, 0x03})));
+    CoderProperties.coderDecodeEncodeEqual(Coder.INSTANCE,
+        EncodedBoundedWindow.forEncoding(ByteString.copyFrom(new byte[] {0x01, 
0x02, 0x03})));
+    CoderProperties.coderDeterministic(
+        Coder.INSTANCE,
+        EncodedBoundedWindow.forEncoding(ByteString.copyFrom(new byte[] {0x01, 
0x02, 0x03})),
+        EncodedBoundedWindow.forEncoding(ByteString.copyFrom(new byte[] {0x01, 
0x02, 0x03})));
+    CoderProperties.structuralValueDecodeEncodeEqual(Coder.INSTANCE,
+        EncodedBoundedWindow.forEncoding(ByteString.copyFrom(new byte[] {0x01, 
0x02, 0x03})));
+  }
+}


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


> Add support for Side Inputs over the Fn API
> -------------------------------------------
>
>                 Key: BEAM-2863
>                 URL: https://issues.apache.org/jira/browse/BEAM-2863
>             Project: Beam
>          Issue Type: Improvement
>          Components: beam-model
>            Reporter: Luke Cwik
>            Assignee: Luke Cwik
>              Labels: portability
>             Fix For: 2.3.0
>
>
> See:
> * https://s.apache.org/beam-side-inputs-1-pager
> * http://s.apache.org/beam-fn-api-state-api



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Reply via email to