Search in sources :

Example 71 with MockPipelineConfigurer

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());
}
Also used : MockPipelineConfigurer(io.cdap.cdap.etl.mock.common.MockPipelineConfigurer) Schema(io.cdap.cdap.api.data.schema.Schema) Test(org.junit.Test)

Example 72 with MockPipelineConfigurer

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();
}
Also used : MockPipelineConfigurer(io.cdap.cdap.etl.mock.common.MockPipelineConfigurer) Schema(io.cdap.cdap.api.data.schema.Schema) Test(org.junit.Test)

Example 73 with MockPipelineConfigurer

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();
}
Also used : MockPipelineConfigurer(io.cdap.cdap.etl.mock.common.MockPipelineConfigurer) Schema(io.cdap.cdap.api.data.schema.Schema) Test(org.junit.Test)

Example 74 with MockPipelineConfigurer

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());
    }
}
Also used : ValidationException(io.cdap.cdap.etl.api.validation.ValidationException) MockPipelineConfigurer(io.cdap.cdap.etl.mock.common.MockPipelineConfigurer) ETLBatchConfig(io.cdap.cdap.etl.proto.v2.ETLBatchConfig) Schema(io.cdap.cdap.api.data.schema.Schema) Test(org.junit.Test)

Example 75 with MockPipelineConfigurer

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));
    }
}
Also used : ValidationException(io.cdap.cdap.etl.api.validation.ValidationException) MockPipelineConfigurer(io.cdap.cdap.etl.mock.common.MockPipelineConfigurer) ETLBatchConfig(io.cdap.cdap.etl.proto.v2.ETLBatchConfig) Schema(io.cdap.cdap.api.data.schema.Schema) Cause(io.cdap.cdap.etl.api.validation.ValidationFailure.Cause) Test(org.junit.Test)

Aggregations

MockPipelineConfigurer (io.cdap.cdap.etl.mock.common.MockPipelineConfigurer)89 Test (org.junit.Test)89 Schema (io.cdap.cdap.api.data.schema.Schema)56 FailureCollector (io.cdap.cdap.etl.api.FailureCollector)26 StructuredRecord (io.cdap.cdap.api.data.format.StructuredRecord)22 ValidationException (io.cdap.cdap.etl.api.validation.ValidationException)17 Cause (io.cdap.cdap.etl.api.validation.ValidationFailure.Cause)12 ValidationFailure (io.cdap.cdap.etl.api.validation.ValidationFailure)10 TableSinkConfig (io.cdap.plugin.common.TableSinkConfig)10 HBaseSink (io.cdap.plugin.sink.HBaseSink)7 ETLBatchConfig (io.cdap.cdap.etl.proto.v2.ETLBatchConfig)5 MockEmitter (io.cdap.cdap.etl.mock.common.MockEmitter)4 TransformContext (io.cdap.cdap.etl.api.TransformContext)3 MockTransformContext (io.cdap.cdap.etl.mock.transform.MockTransformContext)3 SolrSearchSink (io.cdap.plugin.batch.SolrSearchSink)3 PipelineConfigurer (io.cdap.cdap.etl.api.PipelineConfigurer)2 LookupConfig (io.cdap.cdap.etl.api.LookupConfig)1 LookupTableConfig (io.cdap.cdap.etl.api.LookupTableConfig)1 MockFailureCollector (io.cdap.cdap.etl.mock.validation.MockFailureCollector)1