Search in sources :

Example 21 with Table

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

the class CompositeMetadataStore method findGroup.

public Table findGroup(String fullName) throws QueryMetadataException {
    int index = fullName.indexOf(TransformationMetadata.DELIMITER_STRING);
    if (index == -1) {
        throw new QueryMetadataException(QueryPlugin.Event.TEIID30353, fullName + TransformationMetadata.NOT_EXISTS_MESSAGE);
    }
    String schemaName = fullName.substring(0, index);
    Schema schema = getSchema(schemaName);
    if (schema == null) {
        throw new QueryMetadataException(QueryPlugin.Event.TEIID30352, fullName + TransformationMetadata.NOT_EXISTS_MESSAGE);
    }
    Table result = schema.getTables().get(fullName.substring(index + 1));
    if (result == null) {
        throw new QueryMetadataException(QueryPlugin.Event.TEIID30354, fullName + TransformationMetadata.NOT_EXISTS_MESSAGE);
    }
    return result;
}
Also used : Table(org.teiid.metadata.Table) Schema(org.teiid.metadata.Schema) QueryMetadataException(org.teiid.api.exception.query.QueryMetadataException)

Example 22 with Table

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

the class TestSessionAwareCache method testTtl.

@Test
public void testTtl() {
    SessionAwareCache<Cachable> cache = new SessionAwareCache<Cachable>("resultset", DefaultCacheFactory.INSTANCE, SessionAwareCache.Type.RESULTSET, 0);
    CacheID id = new CacheID(buildWorkContext(), new ParseInfo(), "SELECT * FROM FOO");
    Cachable result = Mockito.mock(Cachable.class);
    // make sure defaults are returned
    assertNull(cache.computeTtl(id, result, null));
    assertEquals(Long.valueOf(1), cache.computeTtl(id, result, 1l));
    AccessInfo ai = new AccessInfo();
    Mockito.stub(result.getAccessInfo()).toReturn(ai);
    Table t = new Table();
    t.setProperty(DataModifiable.DATA_TTL, "2");
    ai.addAccessedObject(t);
    assertEquals(Long.valueOf(2), cache.computeTtl(id, result, null));
    Table t1 = new Table();
    Schema s = new Schema();
    t1.setParent(s);
    s.setProperty(DataModifiable.DATA_TTL, "0");
    ai.addAccessedObject(t1);
    // ensure that the min and the parent are used
    assertEquals(Long.valueOf(0), cache.computeTtl(id, result, null));
}
Also used : Table(org.teiid.metadata.Table) CacheID(org.teiid.dqp.internal.process.SessionAwareCache.CacheID) Schema(org.teiid.metadata.Schema) ParseInfo(org.teiid.query.parser.ParseInfo) Cachable(org.teiid.cache.Cachable) Test(org.junit.Test)

Example 23 with Table

use of org.teiid.metadata.Table 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 24 with Table

use of org.teiid.metadata.Table 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 25 with Table

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

the class ODataSQLBuilder method selectWithEntityKey.

// TODO: allow the generated key building.
public Query selectWithEntityKey(EdmEntityType entityType, Entity entity, Map<String, Object> generatedKeys, List<ExpandNode> expand) throws TeiidException {
    Table table = findTable(entityType.getName(), this.metadata);
    DocumentNode resource = new DocumentNode(table, new GroupSymbol(table.getFullName()), entityType);
    resource.setFromClause(new UnaryFromClause(new GroupSymbol(table.getFullName())));
    resource.addAllColumns(false);
    this.context = resource;
    Query query = this.context.buildQuery();
    processExpand(expand, resource, query, 1);
    Criteria criteria = null;
    KeyRecord pk = ODataSchemaBuilder.getIdentifier(table);
    for (Column c : pk.getColumns()) {
        Property prop = entity.getProperty(c.getName());
        Constant right = null;
        if (prop != null) {
            right = new Constant(ODataTypeManager.convertToTeiidRuntimeType(c.getJavaType(), prop.getValue(), null));
        } else {
            Object value = generatedKeys.get(c.getName());
            if (value == null) {
                throw new TeiidProcessingException(ODataPlugin.Util.gs(ODataPlugin.Event.TEIID16016, entityType.getName()));
            }
            right = new Constant(value);
        }
        ElementSymbol left = new ElementSymbol(c.getName(), this.context.getGroupSymbol());
        if (criteria == null) {
            criteria = new CompareCriteria(left, AbstractCompareCriteria.EQ, right);
        } else {
            CompareCriteria rightCC = new CompareCriteria(left, AbstractCompareCriteria.EQ, right);
            criteria = new CompoundCriteria(CompoundCriteria.AND, criteria, rightCC);
        }
    }
    query.setCriteria(criteria);
    return query;
}
Also used : ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) Table(org.teiid.metadata.Table) Constant(org.teiid.query.sql.symbol.Constant) TeiidProcessingException(org.teiid.core.TeiidProcessingException) KeyRecord(org.teiid.metadata.KeyRecord) Column(org.teiid.metadata.Column) GroupSymbol(org.teiid.query.sql.symbol.GroupSymbol) Property(org.apache.olingo.commons.api.data.Property) EdmNavigationProperty(org.apache.olingo.commons.api.edm.EdmNavigationProperty) EdmProperty(org.apache.olingo.commons.api.edm.EdmProperty)

Aggregations

Table (org.teiid.metadata.Table)239 Test (org.junit.Test)82 Column (org.teiid.metadata.Column)72 MetadataFactory (org.teiid.metadata.MetadataFactory)59 Properties (java.util.Properties)45 MetadataStore (org.teiid.metadata.MetadataStore)37 Schema (org.teiid.metadata.Schema)35 TranslatorException (org.teiid.translator.TranslatorException)30 ArrayList (java.util.ArrayList)27 TransformationMetadata (org.teiid.query.metadata.TransformationMetadata)27 RealMetadataFactory (org.teiid.query.unittest.RealMetadataFactory)23 List (java.util.List)22 ForeignKey (org.teiid.metadata.ForeignKey)22 Connection (java.sql.Connection)15 QueryNode (org.teiid.query.mapping.relational.QueryNode)15 BasicSourceCapabilities (org.teiid.query.optimizer.capabilities.BasicSourceCapabilities)15 KeyRecord (org.teiid.metadata.KeyRecord)14 Dimension (org.teiid.translator.couchbase.CouchbaseMetadataProcessor.Dimension)14 CouchbaseMetadataProcessor (org.teiid.translator.couchbase.CouchbaseMetadataProcessor)13 CouchbaseProperties (org.teiid.translator.couchbase.CouchbaseProperties)13