Search in sources :

Example 1 with MetadataStore

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

the class TestMetaDataProcessor method examplePrivatePhysicalModel.

public static TransformationMetadata examplePrivatePhysicalModel() {
    MetadataStore metadataStore = new MetadataStore();
    // Create models
    // $NON-NLS-1$
    Schema pm1 = RealMetadataFactory.createPhysicalModel("pm1", metadataStore);
    // $NON-NLS-1$
    Schema vm1 = RealMetadataFactory.createVirtualModel("vm1", metadataStore);
    // Create physical groups
    // $NON-NLS-1$
    Table pm1g1 = RealMetadataFactory.createPhysicalGroup("g1", pm1);
    // $NON-NLS-1$ //$NON-NLS-2$
    QueryNode vm1g1n1 = new QueryNode("SELECT * FROM pm1.g1");
    // $NON-NLS-1$
    Table vm1g1 = RealMetadataFactory.createVirtualGroup("g1", vm1, vm1g1n1);
    // $NON-NLS-1$
    Table pm1g2 = RealMetadataFactory.createPhysicalGroup("g2", pm1);
    // Create physical elements
    RealMetadataFactory.createElements(pm1g1, // $NON-NLS-1$
    new String[] { "e1" }, new String[] { DataTypeManager.DefaultDataTypes.SHORT });
    // Create physical elements
    List<Column> pm1g2e = RealMetadataFactory.createElements(pm1g2, // $NON-NLS-1$
    new String[] { "e1" }, new String[] { DataTypeManager.DefaultDataTypes.BIG_DECIMAL });
    Column e1 = pm1g2e.get(0);
    e1.setPrecision(19);
    e1.setLength(21);
    e1.setScale(4);
    RealMetadataFactory.createElements(vm1g1, // $NON-NLS-1$
    new String[] { "e1" }, new String[] { DataTypeManager.DefaultDataTypes.STRING });
    // Create the facade from the store
    return RealMetadataFactory.createTransformationMetadata(metadataStore, "example");
}
Also used : MetadataStore(org.teiid.metadata.MetadataStore) Table(org.teiid.metadata.Table) Column(org.teiid.metadata.Column) QueryNode(org.teiid.query.mapping.relational.QueryNode) Schema(org.teiid.metadata.Schema)

Example 2 with MetadataStore

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

the class TestMetadataFactory method setUp.

@Before
public void setUp() {
    MetadataStore metadataStore = new MetadataStore();
    CompositeMetadataStore store = new CompositeMetadataStore(metadataStore);
    VDBMetaData vdbMetaData = new VDBMetaData();
    // $NON-NLS-1$
    vdbMetaData.setName("foo");
    vdbMetaData.setVersion(1);
    Map<String, VDBResources.Resource> vdbEntries = new LinkedHashMap<String, VDBResources.Resource>();
    vdbEntries.put(MY_RESOURCE_PATH, new VDBResources.Resource(root.getChild("foo")));
    metadataFactory = new RuntimeMetadataImpl(new TransformationMetadata(vdbMetaData, store, vdbEntries, null, null));
}
Also used : MetadataStore(org.teiid.metadata.MetadataStore) CompositeMetadataStore(org.teiid.query.metadata.CompositeMetadataStore) TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) CompositeMetadataStore(org.teiid.query.metadata.CompositeMetadataStore) VDBMetaData(org.teiid.adminapi.impl.VDBMetaData) VDBResources(org.teiid.query.metadata.VDBResources) LinkedHashMap(java.util.LinkedHashMap) Before(org.junit.Before)

Example 3 with MetadataStore

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

the class TestODataIntegration method testBasicTypes.

@Test
public void testBasicTypes() throws Exception {
    try {
        ModelMetaData mmd = new ModelMetaData();
        mmd.setName("m");
        mmd.addSourceMapping("x3", "x3", null);
        MetadataStore ms = RealMetadataFactory.exampleBQTStore();
        Schema s = ms.getSchema("BQT1");
        KeyRecord pk = new KeyRecord(KeyRecord.Type.Primary);
        Table smalla = s.getTable("SmallA");
        pk.setName("pk");
        pk.addColumn(smalla.getColumnByName("IntKey"));
        smalla.setPrimaryKey(pk);
        String ddl = DDLStringVisitor.getDDLString(s, EnumSet.allOf(SchemaObjectType.class), "SmallA");
        mmd.addSourceMetadata("DDL", ddl);
        HardCodedExecutionFactory hc = buildHardCodedExecutionFactory();
        teiid.addTranslator("x3", hc);
        teiid.deployVDB("northwind", mmd);
        localClient = getClient(teiid.getDriver(), "northwind", new Properties());
        ContentResponse response = http.GET(baseURL + "/northwind/m/SmallA?$format=json&$select=TimeValue");
        assertEquals(200, response.getStatus());
    } finally {
        localClient = null;
        teiid.undeployVDB("northwind");
    }
}
Also used : MetadataStore(org.teiid.metadata.MetadataStore) KeyRecord(org.teiid.metadata.KeyRecord) Table(org.teiid.metadata.Table) ContentResponse(org.eclipse.jetty.client.api.ContentResponse) Schema(org.teiid.metadata.Schema) HardCodedExecutionFactory(org.teiid.runtime.HardCodedExecutionFactory) Properties(java.util.Properties) SchemaObjectType(org.teiid.adminapi.Admin.SchemaObjectType) ModelMetaData(org.teiid.adminapi.impl.ModelMetaData) Test(org.junit.Test)

Example 4 with MetadataStore

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

the class TestODataSQLBuilder method setup.

