JoinToOneParent implements AISValidation { @Override public void validate(AkibanInformationSchema ais, AISValidationOutput output) { Set<Table> childTables = new HashSet<>(); for (Join join : ais.getJoins().values()) { if (childTables.contains(join.getChild())) { output.reportFailure(new AISValidationFailure ( new JoinToMultipleParentsException (join.getChild().getName()))); } else { childTables.add(join.getChild()); } } }  @Override void validate(AkibanInformationSchema ais, AISValidationOutput output);  }
@Test public void testValidJoins() { Assert.assertEquals(0, builder.akibanInformationSchema().validate(validations).failures().size()); }
@Test public void testTwoJoinsToOneParent() { builder.joinTables("co2", "schema", "customer", "schema", "order"); builder.joinColumns("co2", "schema", "customer", "customer_id", "schema", "order", "customer_id"); builder.groupingIsComplete(); Collection<AISValidationFailure> failures = builder.akibanInformationSchema().validate(validations).failures(); Assert.assertEquals(1, failures.size()); AISValidationFailure fail = failures.iterator().next(); Assert.assertEquals(ErrorCode.JOIN_TO_MULTIPLE_PARENTS, fail.errorCode()); }
@Test public void testTwoJoinsToTwoParents() { builder.table("schema", "address"); builder.column("schema", "address", "order_id", 0, "MCOMPAT", "int", false); builder.column("schema", "address", "customer_id", 1, "MCOMPAT", "int", false); builder.joinTables("ca", "schema", "customer", "schema", "address"); builder.joinColumns("ca", "schema", "customer", "customer_id", "schema", "address", "customer_id"); builder.joinTables("oa", "schema", "order", "schema", "address"); builder.joinColumns("oa", "schema", "order", "order_id", "schema", "address", "order_id"); builder.basicSchemaIsComplete(); builder.addJoinToGroup("group", "ca", 0); builder.groupingIsComplete(); Collection<AISValidationFailure> failures = builder.akibanInformationSchema().validate(validations).failures(); Assert.assertEquals(1, failures.size()); AISValidationFailure fail = failures.iterator().next(); Assert.assertEquals(ErrorCode.JOIN_TO_MULTIPLE_PARENTS, fail.errorCode()); }