ProjectionTransform extends Transform<StructuredRecord, StructuredRecord> { @Override public void initialize(TransformContext context) throws Exception { super.initialize(context); FailureCollector collector = context.getFailureCollector(); init(null, collector); collector.getOrThrowException(); } ProjectionTransform(ProjectionTransformConfig projectionTransformConfig); @Override void configurePipeline(PipelineConfigurer pipelineConfigurer); @Override void initialize(TransformContext context); @Override void prepareRun(StageSubmitterContext context); @Override void transform(StructuredRecord valueIn, Emitter<StructuredRecord> emitter);  }
@Test public void testSameFieldMultipleConverts() throws Exception { ProjectionTransform.ProjectionTransformConfig config = new ProjectionTransform .ProjectionTransformConfig(null, null, "x:int,x:long", null); Transform<StructuredRecord, StructuredRecord> transform = new ProjectionTransform(config); TransformContext transformContext = new MockTransformContext(); try { transform.initialize(transformContext); Assert.fail(); } catch (ValidationException e) { Assert.assertEquals(1, e.getFailures().size()); Assert.assertEquals(1, e.getFailures().get(0).getCauses().size()); Cause expectedCause = new Cause(); expectedCause.addAttribute(CauseAttributes.STAGE_CONFIG, ProjectionTransform.ProjectionTransformConfig.CONVERT); expectedCause.addAttribute(STAGE, MOCK_STAGE); Assert.assertEquals(expectedCause, e.getFailures().get(0).getCauses().get(0)); } }
@Test public void testSameFieldMultipleRenames() throws Exception { ProjectionTransform.ProjectionTransformConfig config = new ProjectionTransform .ProjectionTransformConfig(null, "x:z,x:y", null, null); Transform<StructuredRecord, StructuredRecord> transform = new ProjectionTransform(config); TransformContext transformContext = new MockTransformContext(); try { transform.initialize(transformContext); Assert.fail(); } catch (ValidationException e) { Assert.assertEquals(1, e.getFailures().size()); Assert.assertEquals(2, e.getFailures().get(0).getCauses().size()); } }
@Test public void testMultipleRenamesToSameField() throws Exception { ProjectionTransform.ProjectionTransformConfig config = new ProjectionTransform .ProjectionTransformConfig(null, "x:z,y:z", null, null); Transform<StructuredRecord, StructuredRecord> transform = new ProjectionTransform(config); TransformContext transformContext = new MockTransformContext(); try { transform.initialize(transformContext); Assert.fail(); } catch (ValidationException e) { Assert.assertEquals(1, e.getFailures().size()); Assert.assertEquals(1, e.getFailures().get(0).getCauses().size()); Cause expectedCause = new Cause(); expectedCause.addAttribute(CauseAttributes.STAGE_CONFIG, ProjectionTransform.ProjectionTransformConfig.RENAME); expectedCause.addAttribute(STAGE, MOCK_STAGE); Assert.assertEquals(expectedCause, e.getFailures().get(0).getCauses().get(0)); } }
@Test(expected = IllegalArgumentException.class) public void testInvalidSyntax() throws Exception { ProjectionTransform.ProjectionTransformConfig config = new ProjectionTransform .ProjectionTransformConfig(null, "x,y", null, null); Transform<StructuredRecord, StructuredRecord> transform = new ProjectionTransform(config); TransformContext transformContext = new MockTransformContext(); transform.initialize(transformContext); }