use of io.cdap.cdap.etl.mock.validation.MockFailureCollector in project hydrator-plugins by cdapio.
the class JoinerConfigTest method testJoinerConfigWithInvalidJoinKeys.
@Test
public void testJoinerConfigWithInvalidJoinKeys() {
String selectedFields = "film.film_id, film.film_name, " + "filmActor.actor_name as renamed_actor, filmCategory.category_name as renamed_category";
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)));
JoinerConfig config = new JoinerConfig("film.film_id=filmActor.film_id=filmCategory.film_id&" + "film.film_name=filmActor.film_name=filmCategory.film_name", selectedFields, "film,filmActor,filmCategory");
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("fileCategory", JoinStage.builder("filmCategory", filmCategorySchema).build());
AutoJoinerContext autoJoinerContext = new MockAutoJoinerContext(inputStages, collector);
try {
joiner.define(autoJoinerContext);
} 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, JoinerConfig.JOIN_KEYS);
expectedCause.addAttribute("stage", "mockstage");
Assert.assertEquals(JoinerConfig.JOIN_KEYS, e.getFailures().get(0).getCauses().get(0).getAttribute(CauseAttributes.STAGE_CONFIG));
}
}
use of io.cdap.cdap.etl.mock.validation.MockFailureCollector in project hydrator-plugins by cdapio.
the class JoinerConfigTest method testJoinerConfigWithSelectedFields.
@Test
public void testJoinerConfigWithSelectedFields() {
JoinerConfig 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");
List<JoinField> expected = Arrays.asList(new JoinField("film", "film_id", "film_id"), new JoinField("film", "film_name", "film_name"), new JoinField("filmActor", "actor_name", "renamed_actor"), new JoinField("filmCategory", "category_name", "renamed_category"));
Assert.assertEquals(expected, config.getSelectedFields(new MockFailureCollector()));
}
use of io.cdap.cdap.etl.mock.validation.MockFailureCollector in project hydrator-plugins by cdapio.
the class JoinerConfigTest method testJoinerConfigWithWrongJoinKeys.
@Test
public void testJoinerConfigWithWrongJoinKeys() {
JoinerConfig config = new JoinerConfig("film.film_id=filmCategory.film_id&" + "film.film_name=filmActor.film_name=filmCategory.film_name", SELECTED_FIELDS, "film,filmActor,filmCategory");
FailureCollector failureCollector = new MockFailureCollector();
try {
config.getJoinKeys(failureCollector);
Assert.fail();
} catch (ValidationException e) {
Assert.assertEquals(1, e.getFailures().size());
ValidationFailure failure = e.getFailures().get(0);
Assert.assertEquals(1, failure.getCauses().size());
ValidationFailure.Cause cause = failure.getCauses().get(0);
Assert.assertEquals(JoinerConfig.JOIN_KEYS, cause.getAttribute(CauseAttributes.STAGE_CONFIG));
}
}
use of io.cdap.cdap.etl.mock.validation.MockFailureCollector in project hydrator-plugins by cdapio.
the class JoinerConfigTest method testJoinerConfig.
@Test
public void testJoinerConfig() {
JoinerConfig 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");
Joiner joiner = new Joiner(config);
FailureCollector collector = new MockFailureCollector();
AutoJoinerContext autoJoinerContext = new MockAutoJoinerContext(INPUT_STAGES, collector);
JoinDefinition joinDefinition = joiner.define(autoJoinerContext);
Assert.assertEquals(OUTPUT_SCHEMA, joinDefinition.getOutputSchema());
Assert.assertEquals(0, collector.getValidationFailures().size());
}
use of io.cdap.cdap.etl.mock.validation.MockFailureCollector in project hydrator-plugins by cdapio.
the class JoinerConfigTest method testAdvancedOuterRequiresBroadcast.
@Test
public void testAdvancedOuterRequiresBroadcast() {
JoinerConfig conf = new JoinerConfig("users.id, emails.email", "users.id = emails.userid", Collections.singleton("users"));
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());
inputStages.put("users2", JoinStage.builder("users2", userSchema).build());
AutoJoinerContext autoJoinerContext = new MockAutoJoinerContext(inputStages, collector);
try {
joiner.define(autoJoinerContext);
Assert.fail("Advanced left outer join without broadcast did not fail as expected.");
} catch (ValidationException e) {
List<ValidationFailure> failures = e.getFailures();
Assert.assertEquals(1, failures.size());
List<ValidationFailure.Cause> causes = failures.get(0).getCauses();
Assert.assertEquals(1, causes.size());
Assert.assertEquals(JoinerConfig.CONDITION_TYPE, causes.get(0).getAttribute(CauseAttributes.STAGE_CONFIG));
}
}
Aggregations