You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@beam.apache.org by GitBox <gi...@apache.org> on 2020/12/30 11:03:48 UTC

[GitHub] [beam] Fokko opened a new pull request #13635: [BEAM-11538] Add a Deque Encoder

Fokko opened a new pull request #13635:
URL: https://github.com/apache/beam/pull/13635


   **Please** add a meaningful description for your change here.
   
   A Deque is in certain situations faster than a List: https://stackoverflow.com/questions/6163166/why-is-arraydeque-better-than-linkedlist. When writing a custom CombineFn, appending is something that we often do, therefore I think it is a nice addition to the default encoders.
   
   ------------------------
   
   Thank you for your contribution! Follow this checklist to help us incorporate your contribution quickly and easily:
   
    - [x] [**Choose reviewer(s)**](https://beam.apache.org/contribute/#make-your-change) and mention them in a comment (`R: @username`). R: @iemejia 
    - [x] Format the pull request title like `[BEAM-XXX] Fixes bug in ApproximateQuantiles`, where you replace `BEAM-XXX` with the appropriate JIRA issue, if applicable. This will automatically link the pull request to the issue.
    - [x] Update `CHANGES.md` with noteworthy changes.
    - [x] If this contribution is large, please file an Apache [Individual Contributor License Agreement](https://www.apache.org/licenses/icla.pdf).
   
   See the [Contributor Guide](https://beam.apache.org/contribute) for more tips on [how to make review process smoother](https://beam.apache.org/contribute/#make-reviewers-job-easier).
   
   Post-Commit Tests Status (on master branch)
   ------------------------------------------------------------------------------------------------
   
   Lang | SDK | Dataflow | Flink | Samza | Spark | Twister2
   --- | --- | --- | --- | --- | --- | ---
   Go | [![Build Status](https://ci-beam.apache.org/job/beam_PostCommit_Go/lastCompletedBuild/badge/icon)](https://ci-beam.apache.org/job/beam_PostCommit_Go/lastCompletedBuild/) | --- | [![Build Status](https://ci-beam.apache.org/job/beam_PostCommit_Go_VR_Flink/lastCompletedBuild/badge/icon)](https://ci-beam.apache.org/job/beam_PostCommit_Go_VR_Flink/lastCompletedBuild/) | --- | [![Build Status](https://ci-beam.apache.org/job/beam_PostCommit_Go_VR_Spark/lastCompletedBuild/badge/icon)](https://ci-beam.apache.org/job/beam_PostCommit_Go_VR_Spark/lastCompletedBuild/) | ---
   Java | [![Build Status](https://ci-beam.apache.org/job/beam_PostCommit_Java/lastCompletedBuild/badge/icon)](https://ci-beam.apache.org/job/beam_PostCommit_Java/lastCompletedBuild/) | [![Build Status](https://ci-beam.apache.org/job/beam_PostCommit_Java_ValidatesRunner_Dataflow/lastCompletedBuild/badge/icon)](https://ci-beam.apache.org/job/beam_PostCommit_Java_ValidatesRunner_Dataflow/lastCompletedBuild/)<br>[![Build Status](https://ci-beam.apache.org/job/beam_PostCommit_Java_VR_Dataflow_V2/lastCompletedBuild/badge/icon)](https://ci-beam.apache.org/job/beam_PostCommit_Java_VR_Dataflow_V2/lastCompletedBuild/)<br>[![Build Status](https://ci-beam.apache.org/job/beam_PostCommit_Java_ValidatesRunner_Dataflow_Java11/lastCompletedBuild/badge/icon)](https://ci-beam.apache.org/job/beam_PostCommit_Java_ValidatesRunner_Dataflow_Java11/lastCompletedBuild/) | [![Build Status](https://ci-beam.apache.org/job/beam_PostCommit_Java_ValidatesRunner_Flink/lastCompletedBuild/badge/icon)](https://ci-beam
 .apache.org/job/beam_PostCommit_Java_ValidatesRunner_Flink/lastCompletedBuild/)<br>[![Build Status](https://ci-beam.apache.org/job/beam_PostCommit_Java_ValidatesRunner_Flink_Java11/lastCompletedBuild/badge/icon)](https://ci-beam.apache.org/job/beam_PostCommit_Java_ValidatesRunner_Flink_Java11/lastCompletedBuild/)<br>[![Build Status](https://ci-beam.apache.org/job/beam_PostCommit_Java_PVR_Flink_Batch/lastCompletedBuild/badge/icon)](https://ci-beam.apache.org/job/beam_PostCommit_Java_PVR_Flink_Batch/lastCompletedBuild/)<br>[![Build Status](https://ci-beam.apache.org/job/beam_PostCommit_Java_PVR_Flink_Streaming/lastCompletedBuild/badge/icon)](https://ci-beam.apache.org/job/beam_PostCommit_Java_PVR_Flink_Streaming/lastCompletedBuild/) | [![Build Status](https://ci-beam.apache.org/job/beam_PostCommit_Java_ValidatesRunner_Samza/lastCompletedBuild/badge/icon)](https://ci-beam.apache.org/job/beam_PostCommit_Java_ValidatesRunner_Samza/lastCompletedBuild/) | [![Build Status](https://ci-beam.a
 pache.org/job/beam_PostCommit_Java_ValidatesRunner_Spark/lastCompletedBuild/badge/icon)](https://ci-beam.apache.org/job/beam_PostCommit_Java_ValidatesRunner_Spark/lastCompletedBuild/)<br>[![Build Status](https://ci-beam.apache.org/job/beam_PostCommit_Java_PVR_Spark_Batch/lastCompletedBuild/badge/icon)](https://ci-beam.apache.org/job/beam_PostCommit_Java_PVR_Spark_Batch/lastCompletedBuild/)<br>[![Build Status](https://ci-beam.apache.org/job/beam_PostCommit_Java_ValidatesRunner_SparkStructuredStreaming/lastCompletedBuild/badge/icon)](https://ci-beam.apache.org/job/beam_PostCommit_Java_ValidatesRunner_SparkStructuredStreaming/lastCompletedBuild/) | [![Build Status](https://ci-beam.apache.org/job/beam_PostCommit_Java_ValidatesRunner_Twister2/lastCompletedBuild/badge/icon)](https://ci-beam.apache.org/job/beam_PostCommit_Java_ValidatesRunner_Twister2/lastCompletedBuild/)
   Python | [![Build Status](https://ci-beam.apache.org/job/beam_PostCommit_Python36/lastCompletedBuild/badge/icon)](https://ci-beam.apache.org/job/beam_PostCommit_Python36/lastCompletedBuild/)<br>[![Build Status](https://ci-beam.apache.org/job/beam_PostCommit_Python37/lastCompletedBuild/badge/icon)](https://ci-beam.apache.org/job/beam_PostCommit_Python37/lastCompletedBuild/)<br>[![Build Status](https://ci-beam.apache.org/job/beam_PostCommit_Python38/lastCompletedBuild/badge/icon)](https://ci-beam.apache.org/job/beam_PostCommit_Python38/lastCompletedBuild/) | [![Build Status](https://ci-beam.apache.org/job/beam_PostCommit_Py_VR_Dataflow/lastCompletedBuild/badge/icon)](https://ci-beam.apache.org/job/beam_PostCommit_Py_VR_Dataflow/lastCompletedBuild/)<br>[![Build Status](https://ci-beam.apache.org/job/beam_PostCommit_Py_VR_Dataflow_V2/lastCompletedBuild/badge/icon)](https://ci-beam.apache.org/job/beam_PostCommit_Py_VR_Dataflow_V2/lastCompletedBuild/)<br>[![Build Status](https://ci-beam
 .apache.org/job/beam_PostCommit_Py_ValCont/lastCompletedBuild/badge/icon)](https://ci-beam.apache.org/job/beam_PostCommit_Py_ValCont/lastCompletedBuild/) | [![Build Status](https://ci-beam.apache.org/job/beam_PreCommit_Python_PVR_Flink_Cron/lastCompletedBuild/badge/icon)](https://ci-beam.apache.org/job/beam_PreCommit_Python_PVR_Flink_Cron/lastCompletedBuild/)<br>[![Build Status](https://ci-beam.apache.org/job/beam_PostCommit_Python_VR_Flink/lastCompletedBuild/badge/icon)](https://ci-beam.apache.org/job/beam_PostCommit_Python_VR_Flink/lastCompletedBuild/) | --- | [![Build Status](https://ci-beam.apache.org/job/beam_PostCommit_Python_VR_Spark/lastCompletedBuild/badge/icon)](https://ci-beam.apache.org/job/beam_PostCommit_Python_VR_Spark/lastCompletedBuild/) | ---
   XLang | [![Build Status](https://ci-beam.apache.org/job/beam_PostCommit_XVR_Direct/lastCompletedBuild/badge/icon)](https://ci-beam.apache.org/job/beam_PostCommit_XVR_Direct/lastCompletedBuild/) | [![Build Status](https://ci-beam.apache.org/job/beam_PostCommit_XVR_Dataflow/lastCompletedBuild/badge/icon)](https://ci-beam.apache.org/job/beam_PostCommit_XVR_Dataflow/lastCompletedBuild/) | [![Build Status](https://ci-beam.apache.org/job/beam_PostCommit_XVR_Flink/lastCompletedBuild/badge/icon)](https://ci-beam.apache.org/job/beam_PostCommit_XVR_Flink/lastCompletedBuild/) | --- | [![Build Status](https://ci-beam.apache.org/job/beam_PostCommit_XVR_Spark/lastCompletedBuild/badge/icon)](https://ci-beam.apache.org/job/beam_PostCommit_XVR_Spark/lastCompletedBuild/) | ---
   
   Pre-Commit Tests Status (on master branch)
   ------------------------------------------------------------------------------------------------
   
   --- |Java | Python | Go | Website | Whitespace | Typescript
   --- | --- | --- | --- | --- | --- | ---
   Non-portable | [![Build Status](https://ci-beam.apache.org/job/beam_PreCommit_Java_Cron/lastCompletedBuild/badge/icon)](https://ci-beam.apache.org/job/beam_PreCommit_Java_Cron/lastCompletedBuild/) | [![Build Status](https://ci-beam.apache.org/job/beam_PreCommit_Python_Cron/lastCompletedBuild/badge/icon)](https://ci-beam.apache.org/job/beam_PreCommit_Python_Cron/lastCompletedBuild/)<br>[![Build Status](https://ci-beam.apache.org/job/beam_PreCommit_PythonLint_Cron/lastCompletedBuild/badge/icon)](https://ci-beam.apache.org/job/beam_PreCommit_PythonLint_Cron/lastCompletedBuild/)<br>[![Build Status](https://ci-beam.apache.org/job/beam_PreCommit_PythonDocker_Cron/badge/icon)](https://ci-beam.apache.org/job/beam_PreCommit_PythonDocker_Cron/lastCompletedBuild/) <br>[![Build Status](https://ci-beam.apache.org/job/beam_PreCommit_PythonDocs_Cron/badge/icon)](https://ci-beam.apache.org/job/beam_PreCommit_PythonDocs_Cron/lastCompletedBuild/) | [![Build Status](https://ci-beam.apache.org/job/be
 am_PreCommit_Go_Cron/lastCompletedBuild/badge/icon)](https://ci-beam.apache.org/job/beam_PreCommit_Go_Cron/lastCompletedBuild/) | [![Build Status](https://ci-beam.apache.org/job/beam_PreCommit_Website_Cron/lastCompletedBuild/badge/icon)](https://ci-beam.apache.org/job/beam_PreCommit_Website_Cron/lastCompletedBuild/) | [![Build Status](https://ci-beam.apache.org/job/beam_PreCommit_Whitespace_Cron/lastCompletedBuild/badge/icon)](https://ci-beam.apache.org/job/beam_PreCommit_Whitespace_Cron/lastCompletedBuild/) | [![Build Status](https://ci-beam.apache.org/job/beam_PreCommit_Typescript_Cron/lastCompletedBuild/badge/icon)](https://ci-beam.apache.org/job/beam_PreCommit_Typescript_Cron/lastCompletedBuild/)
   Portable | --- | [![Build Status](https://ci-beam.apache.org/job/beam_PreCommit_Portable_Python_Cron/lastCompletedBuild/badge/icon)](https://ci-beam.apache.org/job/beam_PreCommit_Portable_Python_Cron/lastCompletedBuild/) | --- | --- | --- | ---
   
   See [.test-infra/jenkins/README](https://github.com/apache/beam/blob/master/.test-infra/jenkins/README.md) for trigger phrase, status and link of all Jenkins jobs.
   
   
   GitHub Actions Tests Status (on master branch)
   ------------------------------------------------------------------------------------------------
   [![Build python source distribution and wheels](https://github.com/apache/beam/workflows/Build%20python%20source%20distribution%20and%20wheels/badge.svg?branch=master&event=schedule)](https://github.com/apache/beam/actions?query=workflow%3A%22Build+python+source+distribution+and+wheels%22+branch%3Amaster+event%3Aschedule)
   [![Python tests](https://github.com/apache/beam/workflows/Python%20tests/badge.svg?branch=master&event=schedule)](https://github.com/apache/beam/actions?query=workflow%3A%22Python+Tests%22+branch%3Amaster+event%3Aschedule)
   [![Java tests](https://github.com/apache/beam/workflows/Java%20Tests/badge.svg?branch=master&event=schedule)](https://github.com/apache/beam/actions?query=workflow%3A%22Java+Tests%22+branch%3Amaster+event%3Aschedule)
   
   See [CI.md](https://github.com/apache/beam/blob/master/CI.md) for more information about GitHub Actions CI.
   


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [beam] iemejia commented on pull request #13635: [BEAM-11538] Add a Deque Encoder

Posted by GitBox <gi...@apache.org>.
iemejia commented on pull request #13635:
URL: https://github.com/apache/beam/pull/13635#issuecomment-756691758


   checkstyle unhappy again


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [beam] Fokko commented on a change in pull request #13635: [BEAM-11538] Add a Deque Encoder

Posted by GitBox <gi...@apache.org>.
Fokko commented on a change in pull request #13635:
URL: https://github.com/apache/beam/pull/13635#discussion_r551563101



##########
File path: sdks/java/core/src/main/java/org/apache/beam/sdk/coders/DequeCoder.java
##########
@@ -0,0 +1,81 @@
+/*
+ * 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.coders;
+
+import java.util.ArrayDeque;
+import java.util.Deque;
+import java.util.List;
+import org.apache.beam.sdk.values.TypeDescriptor;
+import org.apache.beam.sdk.values.TypeParameter;
+
+/**
+ * A {@link Coder} for {@link Deque}, using the format of {@link IterableLikeCoder}.
+ *
+ * @param <T> the type of the elements of the Deques being transcoded
+ */
+public class DequeCoder<T> extends IterableLikeCoder<T, Deque<T>> {
+
+  public static <T> DequeCoder<T> of(Coder<T> elemCoder) {
+    return new DequeCoder<>(elemCoder);
+  }
+
+  /////////////////////////////////////////////////////////////////////////////
+  // Internal operations below here.
+
+  @Override
+  protected Deque<T> decodeToIterable(List<T> decodedElements) {
+    return new ArrayDeque<>(decodedElements);
+  }
+
+  protected DequeCoder(Coder<T> elemCoder) {
+    super(elemCoder, "Deque");
+  }
+
+  @Override
+  public boolean consistentWithEquals() {
+    return getElemCoder().consistentWithEquals();
+  }
+
+  @Override
+  public Object structuralValue(Deque<T> values) {
+    if (consistentWithEquals()) {
+      return values;
+    } else {
+      final Deque<Object> ret = new ArrayDeque<>(values.size());
+      for (T value : values) {
+        ret.add(getElemCoder().structuralValue(value));
+      }
+      return ret;
+    }
+  }
+
+  /**
+   * Deque sizes are always known, so DequeIterable may be deterministic while the general
+   * IterableLikeCoder is not.
+   */
+  @Override
+  public void verifyDeterministic() throws NonDeterministicException {
+    verifyDeterministic(this, "ListCoder.elemCoder must be deterministic", getElemCoder());

Review comment:
       I've copied this from the `SetCoder`, but that's a good point!




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [beam] iemejia commented on pull request #13635: [BEAM-11538] Add a Deque Encoder

Posted by GitBox <gi...@apache.org>.
iemejia commented on pull request #13635:
URL: https://github.com/apache/beam/pull/13635#issuecomment-753881754


   @Fokko can you please run `git pull origin master --rebase` it looks weird and I cannot see the changes here (and locally), but with this I can.
   
   I was wondering why this was not done in the past just for not overspecializing? any ideas @kennknowles?
   


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [beam] iemejia commented on pull request #13635: [BEAM-11538] Add a Deque Encoder

Posted by GitBox <gi...@apache.org>.
iemejia commented on pull request #13635:
URL: https://github.com/apache/beam/pull/13635#issuecomment-755183946


   Seems checkstyle is not happy about the format @Fokko (You can test this locally with `/gradlew :sdks:java:core:checkstyleTest`, I suppose after fixing this it should be good to merge but let's wait to see if @kennknowles has some additional comments.


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [beam] Fokko commented on pull request #13635: [BEAM-11538] Add a Deque Encoder

Posted by GitBox <gi...@apache.org>.
Fokko commented on pull request #13635:
URL: https://github.com/apache/beam/pull/13635#issuecomment-762189744


   @iemejia Nicely squashed :)


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [beam] Fokko commented on pull request #13635: [BEAM-11538] Add a Deque Encoder

Posted by GitBox <gi...@apache.org>.
Fokko commented on pull request #13635:
URL: https://github.com/apache/beam/pull/13635#issuecomment-756717168


   🙀 I've fixed the import and ran the Spotless and Checkstyle.. twice!


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [beam] Fokko commented on a change in pull request #13635: [BEAM-11538] Add a Deque Encoder

Posted by GitBox <gi...@apache.org>.
Fokko commented on a change in pull request #13635:
URL: https://github.com/apache/beam/pull/13635#discussion_r558836580



##########
File path: sdks/java/core/src/main/java/org/apache/beam/sdk/coders/DequeCoder.java
##########
@@ -0,0 +1,82 @@
+/*
+ * 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.coders;
+
+import java.util.ArrayDeque;
+import java.util.Deque;
+import java.util.List;
+import org.apache.beam.sdk.values.TypeDescriptor;
+import org.apache.beam.sdk.values.TypeParameter;
+
+/**
+ * A {@link Coder} for {@link Deque}, using the format of {@link IterableLikeCoder}.
+ *
+ * @param <T> the type of the elements of the Deques being transcoded
+ */
+public class DequeCoder<T> extends IterableLikeCoder<T, Deque<T>> {
+
+  public static <T> DequeCoder<T> of(Coder<T> elemCoder) {
+    return new DequeCoder<>(elemCoder);
+  }
+
+  /////////////////////////////////////////////////////////////////////////////
+  // Internal operations below here.
+
+  @Override
+  protected Deque<T> decodeToIterable(List<T> decodedElements) {
+    return new ArrayDeque<>(decodedElements);
+  }
+
+  protected DequeCoder(Coder<T> elemCoder) {
+    super(elemCoder, "Deque");
+  }
+
+  @Override
+  public boolean consistentWithEquals() {
+    return getElemCoder().consistentWithEquals();
+  }
+
+  @Override
+  public Object structuralValue(Deque<T> values) {

Review comment:
       I'm actually looking into this, but it isn't that trivial. This method is only tested for the `MapCoder` and `ListCoder`. My startingpoint was the tests of the `SetCoder`, where this wasn't covered. The issue with the Deque is that it do
   
   `LinkedList` extends `AbstractSequentialList` which extends `AbstractList` which does override `equals` and `hashCode` - so the implementation is not inherited from `Object`. `ArrayDeque`, on the other hand, really doesn't inherit anything other implementation as far as I can see. Its direct superclass (`AbstractCollection`) doesn't override them. So the test is failing for the Deque since the objects aren't equal (it only tests `lhs == rhs`, as this is the equals implementation of Object.




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [beam] kennknowles commented on a change in pull request #13635: [BEAM-11538] Add a Deque Encoder

Posted by GitBox <gi...@apache.org>.
kennknowles commented on a change in pull request #13635:
URL: https://github.com/apache/beam/pull/13635#discussion_r551482389



##########
File path: sdks/java/core/src/test/java/org/apache/beam/sdk/coders/DequeCoderTest.java
##########
@@ -0,0 +1,92 @@
+/*
+ * 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.coders;
+
+import static org.hamcrest.Matchers.equalTo;
+import static org.junit.Assert.assertThat;
+
+import java.util.ArrayDeque;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Deque;
+import java.util.List;
+import org.apache.beam.sdk.testing.CoderProperties;
+import org.apache.beam.sdk.transforms.windowing.GlobalWindow;
+import org.apache.beam.sdk.util.CoderUtils;
+import org.apache.beam.sdk.values.TypeDescriptor;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
+/** Test case for {@link DequeCoder}. */
+@RunWith(JUnit4.class)
+@SuppressWarnings({
+  "nullness" // TODO(https://issues.apache.org/jira/browse/BEAM-10402)
+})
+public class DequeCoderTest {
+
+  private static final Coder<Deque<Integer>> TEST_CODER = DequeCoder.of(VarIntCoder.of());
+
+  private static final List<Deque<Integer>> TEST_VALUES =
+      Arrays.asList(

Review comment:
       Prefer `ImmutableList.of` since this is not converting an array to a list, but just building a list.

##########
File path: sdks/java/core/src/main/java/org/apache/beam/sdk/coders/DequeCoder.java
##########
@@ -0,0 +1,81 @@
+/*
+ * 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.coders;
+
+import java.util.ArrayDeque;
+import java.util.Deque;
+import java.util.List;
+import org.apache.beam.sdk.values.TypeDescriptor;
+import org.apache.beam.sdk.values.TypeParameter;
+
+/**
+ * A {@link Coder} for {@link Deque}, using the format of {@link IterableLikeCoder}.
+ *
+ * @param <T> the type of the elements of the Deques being transcoded
+ */
+public class DequeCoder<T> extends IterableLikeCoder<T, Deque<T>> {
+
+  public static <T> DequeCoder<T> of(Coder<T> elemCoder) {
+    return new DequeCoder<>(elemCoder);
+  }
+
+  /////////////////////////////////////////////////////////////////////////////
+  // Internal operations below here.
+
+  @Override
+  protected Deque<T> decodeToIterable(List<T> decodedElements) {
+    return new ArrayDeque<>(decodedElements);
+  }
+
+  protected DequeCoder(Coder<T> elemCoder) {
+    super(elemCoder, "Deque");
+  }
+
+  @Override
+  public boolean consistentWithEquals() {
+    return getElemCoder().consistentWithEquals();
+  }
+
+  @Override
+  public Object structuralValue(Deque<T> values) {
+    if (consistentWithEquals()) {
+      return values;
+    } else {
+      final Deque<Object> ret = new ArrayDeque<>(values.size());
+      for (T value : values) {
+        ret.add(getElemCoder().structuralValue(value));
+      }
+      return ret;
+    }
+  }
+
+  /**
+   * Deque sizes are always known, so DequeIterable may be deterministic while the general
+   * IterableLikeCoder is not.
+   */
+  @Override
+  public void verifyDeterministic() throws NonDeterministicException {
+    verifyDeterministic(this, "ListCoder.elemCoder must be deterministic", getElemCoder());

Review comment:
       `DequeCoder.elemCoder` or better to even not reference private variables and say "Coder for elements of `DequeCoder` must be determistic".

##########
File path: sdks/java/core/src/test/java/org/apache/beam/sdk/coders/DequeCoderTest.java
##########
@@ -0,0 +1,92 @@
+/*
+ * 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.coders;
+
+import static org.hamcrest.Matchers.equalTo;
+import static org.junit.Assert.assertThat;
+
+import java.util.ArrayDeque;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Deque;
+import java.util.List;
+import org.apache.beam.sdk.testing.CoderProperties;
+import org.apache.beam.sdk.transforms.windowing.GlobalWindow;
+import org.apache.beam.sdk.util.CoderUtils;
+import org.apache.beam.sdk.values.TypeDescriptor;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
+/** Test case for {@link DequeCoder}. */
+@RunWith(JUnit4.class)
+@SuppressWarnings({
+  "nullness" // TODO(https://issues.apache.org/jira/browse/BEAM-10402)
+})
+public class DequeCoderTest {
+
+  private static final Coder<Deque<Integer>> TEST_CODER = DequeCoder.of(VarIntCoder.of());
+
+  private static final List<Deque<Integer>> TEST_VALUES =
+      Arrays.asList(
+          new ArrayDeque<>(),
+          new ArrayDeque<>(Collections.singleton(13)),
+          new ArrayDeque<>(Arrays.asList(31, -5, 83)));

Review comment:
       It would be good to have some tests where the element type is not integer. For example for the case where the inner type is arrays or some other nested structure.




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [beam] Fokko commented on a change in pull request #13635: [BEAM-11538] Add a Deque Encoder

Posted by GitBox <gi...@apache.org>.
Fokko commented on a change in pull request #13635:
URL: https://github.com/apache/beam/pull/13635#discussion_r551571559



##########
File path: sdks/java/core/src/test/java/org/apache/beam/sdk/coders/DequeCoderTest.java
##########
@@ -0,0 +1,92 @@
+/*
+ * 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.coders;
+
+import static org.hamcrest.Matchers.equalTo;
+import static org.junit.Assert.assertThat;
+
+import java.util.ArrayDeque;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Deque;
+import java.util.List;
+import org.apache.beam.sdk.testing.CoderProperties;
+import org.apache.beam.sdk.transforms.windowing.GlobalWindow;
+import org.apache.beam.sdk.util.CoderUtils;
+import org.apache.beam.sdk.values.TypeDescriptor;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
+/** Test case for {@link DequeCoder}. */
+@RunWith(JUnit4.class)
+@SuppressWarnings({
+  "nullness" // TODO(https://issues.apache.org/jira/browse/BEAM-10402)
+})
+public class DequeCoderTest {
+
+  private static final Coder<Deque<Integer>> TEST_CODER = DequeCoder.of(VarIntCoder.of());
+
+  private static final List<Deque<Integer>> TEST_VALUES =
+      Arrays.asList(
+          new ArrayDeque<>(),
+          new ArrayDeque<>(Collections.singleton(13)),
+          new ArrayDeque<>(Arrays.asList(31, -5, 83)));

Review comment:
       Sure, I've added the following test:
   ```java
     @Test
     public void encodeDequeWithList() throws Exception {
       DequeCoder<List<Long>> OBJECT_TEST_CODER = DequeCoder.of(ListCoder.of(VarLongCoder.of()));
   
       CoderProperties.coderDecodeEncodeContentsEqual(
           OBJECT_TEST_CODER,
           new ArrayDeque<>(
               ImmutableList.of(
                   ImmutableList.of(18L, 15L), ImmutableList.of(19L, 25L), ImmutableList.of(22L))));
     }
   ```
   Let me know if there are any other cases that you would like to see.




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [beam] iemejia merged pull request #13635: [BEAM-11538] Add a Deque Encoder

Posted by GitBox <gi...@apache.org>.
iemejia merged pull request #13635:
URL: https://github.com/apache/beam/pull/13635


   


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [beam] kennknowles commented on pull request #13635: [BEAM-11538] Add a Deque Encoder

Posted by GitBox <gi...@apache.org>.
kennknowles commented on pull request #13635:
URL: https://github.com/apache/beam/pull/13635#issuecomment-756903354


   Also not to anyone who merges it: don't merge all the fixup commits!


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [beam] Fokko commented on pull request #13635: [BEAM-11538] Add a Deque Encoder

Posted by GitBox <gi...@apache.org>.
Fokko commented on pull request #13635:
URL: https://github.com/apache/beam/pull/13635#issuecomment-761875620


   I've added the missing test :) It will check if the content of the iterable is equals.


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [beam] Fokko commented on a change in pull request #13635: [BEAM-11538] Add a Deque Encoder

Posted by GitBox <gi...@apache.org>.
Fokko commented on a change in pull request #13635:
URL: https://github.com/apache/beam/pull/13635#discussion_r551563582



##########
File path: sdks/java/core/src/test/java/org/apache/beam/sdk/coders/DequeCoderTest.java
##########
@@ -0,0 +1,92 @@
+/*
+ * 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.coders;
+
+import static org.hamcrest.Matchers.equalTo;
+import static org.junit.Assert.assertThat;
+
+import java.util.ArrayDeque;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Deque;
+import java.util.List;
+import org.apache.beam.sdk.testing.CoderProperties;
+import org.apache.beam.sdk.transforms.windowing.GlobalWindow;
+import org.apache.beam.sdk.util.CoderUtils;
+import org.apache.beam.sdk.values.TypeDescriptor;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
+/** Test case for {@link DequeCoder}. */
+@RunWith(JUnit4.class)
+@SuppressWarnings({
+  "nullness" // TODO(https://issues.apache.org/jira/browse/BEAM-10402)
+})
+public class DequeCoderTest {
+
+  private static final Coder<Deque<Integer>> TEST_CODER = DequeCoder.of(VarIntCoder.of());
+
+  private static final List<Deque<Integer>> TEST_VALUES =
+      Arrays.asList(

Review comment:
       Good one, updated.




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [beam] kennknowles commented on pull request #13635: [BEAM-11538] Add a Deque Encoder

Posted by GitBox <gi...@apache.org>.
kennknowles commented on pull request #13635:
URL: https://github.com/apache/beam/pull/13635#issuecomment-756903354


   Also not to anyone who merges it: don't merge all the fixup commits!


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [beam] kennknowles commented on a change in pull request #13635: [BEAM-11538] Add a Deque Encoder

Posted by GitBox <gi...@apache.org>.
kennknowles commented on a change in pull request #13635:
URL: https://github.com/apache/beam/pull/13635#discussion_r554092904



##########
File path: sdks/java/core/src/main/java/org/apache/beam/sdk/coders/DequeCoder.java
##########
@@ -0,0 +1,82 @@
+/*
+ * 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.coders;
+
+import java.util.ArrayDeque;
+import java.util.Deque;
+import java.util.List;
+import org.apache.beam.sdk.values.TypeDescriptor;
+import org.apache.beam.sdk.values.TypeParameter;
+
+/**
+ * A {@link Coder} for {@link Deque}, using the format of {@link IterableLikeCoder}.
+ *
+ * @param <T> the type of the elements of the Deques being transcoded
+ */
+public class DequeCoder<T> extends IterableLikeCoder<T, Deque<T>> {
+
+  public static <T> DequeCoder<T> of(Coder<T> elemCoder) {
+    return new DequeCoder<>(elemCoder);
+  }
+
+  /////////////////////////////////////////////////////////////////////////////
+  // Internal operations below here.
+
+  @Override
+  protected Deque<T> decodeToIterable(List<T> decodedElements) {
+    return new ArrayDeque<>(decodedElements);
+  }
+
+  protected DequeCoder(Coder<T> elemCoder) {
+    super(elemCoder, "Deque");
+  }
+
+  @Override
+  public boolean consistentWithEquals() {
+    return getElemCoder().consistentWithEquals();
+  }
+
+  @Override
+  public Object structuralValue(Deque<T> values) {

Review comment:
       I don't believe this one is tested.




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [beam] Fokko commented on pull request #13635: [BEAM-11538] Add a Deque Encoder

Posted by GitBox <gi...@apache.org>.
Fokko commented on pull request #13635:
URL: https://github.com/apache/beam/pull/13635#issuecomment-756717168


   🙀 I've fixed the import and ran the Spotless and Checkstyle.. twice!


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [beam] Fokko commented on pull request #13635: [BEAM-11538] Add a Deque Encoder

Posted by GitBox <gi...@apache.org>.
Fokko commented on pull request #13635:
URL: https://github.com/apache/beam/pull/13635#issuecomment-754222836


   Thanks @kennknowles for the review. I agree that it would be nice to have more standard Java structures in there by default. I had a simple combiner, where I changed from a List to a Deque, but it failed to run with a very hard-to-understand error message and took me quite a while to figure out what was going on.


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [beam] kennknowles edited a comment on pull request #13635: [BEAM-11538] Add a Deque Encoder

Posted by GitBox <gi...@apache.org>.
kennknowles edited a comment on pull request #13635:
URL: https://github.com/apache/beam/pull/13635#issuecomment-756903354


   Also note to anyone who merges it: don't merge all the fixup commits!


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [beam] Fokko edited a comment on pull request #13635: [BEAM-11538] Add a Deque Encoder

Posted by GitBox <gi...@apache.org>.
Fokko edited a comment on pull request #13635:
URL: https://github.com/apache/beam/pull/13635#issuecomment-761875620


   I've added the missing test :) It will check if the content of the iterable is equal.


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [beam] kennknowles edited a comment on pull request #13635: [BEAM-11538] Add a Deque Encoder

Posted by GitBox <gi...@apache.org>.
kennknowles edited a comment on pull request #13635:
URL: https://github.com/apache/beam/pull/13635#issuecomment-756903354


   Also note to anyone who merges it: don't merge all the fixup commits!


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [beam] iemejia commented on pull request #13635: [BEAM-11538] Add a Deque Encoder

Posted by GitBox <gi...@apache.org>.
iemejia commented on pull request #13635:
URL: https://github.com/apache/beam/pull/13635#issuecomment-760471750


   Can you please rebase @Fokko and add the proposed test


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [beam] kennknowles commented on a change in pull request #13635: [BEAM-11538] Add a Deque Encoder

Posted by GitBox <gi...@apache.org>.
kennknowles commented on a change in pull request #13635:
URL: https://github.com/apache/beam/pull/13635#discussion_r554092904



##########
File path: sdks/java/core/src/main/java/org/apache/beam/sdk/coders/DequeCoder.java
##########
@@ -0,0 +1,82 @@
+/*
+ * 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.coders;
+
+import java.util.ArrayDeque;
+import java.util.Deque;
+import java.util.List;
+import org.apache.beam.sdk.values.TypeDescriptor;
+import org.apache.beam.sdk.values.TypeParameter;
+
+/**
+ * A {@link Coder} for {@link Deque}, using the format of {@link IterableLikeCoder}.
+ *
+ * @param <T> the type of the elements of the Deques being transcoded
+ */
+public class DequeCoder<T> extends IterableLikeCoder<T, Deque<T>> {
+
+  public static <T> DequeCoder<T> of(Coder<T> elemCoder) {
+    return new DequeCoder<>(elemCoder);
+  }
+
+  /////////////////////////////////////////////////////////////////////////////
+  // Internal operations below here.
+
+  @Override
+  protected Deque<T> decodeToIterable(List<T> decodedElements) {
+    return new ArrayDeque<>(decodedElements);
+  }
+
+  protected DequeCoder(Coder<T> elemCoder) {
+    super(elemCoder, "Deque");
+  }
+
+  @Override
+  public boolean consistentWithEquals() {
+    return getElemCoder().consistentWithEquals();
+  }
+
+  @Override
+  public Object structuralValue(Deque<T> values) {

Review comment:
       I don't believe this one is tested.




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [beam] iemejia commented on pull request #13635: [BEAM-11538] Add a Deque Encoder

Posted by GitBox <gi...@apache.org>.
iemejia commented on pull request #13635:
URL: https://github.com/apache/beam/pull/13635#issuecomment-756691758


   checkstyle unhappy again


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [beam] Fokko commented on pull request #13635: [BEAM-11538] Add a Deque Encoder

Posted by GitBox <gi...@apache.org>.
Fokko commented on pull request #13635:
URL: https://github.com/apache/beam/pull/13635#issuecomment-753642255


   @iemejia The CI is green now. What do you think of the Deque encoder?


----------------------------------------------------------------
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:
users@infra.apache.org