Search in sources :

Example 56 with MetadataFactory

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;
}
Also used : TeiidExecutionFactory(org.teiid.translator.jdbc.teiid.TeiidExecutionFactory) MetadataFactory(org.teiid.metadata.MetadataFactory)

Example 57 with MetadataFactory

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());
}
Also used : MetadataStore(org.teiid.metadata.MetadataStore) ProcedureParameter(org.teiid.metadata.ProcedureParameter) Table(org.teiid.metadata.Table) MetadataFactory(org.teiid.metadata.MetadataFactory) Column(org.teiid.metadata.Column) Connection(java.sql.Connection) Procedure(org.teiid.metadata.Procedure) Properties(java.util.Properties) Test(org.junit.Test)

Example 58 with MetadataFactory

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));
}
Also used : MetadataRepository(org.teiid.metadata.MetadataRepository) Table(org.teiid.metadata.Table) MetadataFactory(org.teiid.metadata.MetadataFactory) ByteArrayInputStream(java.io.ByteArrayInputStream) ExecutionFactory(org.teiid.translator.ExecutionFactory) TranslatorException(org.teiid.translator.TranslatorException) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 59 with MetadataFactory

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);
}
Also used : Table(org.teiid.metadata.Table) MetadataFactory(org.teiid.metadata.MetadataFactory) TranslatorException(org.teiid.translator.TranslatorException) ModelMetaData(org.teiid.adminapi.impl.ModelMetaData) Test(org.junit.Test)

Example 60 with MetadataFactory

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;
}
Also used : UDFSource(org.teiid.query.function.UDFSource) TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) FunctionTree(org.teiid.query.function.FunctionTree) RealMetadataFactory(org.teiid.query.unittest.RealMetadataFactory) MetadataFactory(org.teiid.metadata.MetadataFactory) MetadataValidator(org.teiid.query.metadata.MetadataValidator) File(java.io.File) ValidatorReport(org.teiid.query.validator.ValidatorReport) FileConnection(org.teiid.translator.FileConnection)

Aggregations

MetadataFactory (org.teiid.metadata.MetadataFactory)159 Test (org.junit.Test)116 RealMetadataFactory (org.teiid.query.unittest.RealMetadataFactory)91 Properties (java.util.Properties)74 Table (org.teiid.metadata.Table)59 TransformationMetadata (org.teiid.query.metadata.TransformationMetadata)35 Procedure (org.teiid.metadata.Procedure)30 ModelMetaData (org.teiid.adminapi.impl.ModelMetaData)21 Column (org.teiid.metadata.Column)20 Connection (java.sql.Connection)18 FunctionTree (org.teiid.query.function.FunctionTree)15 UDFSource (org.teiid.query.function.UDFSource)14 CouchbaseMetadataProcessor (org.teiid.translator.couchbase.CouchbaseMetadataProcessor)14 Dimension (org.teiid.translator.couchbase.CouchbaseMetadataProcessor.Dimension)14 CouchbaseProperties (org.teiid.translator.couchbase.CouchbaseProperties)14 TranslationUtility (org.teiid.cdk.api.TranslationUtility)13 ValidatorReport (org.teiid.query.validator.ValidatorReport)13 XMLMetadata (org.apache.olingo.client.api.edm.xml.XMLMetadata)12 ClientCsdlXMLMetadata (org.apache.olingo.client.core.edm.ClientCsdlXMLMetadata)12 ForeignKey (org.teiid.metadata.ForeignKey)12