TheNeuralBit commented on a change in pull request #16958:
URL: https://github.com/apache/beam/pull/16958#discussion_r826463579



##########
File path: 
sdks/java/core/src/test/java/org/apache/beam/sdk/values/PCollectionRowTupleTest.java
##########
@@ -0,0 +1,172 @@
+/*
+ * 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.values;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.equalTo;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import com.google.common.testing.EqualsTester;
+import java.io.Serializable;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.stream.Collectors;
+import org.apache.beam.sdk.Pipeline;
+import org.apache.beam.sdk.coders.RowCoder;
+import org.apache.beam.sdk.schemas.Schema;
+import org.apache.beam.sdk.schemas.Schema.Field;
+import org.apache.beam.sdk.schemas.Schema.FieldType;
+import org.apache.beam.sdk.testing.PAssert;
+import org.apache.beam.sdk.testing.TestPipeline;
+import org.apache.beam.sdk.testing.ValidatesRunner;
+import org.apache.beam.sdk.transforms.Create;
+import org.apache.beam.sdk.transforms.MapElements;
+import org.apache.beam.sdk.transforms.SimpleFunction;
+import org.apache.beam.sdk.values.PCollection.IsBounded;
+import 
org.apache.beam.vendor.guava.v26_0_jre.com.google.common.collect.ImmutableMap;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
+/** Unit tests for {@link PCollectionRowTuple}. */
+@RunWith(JUnit4.class)
+public final class PCollectionRowTupleTest implements Serializable {
+
+  public static final Schema intSchema = Schema.of(Field.of("int", 
FieldType.INT32));
+  public static final Schema stringSchema = Schema.of(Field.of("str", 
FieldType.STRING));
+  public static final Schema boolSchema = Schema.of(Field.of("str", 
FieldType.BOOLEAN));
+
+  @Rule
+  public final transient TestPipeline pipeline =
+      TestPipeline.create().enableAbandonedNodeEnforcement(false);
+
+  List<Row> toRows(List<Object> ints, Schema schema) {
+    return ints.stream()
+        .map((value) -> Row.withSchema(schema).addValue(value).build())
+        .collect(Collectors.toList());
+  }
+
+  @Test
+  public void testOfThenHas() {
+    PCollection<Row> pCollection =
+        PCollection.createPrimitiveOutputInternal(
+            pipeline, WindowingStrategy.globalDefault(), IsBounded.BOUNDED, 
RowCoder.of(intSchema));
+    String tag = "collection1";
+    assertTrue(PCollectionRowTuple.of(tag, pCollection).has(tag));
+  }
+
+  @Test
+  public void testEmpty() {
+    String tag = "collection1";
+    assertFalse(PCollectionRowTuple.empty(pipeline).has(tag));
+  }
+
+  @Test
+  @Category(ValidatesRunner.class)
+  public void testComposePCollectionRowTuple() {
+    pipeline.enableAbandonedNodeEnforcement(true);
+
+    List<Row> inputs = toRows(Arrays.asList(3, -42, 77), intSchema);
+
+    PCollection<Row> mainInput = pipeline.apply(Create.of(inputs));
+    PCollection<Row> secondInput = pipeline.apply(Create.of(inputs));

Review comment:
       It looks like this is causing an actual failure in Java PreCommit:
   ```
   java.lang.IllegalStateException: Pipeline update will not be possible 
because the following transforms do not have stable unique names: Create.Values.
   
   Conflicting instances:
   - name=Create.Values:
       - Create.Values
       - Create.Values
   
   You can fix it adding a name when you call apply(): pipeline.apply(<name>, 
<transform>).
        at org.apache.beam.sdk.Pipeline.validate(Pipeline.java:619)
        at org.apache.beam.sdk.Pipeline.run(Pipeline.java:322)
        at org.apache.beam.sdk.testing.TestPipeline.run(TestPipeline.java:399)
        at org.apache.beam.sdk.testing.TestPipeline.run(TestPipeline.java:335)
        at 
org.apache.beam.sdk.values.PCollectionRowTupleTest.testComposePCollectionRowTuple(PCollectionRowTupleTest.java:101)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at 
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at 
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
   ```




-- 
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