@Test public void testMultipleUnique() throws Exception { String ddl = "CREATE FOREIGN TABLE G1(\n" + "e1 integer primary key,\n" + "e2 varchar(10) unique,\n" + "e3 date not null unique)"; buildModel("phy1", true, this.vdb, this.store, ddl); buildTransformationMetadata(); ValidatorReport report = new MetadataValidator().validate(this.vdb, this.store); assertFalse(printError(report), report.hasItems()); }
@Test(expected=ParseException.class) public void testProcWithMultipleReturn() throws Exception { String ddl = "create foreign procedure x (out param1 string result, out param2 string result); "; buildModel("pm1", true, this.vdb, this.store,ddl); buildTransformationMetadata(); ValidatorReport report = new MetadataValidator().validate(vdb, store); assertTrue(printError(report), report.hasItems()); }
@Test public void testProcWithDuplicateParam() throws Exception { String ddl = "create foreign procedure x (out param1 string, out param1 string); "; buildModel("pm1", true, this.vdb, this.store,ddl); buildTransformationMetadata(); ValidatorReport report = new MetadataValidator().validate(vdb, store); assertTrue(printError(report), report.hasItems()); }
@Test public void testMinimalDataNoColumns() throws Exception { ModelMetaData model = new ModelMetaData(); model.setName("x"); vdb.addModel(model); MetadataFactory mf = new MetadataFactory("myVDB",1, "x", TestDDLParser.getDataTypes(), new Properties(), null); mf.addTable("y"); mf.mergeInto(store); buildTransformationMetadata(); ValidatorReport report = new MetadataValidator().validate(this.vdb, this.store); assertTrue(printError(report), report.hasItems()); }
@Test public void testConstraintNames() throws Exception { buildModel("phy1", true, this.vdb, this.store, "CREATE FOREIGN TABLE t1 ( col1 string, col2 integer, constraint x primary key (col1), constraint x unique (col2) )"); buildTransformationMetadata(); ValidatorReport report = new MetadataValidator().validate(this.vdb, this.store); assertTrue(printError(report), report.hasItems()); }
@Test public void testResolvingOrder() throws Exception { buildModel("phy1", true, this.vdb, this.store, "CREATE FOREIGN TABLE t1 ( col1 string, col2 integer ) options (updatable true); CREATE view a as select * from t1;"); buildTransformationMetadata(); ValidatorReport report = new MetadataValidator().validate(this.vdb, this.store); assertFalse(printError(report), report.hasItems()); }
@Test public void testAfterTriggerFails() throws Exception { String ddl = "CREATE FOREIGN TABLE T ( e1 integer, e2 varchar);" + "CREATE TRIGGER tr ON T AFTER INSERT AS " + "FOR EACH ROW \n" + "BEGIN ATOMIC \n" + " raise sqlexception old.e1;\n" + "END;"; buildModel("phy1", true, this.vdb, this.store, ddl); buildTransformationMetadata(); ValidatorReport report = new MetadataValidator().validate(this.vdb, this.store); //old is not resolvable with insert assertTrue(printError(report), report.hasItems()); }
@Test(expected=ParseException.class) public void testProcWithOutOfOrderReturn() throws Exception { String ddl = "create foreign procedure x (out param1 string, out param2 string result); "; buildModel("pm1", true, this.vdb, this.store,ddl); buildTransformationMetadata(); ValidatorReport report = new MetadataValidator().validate(vdb, store); assertTrue(printError(report), report.hasItems()); }
@Test public void testCreateTriggerFails() throws Exception { String ddl = "create view g1 options (updatable true) AS select * from pm1.g1; " + "create trigger on g1 instead of update as for each row begin if (\"new\" is distinct from pm1.g1) select 1; END; "; buildModel("pm1", true, this.vdb, this.store, "create foreign table g1(e1 integer, e2 varchar(12));"); buildModel("vm1", false, this.vdb, this.store, ddl); buildTransformationMetadata(); ValidatorReport report = new MetadataValidator().validate(vdb, store); assertTrue(printError(report), report.hasItems()); }
@Test public void testCreateTrigger() throws Exception { String ddl = "create view g1 options (updatable true) AS select * from pm1.g1; " + "create trigger on g1 INSTEAD OF UPDATE AS FOR EACH ROW BEGIN ATOMIC END; "; buildModel("pm1", true, this.vdb, this.store, "create foreign table g1(e1 integer, e2 varchar(12));"); buildModel("vm1", false, this.vdb, this.store, ddl); buildTransformationMetadata(); ValidatorReport report = new MetadataValidator().validate(vdb, store); assertFalse(printError(report), report.hasItems()); }
@Test public void testEmptyKey() throws Exception { String ddl = "CREATE FOREIGN TABLE G1(g1e1 integer, g1e2 varchar, PRIMARY KEY(g1e1, g1e2));"; buildModel("pm1", true, this.vdb, this.store, ddl); buildTransformationMetadata(); this.store.getSchema("pm1").getTable("G1").getPrimaryKey().getColumns().clear(); ValidatorReport report = new ValidatorReport(); report = new MetadataValidator().validate(this.vdb, this.store); assertTrue(printError(report), report.hasItems()); }
@Test public void testCrossReferenceFKNoPKonRefTable() throws Exception { // note here the unique here does not matter for non-existent reference columns, only primary key counted. String ddl = "CREATE FOREIGN TABLE G1(g1e1 integer, g1e2 varchar, UNIQUE(g1e1, g1e2));"; String ddl2 = "CREATE FOREIGN TABLE G2( g2e1 integer, g2e2 varchar, PRIMARY KEY(g2e1, g2e2), FOREIGN KEY (g2e1, g2e2) REFERENCES pm1.G1)"; buildModel("pm1", true, this.vdb, this.store, ddl); buildModel("pm2", true, this.vdb, this.store, ddl2); buildTransformationMetadata(); ValidatorReport report = new ValidatorReport(); report = new MetadataValidator().validate(this.vdb, this.store); assertTrue(printError(report), report.hasItems()); }
@Test public void testExternalMaterializationValidateMissingStatus() throws Exception { String ddl = "CREATE FOREIGN TABLE G1(e1 integer, e2 varchar); CREATE FOREIGN TABLE status(e1 integer, e2 varchar);"; String ddl2 = "CREATE VIEW G2 OPTIONS (MATERIALIZED 'true', MATERIALIZED_TABLE 'pm1.G1', \"teiid_rel:MATVIEW_STATUS_TABLE\" 'x') AS SELECT * FROM pm1.G1"; buildModel("pm1", true, this.vdb, this.store, ddl); buildModel("vm1", false, this.vdb, this.store, ddl2); buildTransformationMetadata(); ValidatorReport report = new ValidatorReport(); report = new MetadataValidator().validate(this.vdb, this.store); assertTrue(printError(report), report.hasItems()); }
@Test public void testViewKeys() throws Exception { buildModel("phy1", true, this.vdb, this.store, "CREATE FOREIGN TABLE t1 ( col1 string, col2 integer ) options (updatable true)"); buildModel("phy2", true, this.vdb, this.store, "CREATE FOREIGN TABLE t2 ( col1 string, col2 integer ) options (updatable true)"); buildModel("view1", false, this.vdb, this.store, "CREATE view vw_t1 ( col1 string, col2 integer primary key, foreign key (col2) references vw_t2 (col2) ) options (updatable true) as select * from t1;" + "CREATE view vw_t2 ( col1 string, col2 integer primary key, foreign key (col2) references vw_t1 (col2) ) options (updatable true) as select * from t2;" + "CREATE VIEW v1 ( col1 string, col2 integer ) OPTIONS (updatable 'true') AS select vw_t1.col1, vw_t1.col2 FROM vw_t1, vw_t2 where vw_t1.col2 = vw_t2.col2"); buildTransformationMetadata(); ValidatorReport report = new MetadataValidator().validate(this.vdb, this.store); assertFalse(printError(report), report.hasItems()); }
@Test public void testExternalMaterializationValidateColumns() throws Exception { String ddl = "CREATE FOREIGN TABLE G1(e2 varchar);" + STATUS; String ddl2 = "CREATE VIEW G2 (e1 integer, e2 varchar) OPTIONS (MATERIALIZED 'true', MATERIALIZED_TABLE 'pm1.G1', \"teiid_rel:MATVIEW_STATUS_TABLE\" 'pm1.status', \"teiid_rel:MATVIEW_LOAD_SCRIPT\" 'begin end') AS SELECT 1, 'a' FROM pm1.G1"; buildModel("pm1", true, this.vdb, this.store, ddl); buildModel("vm1", false, this.vdb, this.store, ddl2); buildTransformationMetadata(); ValidatorReport report = new ValidatorReport(); report = new MetadataValidator().validate(this.vdb, this.store); assertTrue(printError(report), report.hasItems()); }
@Test public void testExternalMaterializationValidateColumnTypes() throws Exception { String ddl = "CREATE FOREIGN TABLE G1(e1 integer, e2 integer);" + STATUS; String ddl2 = "CREATE VIEW G2 (e1 integer, e2 varchar) OPTIONS (MATERIALIZED 'true', MATERIALIZED_TABLE 'pm1.G1', \"teiid_rel:MATVIEW_STATUS_TABLE\" 'pm1.status', \"teiid_rel:MATVIEW_LOAD_SCRIPT\" 'begin end') AS SELECT 1, 'a' FROM pm1.G1"; buildModel("pm1", true, this.vdb, this.store, ddl); buildModel("vm1", false, this.vdb, this.store, ddl2); buildTransformationMetadata(); ValidatorReport report = new ValidatorReport(); report = new MetadataValidator().validate(this.vdb, this.store); assertTrue(printError(report), report.hasItems()); }
@Test public void testInternalMaterializationValidate() throws Exception { // note here the unique here does not matter for non-existent reference columns, only primary key counted. String ddl = "CREATE FOREIGN TABLE G1(e1 integer, e2 varchar);"; String ddl2 = "CREATE VIEW G2 OPTIONS (MATERIALIZED 'YES') AS SELECT * FROM pm1.G1"; buildModel("pm1", true, this.vdb, this.store, ddl); buildModel("vm1", false, this.vdb, this.store, ddl2); buildTransformationMetadata(); ValidatorReport report = new ValidatorReport(); report = new MetadataValidator().validate(this.vdb, this.store); assertFalse(printError(report), report.hasItems()); }
@Test public void testExternalMaterializationValidateMissingColumns() throws Exception { String ddl = "CREATE FOREIGN TABLE G1(e1 integer, e2 varchar); CREATE FOREIGN TABLE status(e1 integer, e2 varchar);"; String ddl2 = "CREATE VIEW G2 OPTIONS (MATERIALIZED 'true', MATERIALIZED_TABLE 'pm1.G1', \"teiid_rel:MATVIEW_STATUS_TABLE\" 'status') AS SELECT * FROM pm1.G1"; buildModel("pm1", true, this.vdb, this.store, ddl); buildModel("vm1", false, this.vdb, this.store, ddl2); buildTransformationMetadata(); ValidatorReport report = new ValidatorReport(); report = new MetadataValidator().validate(this.vdb, this.store); assertTrue(printError(report), report.hasItems()); }
@Test public void testExternalMaterializationValidateLoadScripts() throws Exception { String ddl = "CREATE FOREIGN TABLE G1(e1 integer, e2 varchar); CREATE FOREIGN TABLE status(e1 integer, e2 varchar);"; String ddl2 = "CREATE VIEW G2 OPTIONS (MATERIALIZED 'true', MATERIALIZED_TABLE 'pm1.G1', \"teiid_rel:MATVIEW_STATUS_TABLE\" 'status' , \"teiid_rel:MATVIEW_BEFORE_LOAD_SCRIPT\" '----') AS SELECT * FROM pm1.G1"; buildModel("pm1", true, this.vdb, this.store, ddl); buildModel("vm1", false, this.vdb, this.store, ddl2); buildTransformationMetadata(); ValidatorReport report = new ValidatorReport(); report = new MetadataValidator().validate(this.vdb, this.store); assertTrue(printError(report), report.hasItems()); }
private ValidatorReport helpTest(String ddl, boolean expectErrors) throws Exception { buildModel("pm1", true, this.vdb, this.store, ddl); buildTransformationMetadata(); ValidatorReport report = new ValidatorReport(); report = new MetadataValidator().validate(this.vdb, this.store); if (expectErrors) { assertTrue(printError(report), report.hasItems()); } else { assertFalse(printError(report), report.hasItems()); } return report; }