private BaseState setup(String ddl, String url, String method, ServletInputStream stream, BaseState state) throws Exception {
    Client client = Mockito.mock(Client.class);
    DDLHolder model = new DDLHolder("PM1", ddl);
    TransformationMetadata metadata = RealMetadataFactory.fromDDL("vdb", model);
    MetadataStore store = metadata.getMetadataStore();
    // TranslationUtility utility = new TranslationUtility(metadata);
    OData odata = OData4Impl.newInstance();
    org.teiid.metadata.Schema teiidSchema = store.getSchema("PM1");
    CsdlSchema schema = ODataSchemaBuilder.buildMetadata("vdb", teiidSchema);
    TeiidEdmProvider edmProvider = new TeiidEdmProvider("baseuri", schema, "x");
    ServiceMetadata serviceMetadata = odata.createServiceMetadata(edmProvider, Collections.<EdmxReference>emptyList());
    ODataHttpHandler handler = odata.createHandler(serviceMetadata);
    Hashtable<String, String> headers = new Hashtable<String, String>();
    headers.put("Content-Type", "application/json");
    Mockito.stub(client.getMetadataStore()).toReturn(store);
    Mockito.stub(client.executeCount(Mockito.any(Query.class), Mockito.anyListOf(SQLParameter.class))).toReturn(new CountResponse() {

        @Override
        public int getCount() {
            return 10;
        }
    });
    HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
    Mockito.stub(request.getHeaderNames()).toReturn(headers.keys());
    Mockito.stub(request.getHeaders("Content-Type")).toReturn(headers.elements());
    Mockito.stub(request.getMethod()).toReturn(method);
    String requestURL = url;
    String queryString = "";
    int idx = url.indexOf("?");
    if (idx != -1) {
        requestURL = url.substring(0, idx);
        queryString = url.substring(idx + 1);
    }
    Mockito.stub(request.getRequestURL()).toReturn(new StringBuffer(requestURL));
    Mockito.stub(request.getQueryString()).toReturn(queryString);
    Mockito.stub(request.getServletPath()).toReturn("");
    Mockito.stub(request.getContextPath()).toReturn("/odata4/vdb/PM1");
    Mockito.stub(request.getInputStream()).toReturn(stream);
    final StringBuffer sb = new StringBuffer();
    ServletOutputStream out = new ServletOutputStream() {

        @Override
        public void write(int b) throws IOException {
            sb.append((char) b);
        }

        @Override
        public boolean isReady() {
            return true;
        }

        @Override
        public void setWriteListener(WriteListener writeListener) {
        }
    };
    HttpServletResponse response = Mockito.mock(HttpServletResponse.class);
    Mockito.stub(response.getOutputStream()).toReturn(out);
    try {
        TeiidServiceHandler tsh = new TeiidServiceHandler("PM1");
        tsh.setPrepared(false);
        TeiidServiceHandler.setClient(client);
        handler.register(tsh);
        handler.process(request, response);
    } finally {
        TeiidServiceHandler.setClient(null);
    }
    ArgumentCaptor<Integer> statusCapture = ArgumentCaptor.forClass(Integer.class);
    Mockito.verify(response).setStatus(statusCapture.capture());
    state.client = client;
    state.response = sb.toString();
    state.status = statusCapture.getValue();
    return state;
}
Also used : Query(org.teiid.query.sql.lang.Query) ServletOutputStream(javax.servlet.ServletOutputStream) CsdlSchema(org.apache.olingo.commons.api.edm.provider.CsdlSchema) HttpServletRequest(javax.servlet.http.HttpServletRequest) TeiidEdmProvider(org.teiid.olingo.service.TeiidEdmProvider) DDLHolder(org.teiid.query.unittest.RealMetadataFactory.DDLHolder) Client(org.teiid.odata.api.Client) WriteListener(javax.servlet.WriteListener) OData(org.apache.olingo.server.api.OData) TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) Hashtable(java.util.Hashtable) SQLParameter(org.teiid.odata.api.SQLParameter) CountResponse(org.teiid.odata.api.CountResponse) HttpServletResponse(javax.servlet.http.HttpServletResponse) ODataHttpHandler(org.apache.olingo.server.api.ODataHttpHandler) MetadataStore(org.teiid.metadata.MetadataStore) TeiidServiceHandler(org.teiid.olingo.service.TeiidServiceHandler) ServiceMetadata(org.apache.olingo.server.api.ServiceMetadata)

Example 5 with MetadataStore

use of org.teiid.metadata.MetadataStore 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)

Aggregations

MetadataStore (org.teiid.metadata.MetadataStore)73 Schema (org.teiid.metadata.Schema)47 Test (org.junit.Test)38 Table (org.teiid.metadata.Table)37 TransformationMetadata (org.teiid.query.metadata.TransformationMetadata)22 QueryNode (org.teiid.query.mapping.relational.QueryNode)19 Column (org.teiid.metadata.Column)17 VDBMetaData (org.teiid.adminapi.impl.VDBMetaData)15 Properties (java.util.Properties)12 MetadataFactory (org.teiid.metadata.MetadataFactory)12 QueryMetadataInterface (org.teiid.query.metadata.QueryMetadataInterface)12 Procedure (org.teiid.metadata.Procedure)11 List (java.util.List)9 ModelMetaData (org.teiid.adminapi.impl.ModelMetaData)9 Connection (java.sql.Connection)8 ConnectorManagerRepository (org.teiid.dqp.internal.datamgr.ConnectorManagerRepository)8 ArrayList (java.util.ArrayList)7 ProcedureParameter (org.teiid.metadata.ProcedureParameter)7 BasicSourceCapabilities (org.teiid.query.optimizer.capabilities.BasicSourceCapabilities)7 TempMetadataStore (org.teiid.query.metadata.TempMetadataStore)6