use of io.cdap.cdap.etl.mock.common.MockPipelineConfigurer in project hydrator-plugins by cdapio.
the class GroupByTestRun method testGroupByCollectList.
@Test
public void testGroupByCollectList() {
/*
<ts, user, item, price> --> group by user, itemList:CollectList(item) --> user table
*/
Schema purchaseSchema = Schema.recordOf("purchase", Schema.Field.of("ts", Schema.of(Schema.Type.LONG)), Schema.Field.of("user", Schema.of(Schema.Type.STRING)), Schema.Field.of("item", Schema.of(Schema.Type.STRING)), Schema.Field.of("price", Schema.of(Schema.Type.DOUBLE)));
Schema aggSchema = Schema.recordOf("purchase.agg", Schema.Field.of("user", Schema.of(Schema.Type.STRING)), Schema.Field.of("itemList", Schema.arrayOf(Schema.of(Schema.Type.STRING))));
GroupByConfig groupByConfig = new GroupByConfig("user", "itemList:CollectList(item)");
GroupByAggregator groupByAggregator = new GroupByAggregator(groupByConfig);
MockPipelineConfigurer mockConfigurer = new MockPipelineConfigurer(purchaseSchema, Collections.emptyMap());
groupByAggregator.configurePipeline(mockConfigurer);
Assert.assertEquals(aggSchema, mockConfigurer.getOutputSchema());
}
use of io.cdap.cdap.etl.mock.common.MockPipelineConfigurer in project hydrator-plugins by cdapio.
the class RowDenormalizerConfigTest method testDenormalizerWithWrongValueField.
@Test(expected = ValidationException.class)
public void testDenormalizerWithWrongValueField() throws Exception {
Schema inputSchema = Schema.recordOf("record", Schema.Field.of("KeyField", Schema.nullableOf(Schema.of(Schema.Type.STRING))), Schema.Field.of("NameField", Schema.nullableOf(Schema.of(Schema.Type.STRING))), Schema.Field.of("ValueField", Schema.nullableOf(Schema.of(Schema.Type.STRING))));
MockPipelineConfigurer configurer = new MockPipelineConfigurer(inputSchema, Collections.emptyMap());
RowDenormalizerConfig config = new RowDenormalizerConfig("KeyField", "NameField", "WrongValueField", "Firstname," + "Lastname,Address", "Lastname:lname,Address:addr");
RowDenormalizerAggregator aggregator = new RowDenormalizerAggregator(config);
aggregator.configurePipeline(configurer);
configurer.getStageConfigurer().getFailureCollector().getOrThrowException();
}
use of io.cdap.cdap.etl.mock.common.MockPipelineConfigurer in project hydrator-plugins by cdapio.
the class RowDenormalizerConfigTest method testDenormalizerWithWrongNameField.
@Test(expected = ValidationException.class)
public void testDenormalizerWithWrongNameField() throws Exception {
Schema inputSchema = Schema.recordOf("record", Schema.Field.of("KeyField", Schema.nullableOf(Schema.of(Schema.Type.STRING))), Schema.Field.of("NameField", Schema.nullableOf(Schema.of(Schema.Type.STRING))), Schema.Field.of("ValueField", Schema.nullableOf(Schema.of(Schema.Type.STRING))));
MockPipelineConfigurer configurer = new MockPipelineConfigurer(inputSchema, Collections.emptyMap());
RowDenormalizerConfig config = new RowDenormalizerConfig("KeyField", "WrongNameField", "ValueField", "Firstname," + "Lastname,Address", "Lastname:lname,Address:addr");
RowDenormalizerAggregator aggregator = new RowDenormalizerAggregator(config);
aggregator.configurePipeline(configurer);
configurer.getStageConfigurer().getFailureCollector().getOrThrowException();
}
use of io.cdap.cdap.etl.mock.common.MockPipelineConfigurer in project hydrator-plugins by cdapio.
the class ValueMapperTest method testStringHandling.
@Test
public void testStringHandling() throws Exception {
Schema inputSchema = Schema.recordOf("sourceRecord", Schema.Field.of(ID, Schema.of(Schema.Type.STRING)), Schema.Field.of(NAME, Schema.of(Schema.Type.STRING)), Schema.Field.of(SALARY, Schema.of(Schema.Type.STRING)), Schema.Field.of(DESIGNATIONID, Schema.of(Schema.Type.INT)));
ValueMapper.Config config = new ValueMapper.Config("designationid:designation_lookup_table:designationName", "designationid:DEFAULTID");
MockPipelineConfigurer configurer = new MockPipelineConfigurer(inputSchema);
try {
new ValueMapper(config).configurePipeline(configurer);
Assert.fail();
} catch (ValidationException e) {
Assert.assertEquals(1, e.getFailures().size());
Assert.assertEquals(2, e.getFailures().get(0).getCauses().size());
}
}
use of io.cdap.cdap.etl.mock.common.MockPipelineConfigurer in project hydrator-plugins by cdapio.
the class ValueMapperTest method testDefaultDoesNotExistInMapping.
@Test
public void testDefaultDoesNotExistInMapping() throws Exception {
Schema inputSchema = Schema.recordOf("sourceRecord", Schema.Field.of(ID, Schema.of(Schema.Type.STRING)), Schema.Field.of(NAME, Schema.of(Schema.Type.STRING)), Schema.Field.of(SALARY, Schema.of(Schema.Type.STRING)), Schema.Field.of(DESIGNATIONID, Schema.of(Schema.Type.STRING)));
ValueMapper.Config config = new ValueMapper.Config("designationid:designation_lookup_table:designationName", "does_not_exist:DEFAULTID");
MockPipelineConfigurer configurer = new MockPipelineConfigurer(inputSchema);
ValueMapper mapper = new ValueMapper(config);
try {
mapper.configurePipeline(configurer);
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(STAGE, MOCK_STAGE);
expectedCause.addAttribute(CauseAttributes.STAGE_CONFIG, ValueMapper.Config.DEFAULTS);
expectedCause.addAttribute(CauseAttributes.CONFIG_ELEMENT, "does_not_exist:DEFAULTID");
Assert.assertEquals(expectedCause, e.getFailures().get(0).getCauses().get(0));
}
}
Aggregations