@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 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 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 testSourceModelArtifacts() throws Exception { String ddl = "create foreign table g1(e1 integer, e2 varchar(12)); create view g2(e1 integer, e2 varchar(12)) AS select * from foo;"; buildModel("pm1", true, this.vdb, this.store, ddl); ValidatorReport report = new ValidatorReport(); new MetadataValidator.SourceModelArtifacts().execute(vdb, store, report, new MetadataValidator()); assertFalse(printError(report), report.hasItems()); }
@Test public void testViewModelArtifacts() throws Exception { String ddl = "create foreign table g1(e1 integer, e2 varchar(12)); create view g2(e1 integer, e2 varchar(12)) AS select * from foo;"; buildModel("vm1", false, this.vdb, this.store, ddl); ValidatorReport report = new ValidatorReport(); new MetadataValidator.SourceModelArtifacts().execute(vdb, store, report, new MetadataValidator()); 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 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 testProcMetadata() throws Exception { String ddl = "create virtual procedure proc1(IN e1 varchar) RETURNS (e1 integer, e2 varchar(12)) AS begin create local temporary table x (e1 integer, e2 varchar); select * from x; end;" + "create virtual procedure proc2(IN e1 varchar) RETURNS (e1 integer, e2 varchar(12)) AS select x.* from (exec proc1('a')) as X; "; buildModel("vm1", false, this.vdb, this.store, ddl); buildTransformationMetadata(); ValidatorReport report = new ValidatorReport(); new MetadataValidator.ResolveQueryPlans().execute(vdb, store, report, new MetadataValidator()); assertFalse(printError(report), report.hasItems()); }
@Test public void testResolveTempMetadata() throws Exception { String ddl = "create virtual procedure proc1() RETURNS (e1 integer, e2 varchar(12)) AS begin create local temporary table x (e1 integer, e2 varchar); select * from x; end;" + "create view z (e1 integer, e2 varchar(12)) AS select x.* from (exec proc1()) as X, (exec proc1()) as Y; "; buildModel("vm1", false, this.vdb, this.store, ddl); buildTransformationMetadata(); ValidatorReport report = new ValidatorReport(); new MetadataValidator.ResolveQueryPlans().execute(vdb, store, report, new MetadataValidator()); assertFalse(printError(report), report.hasItems()); }
@Test public void testModelArtifactsSucess() throws Exception { buildModel("vm1", false, this.vdb, this.store, "create view g2(e1 integer, e2 varchar(12)) AS select * from foo;"); buildModel("pm1", true, this.vdb, this.store, "create foreign table g1(e1 integer, e2 varchar(12));"); ValidatorReport report = new ValidatorReport(); new MetadataValidator.SourceModelArtifacts().execute(vdb, store, report, new MetadataValidator()); 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 testProcDependencies() throws Exception { String ddl = "create virtual procedure proc1(IN e1 varchar) as begin end; " + "create virtual procedure proc2(IN e1 varchar) RETURNS (x integer) as begin call proc1(e1); select 1; end; "; buildModel("vm1", false, this.vdb, this.store, ddl); buildTransformationMetadata(); ValidatorReport report = new ValidatorReport(); new MetadataValidator.ResolveQueryPlans().execute(vdb, store, report, new MetadataValidator()); assertFalse(printError(report), report.hasItems()); }
@Test public void testInvalidView() throws Exception { String ddl = "create view g1 (e1 integer, e2 varchar(12)) AS select 'a';"; buildModel("vm1", false, this.vdb, this.store, ddl); buildTransformationMetadata(); ValidatorReport report = new ValidatorReport(); new MetadataValidator.ResolveQueryPlans().execute(vdb, store, report, new MetadataValidator()); 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; }