Search in sources :

Example 11 with Schema

use of org.teiid.metadata.Schema in project teiid by teiid.

the class TestOptimizer method testUnnamedAggInView.

@Test
public void testUnnamedAggInView() throws Exception {
    MetadataStore metadataStore = new MetadataStore();
    // $NON-NLS-1$
    Schema bqt1 = RealMetadataFactory.createPhysicalModel("BQT1", metadataStore);
    // $NON-NLS-1$
    Schema vqt = RealMetadataFactory.createVirtualModel("VQT", metadataStore);
    // $NON-NLS-1$
    Table bqt1SmallA = RealMetadataFactory.createPhysicalGroup("SmallA", bqt1);
    RealMetadataFactory.createElement("col", bqt1SmallA, DataTypeManager.DefaultDataTypes.STRING);
    Table agg3 = RealMetadataFactory.createVirtualGroup("Agg3", vqt, new QueryNode("select count(*) from smalla"));
    RealMetadataFactory.createElement("count", agg3, DataTypeManager.DefaultDataTypes.INTEGER);
    TransformationMetadata metadata = RealMetadataFactory.createTransformationMetadata(metadataStore, "x");
    BasicSourceCapabilities bac = getTypicalCapabilities();
    bac.setCapabilitySupport(Capability.QUERY_FROM_INLINE_VIEWS, true);
    bac.setCapabilitySupport(Capability.QUERY_AGGREGATES_COUNT_STAR, true);
    bac.setCapabilitySupport(Capability.QUERY_GROUP_BY, true);
    helpPlan("select count(*) from agg3", metadata, new String[] {}, new DefaultCapabilitiesFinder(bac), ComparisonMode.EXACT_COMMAND_STRING);
}
Also used : MetadataStore(org.teiid.metadata.MetadataStore) TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) Table(org.teiid.metadata.Table) BasicSourceCapabilities(org.teiid.query.optimizer.capabilities.BasicSourceCapabilities) QueryNode(org.teiid.query.mapping.relational.QueryNode) Schema(org.teiid.metadata.Schema) DefaultCapabilitiesFinder(org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder) Test(org.junit.Test)

Example 12 with Schema

use of org.teiid.metadata.Schema in project teiid by teiid.

the class TestDDLStringVisitor method testFunction.

@Test
public void testFunction() throws Exception {
    Schema s = new Schema();
    s.addFunction(MetadataFactory.createFunctionFromMethod("x", TestDDLStringVisitor.class.getMethod("someMethod", int.class)));
    String metadataDDL = DDLStringVisitor.getDDLString(s, null, null);
    assertEquals("CREATE VIRTUAL FUNCTION x(param1 integer) RETURNS string[]" + "\nOPTIONS (NAMEINSOURCE 'x', JAVA_CLASS 'org.teiid.query.metadata.TestDDLStringVisitor', JAVA_METHOD 'someMethod');", metadataDDL);
}
Also used : Schema(org.teiid.metadata.Schema) Test(org.junit.Test)

Example 13 with Schema

use of org.teiid.metadata.Schema in project teiid by teiid.

the class TestDDLStringVisitor method helpTest.

private void helpTest(String ddl, String expected) {
    Schema s = TestDDLParser.helpParse(ddl, "model").getSchema();
    String metadataDDL = DDLStringVisitor.getDDLString(s, null, null);
    assertEquals(expected, metadataDDL);
}
Also used : Schema(org.teiid.metadata.Schema)

Example 14 with Schema

use of org.teiid.metadata.Schema in project teiid by teiid.

the class TestDDLStringVisitor method testSchema.

@Test
public void testSchema() throws Exception {
    Database db = new Database("foo", "2");
    DataWrapper dw = new DataWrapper("orcle");
    db.addDataWrapper(dw);
    Server s = new Server("testing");
    s.setDataWrapper(dw.getName());
    s.setJndiName("java://test-server");
    s.setType("orcl");
    db.addServer(s);
    String table = "CREATE FOREIGN TABLE G1( e1 integer, e2 varchar)";
    Table t = TestDDLParser.helpParse(table, "SchemaA").getSchema().getTable("G1");
    Schema schema = new Schema();
    schema.setName("SchemaA");
    schema.addTable(t);
    schema.addServer(s);
    db.addSchema(schema);
    String metadataDDL = DDLStringVisitor.getDDLString(db);
    String expected = "\n" + "/*\n" + "###########################################\n" + "# START DATABASE foo\n" + "###########################################\n" + "*/\n" + "CREATE DATABASE foo VERSION '2';\n" + "USE DATABASE foo VERSION '2';" + "\n" + "\n--############ Translators ############\n" + "CREATE FOREIGN DATA WRAPPER orcle;\n" + "\n" + "\n--############ Servers ############\n" + "CREATE SERVER testing TYPE 'orcl' FOREIGN DATA WRAPPER orcle OPTIONS (\"jndi-name\" 'java://test-server');\n" + "\n" + "\n--############ Schemas ############\n" + "CREATE SCHEMA SchemaA SERVER testing;\n\n" + "\n--############ Schema:SchemaA ############\n" + "SET SCHEMA SchemaA;\n" + "\n" + "CREATE FOREIGN TABLE G1 (\n" + "\te1 integer,\n" + "\te2 string\n" + ");\n" + "/*\n" + "###########################################\n" + "# END DATABASE foo\n" + "###########################################\n" + "*/\n" + "\n";
    assertEquals(expected, metadataDDL);
}
Also used : DataWrapper(org.teiid.metadata.DataWrapper) Table(org.teiid.metadata.Table) Server(org.teiid.metadata.Server) Schema(org.teiid.metadata.Schema) Database(org.teiid.metadata.Database) Test(org.junit.Test)

