[
https://issues.apache.org/jira/browse/BEAM-7116?focusedWorklogId=354696&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-354696
]
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_r349359007
##########
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);
+ case MAP:
+ throw new RuntimeException("Not yet implemented for maps");
+ default:
+ return equalTo(expected).matches(row.getValue(fieldIndex));
+ }
+ }
+
+ @Override
+ public void describeTo(Description description) {
+ description.appendText("rowFieldMatcher: ");
+ description.appendText("FieldType: " + fieldType.getTypeName());
+ description.appendText(expected.toString());
+ }
+ }
+
+ public static class RowIterableFieldMatcher extends BaseMatcher<Row> {
Review comment:
Is this dead? I don't see it used anywhere.
----------------------------------------------------------------
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: 354696)
Time Spent: 1h (was: 50m)
> 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
> 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)