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

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

                Author: ASF GitHub Bot
            Created on: 05/Dec/19 21:20
            Start Date: 05/Dec/19 21:20
    Worklog Time Spent: 10m 
      Work Description: TheNeuralBit commented on pull request #10151: 
[BEAM-7116] Remove use of KV in Schema transforms
URL: https://github.com/apache/beam/pull/10151#discussion_r349359908
 
 

 ##########
 File path: 
sdks/java/core/src/test/java/org/apache/beam/sdk/schemas/utils/SchemaTestUtils.java
 ##########
 @@ -28,4 +38,71 @@
   public static void assertSchemaEquivalent(Schema expected, Schema actual) {
     assertTrue(actual.equivalent(expected));
   }
+
+  public static class RowFieldMatcher extends BaseMatcher<Row> {
+    int fieldIndex;
+    Object expected;
+    FieldType fieldType;
+
+    public RowFieldMatcher(Schema schema, int fieldIndex, Object expected) {
+      this.fieldIndex = fieldIndex;
+      this.expected = expected;
+      this.fieldType = schema.getField(fieldIndex).getType();
+    }
+
+    public RowFieldMatcher(Schema schema, String fieldName, Object expected) {
+      this.fieldIndex = schema.indexOf(fieldName);
+      this.expected = expected;
+      this.fieldType = schema.getField(fieldIndex).getType();
+    }
+
+    @Override
+    public boolean matches(Object item) {
+      if (!(item instanceof Row)) {
+        return false;
+      }
+      Row row = (Row) item;
+      switch (fieldType.getTypeName()) {
+        case ROW:
+          if 
(!row.getSchema().getField(fieldIndex).getType().getTypeName().isCompositeType())
 {
+            return false;
+          }
+          Row actualRow = row.getRow(fieldIndex);
+          return equalTo((Row) expected).matches(actualRow);
+        case ARRAY:
+          Row[] expectedArray = ((List<Row>) expected).toArray(new Row[0]);
+
+          return 
containsInAnyOrder(expectedArray).matches(row.getArray(fieldIndex));
+        case ITERABLE:
+          Row[] expectedIterable = Iterables.toArray((Iterable<Row>) expected, 
Row.class);
+          List<Row> actualIterable = 
Lists.newArrayList(row.getIterable(fieldIndex));
+          return containsInAnyOrder(expectedIterable).matches(actualIterable);
 
 Review comment:
   It's probably worth documenting that `RowFieldMatcher` doesn't care about 
order for array and iterable types. Maybe that should even be indicated in the 
name somehow? It seems like that's the primary difference between this and just 
using `equalTo(expectedRow)`.
 
----------------------------------------------------------------
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: 354697)
    Time Spent: 1h 10m  (was: 1h)

> Remove KV from Schema transforms
> --------------------------------
>
>                 Key: BEAM-7116
>                 URL: https://issues.apache.org/jira/browse/BEAM-7116
>             Project: Beam
>          Issue Type: Sub-task
>          Components: sdk-java-core
>            Reporter: Reuven Lax
>            Assignee: Brian Hulette
>            Priority: Major
>          Time Spent: 1h 10m
>  Remaining Estimate: 0h
>
> Instead of returning KV objects, we should return a Schema with two fields. 
> The Convert transform should be able to convert these to KV objects.



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

Reply via email to