Search in sources :

Example 21 with MockFailureCollector

use of io.cdap.cdap.etl.mock.validation.MockFailureCollector in project hydrator-plugins by cdapio.

the class JoinerConfigTest method testAdvancedJoinCondition.

@Test
public void testAdvancedJoinCondition() {
    JoinerConfig conf = new JoinerConfig("users.id, emails.email", "users.id = emails.userid", new HashSet<>(Arrays.asList("users", "emails")));
    Joiner joiner = new Joiner(conf);
    FailureCollector collector = new MockFailureCollector();
    Schema userSchema = Schema.recordOf("user", Schema.Field.of("id", Schema.of(Schema.Type.INT)));
    Schema emailSchema = Schema.recordOf("email", Schema.Field.of("email", Schema.of(Schema.Type.STRING)), Schema.Field.of("userid", Schema.of(Schema.Type.INT)));
    Map<String, JoinStage> inputStages = new HashMap<>();
    inputStages.put("users", JoinStage.builder("users", userSchema).build());
    inputStages.put("emails", JoinStage.builder("emails", emailSchema).build());
    AutoJoinerContext autoJoinerContext = new MockAutoJoinerContext(inputStages, collector);
    JoinDefinition joinDefinition = joiner.define(autoJoinerContext);
    JoinCondition condition = joinDefinition.getCondition();
    Assert.assertEquals(JoinCondition.Op.EXPRESSION, condition.getOp());
    Assert.assertEquals("users.id = emails.userid", ((JoinCondition.OnExpression) condition).getExpression());
}
Also used : JoinStage(io.cdap.cdap.etl.api.join.JoinStage) HashMap(java.util.HashMap) Schema(io.cdap.cdap.api.data.schema.Schema) JoinCondition(io.cdap.cdap.etl.api.join.JoinCondition) AutoJoinerContext(io.cdap.cdap.etl.api.join.AutoJoinerContext) JoinDefinition(io.cdap.cdap.etl.api.join.JoinDefinition) MockFailureCollector(io.cdap.cdap.etl.mock.validation.MockFailureCollector) FailureCollector(io.cdap.cdap.etl.api.FailureCollector) MockFailureCollector(io.cdap.cdap.etl.mock.validation.MockFailureCollector) Test(org.junit.Test)

Example 22 with MockFailureCollector

use of io.cdap.cdap.etl.mock.validation.MockFailureCollector in project hydrator-plugins by cdapio.

the class JoinerConfigTest method testOutputSchemaForInvalidKeys.

@Test
public void testOutputSchemaForInvalidKeys() {
    // film_id is Long but it should be String, OutputSchema call should throw an exception
    Schema filmCategorySchema = Schema.recordOf("filmCategory", Schema.Field.of("film_id", Schema.of(Schema.Type.LONG)), Schema.Field.of("film_name", Schema.of(Schema.Type.STRING)), Schema.Field.of("category_name", Schema.of(Schema.Type.STRING)));
    String joinKeys = "film.film_id=filmActor.film_id=filmCategory.film_id";
    String selectedFields = "film.film_id, film.film_name, filmActor.actor_name as renamed_actor, " + "filmCategory.category_name as renamed_category";
    String requiredInputs = "film,filmActor,filmCategory";
    JoinerConfig config = new JoinerConfig(joinKeys, selectedFields, requiredInputs);
    Joiner joiner = new Joiner(config);
    FailureCollector collector = new MockFailureCollector();
    Map<String, JoinStage> inputStages = new HashMap<>();
    inputStages.put("film", JoinStage.builder("film", FILM_SCHEMA).build());
    inputStages.put("filmActor", JoinStage.builder("filmActor", FILM_ACTOR_SCHEMA).build());
    inputStages.put("filmCategory", JoinStage.builder("filmCategory", filmCategorySchema).build());
    AutoJoinerContext autoJoinerContext = new MockAutoJoinerContext(inputStages, collector);
    try {
        joiner.define(autoJoinerContext);
        Assert.fail();
    } catch (ValidationException e) {
        Assert.assertEquals(2, e.getFailures().size());
        // Assert first failure
        Assert.assertEquals(1, e.getFailures().get(0).getCauses().size());
        Cause expectedCause = new Cause();
        expectedCause.addAttribute(CauseAttributes.STAGE_CONFIG, JoinerConfig.JOIN_KEYS);
        expectedCause.addAttribute(STAGE, MOCK_STAGE);
        Assert.assertEquals(expectedCause, e.getFailures().get(0).getCauses().get(0));
        // Assert second failure
        Assert.assertEquals(1, e.getFailures().get(1).getCauses().size());
        Assert.assertEquals(expectedCause, e.getFailures().get(1).getCauses().get(0));
    }
}
Also used : JoinStage(io.cdap.cdap.etl.api.join.JoinStage) ValidationException(io.cdap.cdap.etl.api.validation.ValidationException) HashMap(java.util.HashMap) Schema(io.cdap.cdap.api.data.schema.Schema) AutoJoinerContext(io.cdap.cdap.etl.api.join.AutoJoinerContext) Cause(io.cdap.cdap.etl.api.validation.ValidationFailure.Cause) MockFailureCollector(io.cdap.cdap.etl.mock.validation.MockFailureCollector) FailureCollector(io.cdap.cdap.etl.api.FailureCollector) MockFailureCollector(io.cdap.cdap.etl.mock.validation.MockFailureCollector) Test(org.junit.Test)

