use of org.teiid.metadata.MetadataFactory in project teiid by teiid.
the class TestDynamicImportedMetaData method getMetadata.
private MetadataFactory getMetadata(Properties importProperties, Connection conn) throws TranslatorException {
MetadataFactory mf = createMetadataFactory("test", importProperties);
TeiidExecutionFactory tef = new TeiidExecutionFactory();
tef.getMetadata(mf, conn);
return mf;
}
use of org.teiid.metadata.MetadataFactory in project teiid by teiid.
the class TestDynamicImportedMetaData method testDDLMetadata.
@Test
public void testDDLMetadata() throws Exception {
String ddl = "CREATE FOREIGN PROCEDURE getTextFiles(IN pathAndPattern varchar) RETURNS (file clob, filpath string) OPTIONS(UUID 'uuid')";
MetadataFactory mf = createMetadataFactory("MarketData", new Properties());
QueryParser.getQueryParser().parseDDL(mf, ddl);
MetadataStore ms = mf.asMetadataStore();
String ddl2 = "CREATE VIEW stock (symbol string, price bigdecimal) OPTIONS (UUID 'uuid')" + "AS select stock.* from (call MarketData.getTextFiles('*.txt')) f, " + "TEXTTABLE(f.file COLUMNS symbol string, price bigdecimal HEADER) stock;";
MetadataFactory m2 = createMetadataFactory("portfolio", new Properties());
QueryParser.getQueryParser().parseDDL(m2, ddl2);
m2.getSchema().setPhysical(false);
m2.mergeInto(ms);
server.deployVDB("test", ms);
// $NON-NLS-1$
Connection conn = server.createConnection("jdbc:teiid:test");
Properties props = new Properties();
props.setProperty("importer.importProcedures", Boolean.TRUE.toString());
MetadataStore store = getMetadata(props, conn).asMetadataStore();
Procedure p = store.getSchema("test").getProcedure("test.MarketData.getTextFiles");
assertNotNull(p);
ProcedureParameter pp = p.getParameters().get(0);
assertEquals("pathAndPattern", pp.getName());
assertEquals("\"pathAndPattern\"", pp.getNameInSource());
assertEquals(ProcedureParameter.Type.In, pp.getType());
// assertEquals("string", pp.getDatatype().getName());
Table t = store.getSchema("test").getTable("test.portfolio.stock");
assertNotNull(t);
List<Column> columns = t.getColumns();
assertEquals(2, columns.size());
assertEquals("symbol", columns.get(0).getName());
assertEquals("price", columns.get(1).getName());
}
use of org.teiid.metadata.MetadataFactory in project teiid by teiid.
the class TestEmbeddedServer method testImportExcept.
@Ignore("limit to/exclude not yet implemented")
@Test
public void testImportExcept() throws Exception {
es.start(new EmbeddedConfiguration());
es.addMetadataRepository("x", new MetadataRepository() {
@Override
public void loadMetadata(MetadataFactory factory, ExecutionFactory executionFactory, Object connectionFactory, String text) throws TranslatorException {
assertEquals("helloworld1,other", factory.getModelProperties().get("importer.excludeTables"));
Table t = factory.addTable("helloworld");
t.setVirtual(true);
factory.addColumn("col", "string", t);
t.setSelectTransformation("select 'HELLO WORLD'");
}
});
String externalDDL = "CREATE DATABASE test VERSION '1';" + "USE DATABASE test VERSION '1';" + "CREATE VIRTUAL SCHEMA test2;" + "IMPORT FOREIGN SCHEMA public except (helloworld1, other) FROM REPOSITORY x INTO test2;";
es.deployVDB(new ByteArrayInputStream(externalDDL.getBytes(Charset.forName("UTF-8"))), true);
ResultSet rs = es.getDriver().connect("jdbc:teiid:test", null).createStatement().executeQuery("select * from helloworld");
rs.next();
assertEquals("HELLO WORLD", rs.getString(1));
}
use of org.teiid.metadata.MetadataFactory in project teiid by teiid.
the class TestEmbeddedServer method testMultiSourceMetadataMissingSource.
/**
* Check that we'll consult each source
* @throws Exception
*/
@Test
public void testMultiSourceMetadataMissingSource() throws Exception {
EmbeddedConfiguration ec = new EmbeddedConfiguration();
ec.setUseDisk(false);
es.start(ec);
es.addTranslator("t", new ExecutionFactory<Object, Object>() {
@Override
public Object getConnection(Object factory) throws TranslatorException {
return factory;
}
@Override
public void closeConnection(Object connection, Object factory) {
}
@Override
public void getMetadata(MetadataFactory metadataFactory, Object conn) throws TranslatorException {
assertNotNull(conn);
Table t = metadataFactory.addTable("x");
metadataFactory.addColumn("a", "string", t);
}
});
es.addConnectionFactory("b", new Object());
ModelMetaData mmd1 = new ModelMetaData();
mmd1.setName("b");
mmd1.setSupportsMultiSourceBindings(true);
// a is missing
mmd1.addSourceMapping("x", "t", "a");
mmd1.addSourceMapping("y", "t", "b");
es.deployVDB("vdb", mmd1);
}
use of org.teiid.metadata.MetadataFactory 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;
}
Aggregations