@Override public PCollection<Row> expand(PCollection<T> input) { Schema inputSchema = input.getSchema(); verifyCompatibility(inputSchema); return input .apply( ParDo.of( new DoFn<T, Row>() { // TODO: This should be the same as resolved so that Beam knows which fields // are being accessed. Currently Beam only supports wildcard descriptors. // Once BEAM-4457 is fixed, fix this. @FieldAccess("filterFields") final FieldAccessDescriptor fieldAccessDescriptor = FieldAccessDescriptor.withAllFields(); @ProcessElement public void process( @FieldAccess("filterFields") Row input, OutputReceiver<Row> r) { Row output = castRow(input, inputSchema, outputSchema()); r.output(output); } })) .setRowSchema(outputSchema()); }
@Test(expected = IllegalArgumentException.class) @Category(NeedsRunner.class) public void testWeakedNullableFail() throws Exception { Schema inputSchema = pipeline.getSchemaRegistry().getSchema(Nullable1.class); Schema outputSchema = pipeline.getSchemaRegistry().getSchema(Nullable2.class); Cast.widening(outputSchema).verifyCompatibility(inputSchema); }
@Test(expected = IllegalArgumentException.class) @Category(NeedsRunner.class) public void testIgnoreNullableFail() throws Exception { // ignoring nullable is opposite of weakening Schema inputSchema = pipeline.getSchemaRegistry().getSchema(Nullable2.class); Schema outputSchema = pipeline.getSchemaRegistry().getSchema(Nullable1.class); Cast.widening(outputSchema).verifyCompatibility(inputSchema); }
@Test(expected = IllegalArgumentException.class) @Category(NeedsRunner.class) public void testTypeNarrowFail() throws Exception { // narrowing is the opposite of widening Schema inputSchema = pipeline.getSchemaRegistry().getSchema(TypeWiden2.class); Schema outputSchema = pipeline.getSchemaRegistry().getSchema(TypeWiden1.class); Cast.narrowing(outputSchema).verifyCompatibility(inputSchema); }
@Test(expected = IllegalArgumentException.class) @Category(NeedsRunner.class) public void testComplexCastFail() throws Exception { Schema inputSchema = pipeline.getSchemaRegistry().getSchema(All1.class); Schema outputSchema = pipeline.getSchemaRegistry().getSchema(All2.class); Cast.widening(outputSchema).verifyCompatibility(inputSchema); }