Example 23 with MockFailureCollector

use of io.cdap.cdap.etl.mock.validation.MockFailureCollector in project hydrator-plugins by cdapio.

the class JoinerConfigTest method testJoinerConfigWithoutSelectedFields.

@Test
public void testJoinerConfigWithoutSelectedFields() {
    JoinerConfig config = new JoinerConfig("film.film_id=filmActor.film_id=filmCategory.film_id&" + "film.film_name=filmActor.film_name=filmCategory.film_name", "", "film,filmActor,filmCategory");
    FailureCollector failureCollector = new MockFailureCollector();
    try {
        config.getSelectedFields(failureCollector);
    } catch (ValidationException e) {
        Assert.assertEquals(1, e.getFailures().size());
        ValidationFailure failure = e.getFailures().get(0);
        Assert.assertEquals(1, failure.getCauses().size());
        Cause cause = failure.getCauses().get(0);
        Assert.assertEquals(JoinerConfig.SELECTED_FIELDS, cause.getAttribute(CauseAttributes.STAGE_CONFIG));
    }
}
Also used : ValidationException(io.cdap.cdap.etl.api.validation.ValidationException) Cause(io.cdap.cdap.etl.api.validation.ValidationFailure.Cause) MockFailureCollector(io.cdap.cdap.etl.mock.validation.MockFailureCollector) FailureCollector(io.cdap.cdap.etl.api.FailureCollector) MockFailureCollector(io.cdap.cdap.etl.mock.validation.MockFailureCollector) ValidationFailure(io.cdap.cdap.etl.api.validation.ValidationFailure) Test(org.junit.Test)

Example 24 with MockFailureCollector

use of io.cdap.cdap.etl.mock.validation.MockFailureCollector in project hydrator-plugins by cdapio.

the class JoinerConfigTest method testJoinerConfigWithMostSkewedInput.

@Test
public void testJoinerConfigWithMostSkewedInput() {
    JoinerConfig config;
    Joiner joiner;
    FailureCollector collector;
    AutoJoinerContext autoJoinerContext;
    JoinDefinition joinDefinition;
    // Test stages reordering - film
    config = new JoinerConfig("film.film_id=filmActor.film_id=filmCategory.film_id&" + "film.film_name=filmActor.film_name=filmCategory.film_name", SELECTED_FIELDS, "film,filmActor,filmCategory", "film");
    joiner = new Joiner(config);
    collector = new MockFailureCollector();
    autoJoinerContext = new MockAutoJoinerContext(INPUT_STAGES, collector);
    joinDefinition = joiner.define(autoJoinerContext);
    Assert.assertNotNull(joinDefinition);
    Assert.assertNotNull(joinDefinition.getStages());
    Assert.assertEquals("film", joinDefinition.getStages().get(0).getStageName());
    // Test stages reordering - filmActor
    config = new JoinerConfig("film.film_id=filmActor.film_id=filmCategory.film_id&" + "film.film_name=filmActor.film_name=filmCategory.film_name", SELECTED_FIELDS, "film,filmActor,filmCategory", "filmActor");
    joiner = new Joiner(config);
    collector = new MockFailureCollector();
    autoJoinerContext = new MockAutoJoinerContext(INPUT_STAGES, collector);
    joinDefinition = joiner.define(autoJoinerContext);
    Assert.assertNotNull(joinDefinition);
    Assert.assertNotNull(joinDefinition.getStages());
    Assert.assertEquals("filmActor", joinDefinition.getStages().get(0).getStageName());
    // Test stages reordering - filmCategory
    config = new JoinerConfig("film.film_id=filmActor.film_id=filmCategory.film_id&" + "film.film_name=filmActor.film_name=filmCategory.film_name", SELECTED_FIELDS, "film,filmActor,filmCategory", "filmCategory");
    joiner = new Joiner(config);
    collector = new MockFailureCollector();
    autoJoinerContext = new MockAutoJoinerContext(INPUT_STAGES, collector);
    joinDefinition = joiner.define(autoJoinerContext);
    Assert.assertNotNull(joinDefinition);
    Assert.assertNotNull(joinDefinition.getStages());
    Assert.assertEquals("filmCategory", joinDefinition.getStages().get(0).getStageName());
}
Also used : AutoJoinerContext(io.cdap.cdap.etl.api.join.AutoJoinerContext) JoinDefinition(io.cdap.cdap.etl.api.join.JoinDefinition) MockFailureCollector(io.cdap.cdap.etl.mock.validation.MockFailureCollector) FailureCollector(io.cdap.cdap.etl.api.FailureCollector) MockFailureCollector(io.cdap.cdap.etl.mock.validation.MockFailureCollector) Test(org.junit.Test)

