use of org.teiid.query.metadata.MetadataValidator in project teiid by teiid.
the class RealMetadataFactory method fromDDL.
public static TransformationMetadata fromDDL(String vdbName, DDLHolder... schemas) throws Exception {
CompositeMetadataStore cms = new CompositeMetadataStore(Collections.EMPTY_LIST);
for (DDLHolder schema : schemas) {
MetadataFactory mf = TestDDLParser.helpParse(schema.ddl, schema.name);
cms.merge(mf.asMetadataStore());
}
TransformationMetadata tm = createTransformationMetadata(cms, vdbName);
ValidatorReport report = new MetadataValidator().validate(tm.getVdbMetaData(), tm.getMetadataStore());
if (report.hasItems()) {
throw new RuntimeException(report.getFailureMessage());
}
return tm;
}
use of org.teiid.query.metadata.MetadataValidator in project teiid by teiid.
the class TestExcelMetadataProcessor method getDDL.
static String getDDL(Properties props, String filename) throws TranslatorException, ResourceException {
ExcelExecutionFactory translator = new ExcelExecutionFactory();
translator.start();
String xlsName = props.getProperty("importer.excelFileName");
MetadataFactory mf = new MetadataFactory("vdb", 1, "people", SystemMetadata.getInstance().getRuntimeTypeMap(), props, null);
FileConnection connection = Mockito.mock(FileConnection.class);
if (xlsName.contains("*.")) {
Mockito.stub(connection.getFile(xlsName)).toReturn(UnitTestUtil.getTestDataFile(xlsName));
File f = Mockito.mock(File.class);
Mockito.stub(f.isDirectory()).toReturn(true);
Mockito.stub(f.listFiles()).toReturn(new File[] { UnitTestUtil.getTestDataFile(filename) });
Mockito.stub(connection.getFile(xlsName)).toReturn(f);
} else {
Mockito.stub(connection.getFile(xlsName)).toReturn(UnitTestUtil.getTestDataFile(xlsName));
}
translator.getMetadata(mf, connection);
TransformationMetadata metadata = RealMetadataFactory.createTransformationMetadata(mf.asMetadataStore(), "vdb", new FunctionTree("foo", new UDFSource(translator.getPushDownFunctions())));
ValidatorReport report = new MetadataValidator().validate(metadata.getVdbMetaData(), metadata.getMetadataStore());
if (report.hasItems()) {
throw new RuntimeException(report.getFailureMessage());
}
String ddl = DDLStringVisitor.getDDLString(mf.getSchema(), null, null);
return ddl;
}
use of org.teiid.query.metadata.MetadataValidator in project teiid by teiid.
the class TestVisitor method queryMetadataInterface.
private static TransformationMetadata queryMetadataInterface() {
try {
ModelMetaData mmd = new ModelMetaData();
mmd.setName("couchbase");
CouchbaseMetadataProcessor mp = new CouchbaseMetadataProcessor();
MetadataFactory mf = new MetadataFactory("couchbase", 1, SystemMetadata.getInstance().getRuntimeTypeMap(), mmd);
Table customer = createTable(mf, KEYSPACE, "Customer");
mp.scanRow(KEYSPACE, KEYSPACE_SOURCE, formCustomer(), mf, customer, customer.getName(), false, new Dimension());
Table order = createTable(mf, KEYSPACE, "Oder");
mp.scanRow(KEYSPACE, KEYSPACE_SOURCE, formOder(), mf, order, order.getName(), false, new Dimension());
Table t2 = createTable(mf, "T2", "T2");
mp.scanRow("T2", "`T2`", formDataTypeJson(), mf, t2, t2.getName(), false, new Dimension());
Table t3 = createTable(mf, "T3", "T3");
mp.scanRow("T3", "`T3`", nestedJson(), mf, t3, t3.getName(), false, new Dimension());
mp.scanRow("T3", "`T3`", nestedArray(), mf, t3, t3.getName(), false, new Dimension());
mp.addProcedures(mf, null);
TransformationMetadata tm = RealMetadataFactory.createTransformationMetadata(mf.asMetadataStore(), "x");
ValidatorReport report = new MetadataValidator().validate(tm.getVdbMetaData(), tm.getMetadataStore());
if (report.hasItems()) {
throw new RuntimeException(report.getFailureMessage());
}
return tm;
} catch (MetadataException e) {
throw new RuntimeException(e);
}
}
use of org.teiid.query.metadata.MetadataValidator in project teiid by teiid.
the class TestPhoenixUtil method queryMetadataInterface.
public static TransformationMetadata queryMetadataInterface() {
try {
ModelMetaData mmd = new ModelMetaData();
mmd.setName("HBaseModel");
MetadataFactory mf = new MetadataFactory("hbase", 1, SystemMetadata.getInstance().getRuntimeTypeMap(), mmd);
mf.setParser(new QueryParser());
mf.parse(new FileReader(UnitTestUtil.getTestDataFile("customer.ddl")));
TransformationMetadata tm = RealMetadataFactory.createTransformationMetadata(mf.asMetadataStore(), "x");
ValidatorReport report = new MetadataValidator().validate(tm.getVdbMetaData(), tm.getMetadataStore());
if (report.hasItems()) {
throw new RuntimeException(report.getFailureMessage());
}
return tm;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
use of org.teiid.query.metadata.MetadataValidator in project teiid by teiid.
the class TestDDLParser method testOptionalFKFail.
@Test
public void testOptionalFKFail() throws Exception {
String ddl = "CREATE FOREIGN TABLE G1(g1e1 integer, g1e2 varchar);\n" + "CREATE FOREIGN TABLE G2( g2e1 integer, g2e2 varchar, PRIMARY KEY(g2e1, g2e2)," + "FOREIGN KEY (g2e1, g2e2) REFERENCES G1)";
MetadataFactory s = helpParse(ddl, "model");
Map<String, Table> tableMap = s.getSchema().getTables();
assertEquals(2, tableMap.size());
assertTrue("Table not found", tableMap.containsKey("G1"));
assertTrue("Table not found", tableMap.containsKey("G2"));
Table table = tableMap.get("G2");
ForeignKey fk = table.getForeignKeys().get(0);
assertEquals(fk.getColumns(), table.getColumns());
assertEquals("G1", fk.getReferenceTableName());
VDBMetaData vdb = new VDBMetaData();
// $NON-NLS-1$
vdb.setName("myVDB");
ModelMetaData modelOne = new ModelMetaData();
// $NON-NLS-1$
modelOne.setName("model");
vdb.addModel(modelOne);
ValidatorReport report = new MetadataValidator().validate(vdb, s.asMetadataStore());
assertTrue(report.hasItems());
}
Aggregations