RowRecordTransformer { public StructuredRecord toRecord(Row row) { StructuredRecord.Builder builder = StructuredRecord.builder(schema); if (rowField != null) { setField(builder, rowField, row.getRow()); } for (Schema.Field field : schema.getFields()) { if (rowField != null && field.getName().equals(rowField.getName())) { continue; } setField(builder, field, row.get(field.getName())); } return builder.build(); } RowRecordTransformer(Schema schema, String rowFieldName); StructuredRecord toRecord(Row row);  }
@Test public void testTransform() throws Exception { byte[] rowKey = Bytes.toBytes(28); final Schema schema = Schema.recordOf( "record", Schema.Field.of("boolField", Schema.nullableOf(Schema.of(Schema.Type.BOOLEAN))), Schema.Field.of("intField", Schema.of(Schema.Type.INT)), Schema.Field.of("longField", Schema.nullableOf(Schema.of(Schema.Type.LONG))), Schema.Field.of("floatField", Schema.nullableOf(Schema.of(Schema.Type.FLOAT))), Schema.Field.of("doubleField", Schema.nullableOf(Schema.of(Schema.Type.DOUBLE))), Schema.Field.of("bytesField", Schema.nullableOf(Schema.of(Schema.Type.BYTES))), Schema.Field.of("stringField", Schema.nullableOf(Schema.of(Schema.Type.STRING))) ); Map<byte[], byte[]> inputColumns = Maps.newTreeMap(Bytes.BYTES_COMPARATOR); inputColumns.put(Bytes.toBytes("boolField"), Bytes.toBytes(true)); inputColumns.put(Bytes.toBytes("longField"), Bytes.toBytes(512L)); inputColumns.put(Bytes.toBytes("floatField"), Bytes.toBytes(3.14f)); inputColumns.put(Bytes.toBytes("bytesField"), Bytes.toBytes("foo")); inputColumns.put(Bytes.toBytes("stringField"), Bytes.toBytes("rock")); inputColumns.put(Bytes.toBytes("extraField"), Bytes.toBytes("bar")); Row input = new Result(rowKey, inputColumns); RowRecordTransformer transformer = new RowRecordTransformer(schema, "intField"); StructuredRecord actual = transformer.toRecord(input); Assert.assertTrue(actual.get("boolField")); Assert.assertEquals(512L, actual.<Long>get("longField").longValue()); Assert.assertTrue(Math.abs(3.14f - (Float) actual.get("floatField")) < 0.000001); Assert.assertEquals("foo", Bytes.toString((byte[]) actual.get("bytesField"))); Assert.assertEquals("rock", actual.get("stringField")); Assert.assertNull(actual.get("extraField")); Assert.assertNull(actual.get("doubleField")); }