Example 25 with MockFailureCollector

use of io.cdap.cdap.etl.mock.validation.MockFailureCollector in project hydrator-plugins by cdapio.

the class FTPBatchSourceTest method testFTPPathWithSystemPropertiesAndSpecialCharactersInAuth.

@Test
public void testFTPPathWithSystemPropertiesAndSpecialCharactersInAuth() {
    FailureCollector collector = new MockFailureCollector();
    FTPBatchSource.FTPBatchSourceConfig config = new FTPBatchSource.FTPBatchSourceConfig();
    final HashMap<String, String> fileSystemProperties = new HashMap<>();
    config.configuration(String.format("%s://%s:%s@%s:%d%s", FTP_PREFIX, USER, PASSWORD_WITH_SPECIAL_CHARACTERS, HOST, FTP_DEFAULT_PORT, PATH), "{\"fs.sftp.impl\": \"org.apache.hadoop.fs.sftp.SFTPFileSystem\"}");
    config.validate(collector);
    fileSystemProperties.put("fs.ftp.host", HOST);
    fileSystemProperties.put(String.format("fs.ftp.user.%s", HOST), USER);
    fileSystemProperties.put(String.format("fs.ftp.password.%s", HOST), PASSWORD_WITH_SPECIAL_CHARACTERS);
    fileSystemProperties.put("fs.ftp.host.port", String.valueOf(FTP_DEFAULT_PORT));
    fileSystemProperties.put(FS_SFTP_IMPL, SFTP_FS_CLASS);
    Assert.assertEquals(5, config.getFileSystemProperties(collector).size());
    Assert.assertEquals(fileSystemProperties, config.getFileSystemProperties(collector));
}
Also used : HashMap(java.util.HashMap) MockFailureCollector(io.cdap.cdap.etl.mock.validation.MockFailureCollector) MockFailureCollector(io.cdap.cdap.etl.mock.validation.MockFailureCollector) FailureCollector(io.cdap.cdap.etl.api.FailureCollector) Test(org.junit.Test)

Aggregations

MockFailureCollector (io.cdap.cdap.etl.mock.validation.MockFailureCollector)36 Test (org.junit.Test)36 FailureCollector (io.cdap.cdap.etl.api.FailureCollector)31 Schema (io.cdap.cdap.api.data.schema.Schema)11 AutoJoinerContext (io.cdap.cdap.etl.api.join.AutoJoinerContext)11 HashMap (java.util.HashMap)10 ValidationException (io.cdap.cdap.etl.api.validation.ValidationException)9 Cause (io.cdap.cdap.etl.api.validation.ValidationFailure.Cause)9 JoinDefinition (io.cdap.cdap.etl.api.join.JoinDefinition)6 JoinStage (io.cdap.cdap.etl.api.join.JoinStage)5 ValidationFailure (io.cdap.cdap.etl.api.validation.ValidationFailure)5 JoinField (io.cdap.cdap.etl.api.join.JoinField)2 AbstractFileSourceConfig (io.cdap.plugin.format.plugin.AbstractFileSourceConfig)2 List (java.util.List)2 StructuredRecord (io.cdap.cdap.api.data.format.StructuredRecord)1 JoinCondition (io.cdap.cdap.etl.api.join.JoinCondition)1 MockPipelineConfigurer (io.cdap.cdap.etl.mock.common.MockPipelineConfigurer)1