Example 15 with Schema

use of org.teiid.metadata.Schema in project teiid by teiid.

the class InfinispanExecutionFactory method getMetadata.

@Override
public void getMetadata(MetadataFactory metadataFactory, InfinispanConnection conn) throws TranslatorException {
    ProtobufMetadataProcessor metadataProcessor = (ProtobufMetadataProcessor) getMetadataProcessor();
    // $NON-NLS-1$
    PropertiesUtils.setBeanProperties(metadataProcessor, metadataFactory.getModelProperties(), "importer");
    // This block is only invoked when NATIVE metadata is defined, by the time code got here if we have
    // tables already in schema, then user defined through other metadata repositories. In this case,
    // a .proto file need to be generated based on schema, then use that to generate final metadata and
    // register the .proto with the Infinispan
    Schema schema = metadataFactory.getSchema();
    ProtobufResource resource = null;
    ArrayList<Table> removedTables = new ArrayList<>();
    if (schema.getTables() != null && !schema.getTables().isEmpty()) {
        SchemaToProtobufProcessor stpp = new SchemaToProtobufProcessor();
        stpp.setIndexMessages(true);
        resource = stpp.process(metadataFactory, conn);
        metadataProcessor.setProtobufResource(resource);
        ArrayList<Table> tables = new ArrayList<>(schema.getTables().values());
        for (Table t : tables) {
            // remove the previous tables, as we want to introduce them with necessary
            // extension metadata generated with generated .proto file. As some of the default
            // extension metadata can be added.
            removedTables.add(schema.removeTable(t.getName()));
        }
    }
    metadataProcessor.process(metadataFactory, conn);
    // may be not carried forward, we need to make sure we copy those back.
    for (Table oldT : removedTables) {
        Table newT = schema.getTable(oldT.getName());
        Map<String, String> properties = oldT.getProperties();
        for (Map.Entry<String, String> entry : properties.entrySet()) {
            newT.setProperty(entry.getKey(), entry.getValue());
        }
        newT.setSupportsUpdate(oldT.supportsUpdate());
        if (oldT.getAnnotation() != null) {
            newT.setAnnotation(oldT.getAnnotation());
        }
        List<Column> columns = oldT.getColumns();
        for (Column c : columns) {
            Column newCol = newT.getColumnByName(c.getName());
            if (newCol != null) {
                Map<String, String> colProperties = c.getProperties();
                for (Map.Entry<String, String> entry : colProperties.entrySet()) {
                    newCol.setProperty(entry.getKey(), entry.getValue());
                }
                newCol.setUpdatable(c.isUpdatable());
                if (c.getAnnotation() != null) {
                    newCol.setAnnotation(c.getAnnotation());
                }
            }
        }
    }
    resource = metadataProcessor.getProtobufResource();
    if (resource == null) {
        SchemaToProtobufProcessor stpp = new SchemaToProtobufProcessor();
        resource = stpp.process(metadataFactory, conn);
    }
    // register protobuf
    if (resource != null) {
        conn.registerProtobufFile(resource);
    }
}
Also used : Table(org.teiid.metadata.Table) Schema(org.teiid.metadata.Schema) ArrayList(java.util.ArrayList) Column(org.teiid.metadata.Column) ProtobufResource(org.teiid.infinispan.api.ProtobufResource) Map(java.util.Map)

Aggregations

Schema (org.teiid.metadata.Schema)92 MetadataStore (org.teiid.metadata.MetadataStore)47 TransformationMetadata (org.teiid.query.metadata.TransformationMetadata)37 Table (org.teiid.metadata.Table)35 Test (org.junit.Test)34 QueryNode (org.teiid.query.mapping.relational.QueryNode)20 FakeCapabilitiesFinder (org.teiid.query.optimizer.capabilities.FakeCapabilitiesFinder)19 Column (org.teiid.metadata.Column)18 BasicSourceCapabilities (org.teiid.query.optimizer.capabilities.BasicSourceCapabilities)18 Procedure (org.teiid.metadata.Procedure)16 QueryMetadataInterface (org.teiid.query.metadata.QueryMetadataInterface)11 List (java.util.List)10 ArrayList (java.util.ArrayList)9 VDBMetaData (org.teiid.adminapi.impl.VDBMetaData)8 ProcedureParameter (org.teiid.metadata.ProcedureParameter)8 ModelMetaData (org.teiid.adminapi.impl.ModelMetaData)7 FunctionMethod (org.teiid.metadata.FunctionMethod)6 TempMetadataStore (org.teiid.query.metadata.TempMetadataStore)6 CompositeMetadataStore (org.teiid.query.metadata.CompositeMetadataStore)5 DefaultCapabilitiesFinder (org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder)5