Search in sources :

Example 46 with Schema

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

the class TestCoherenceTranslator method getTradeTranslationUtility.

/**
 * this is used as an alternative to loading the vdb
 * @return
 */
private TranslationUtility getTradeTranslationUtility() {
    MetadataStore metadataStore = new MetadataStore();
    // Create TRADE
    // $NON-NLS-1$
    Schema trading = RealMetadataFactory.createPhysicalModel("Trade_Object", metadataStore);
    // Create physical groups
    // $NON-NLS-1$
    Table trade = RealMetadataFactory.createPhysicalGroup("TRADE", trading);
    trade.setNameInSource("org.teiid.translator.coherence.Trade");
    // Create physical elements
    String[] elemNames = new String[] { // $NON-NLS-1$ //$NON-NLS-2$
    "NAME", // $NON-NLS-1$ //$NON-NLS-2$
    "TRADEID" };
    String[] elemTypes = new String[] { DataTypeManager.DefaultDataTypes.STRING, DataTypeManager.DefaultDataTypes.LONG };
    List<Column> cols = RealMetadataFactory.createElements(trade, elemNames, elemTypes);
    // Set name in source on each column
    String[] nameInSource = new String[] { "Name", "TradeId" };
    for (int i = 0; i < nameInSource.length; i++) {
        cols.get(i).setNameInSource(nameInSource[i]);
    }
    List<Column> keys = new ArrayList(1);
    keys.add(cols.get(1));
    KeyRecord trade_pk = RealMetadataFactory.createKey(Type.Primary, "TradeID_PK", trade, keys);
    // LEG
    // $NON-NLS-1$
    Table leg = RealMetadataFactory.createPhysicalGroup("LEG", trading);
    leg.setNameInSource("org.teiid.translator.coherence.Leg");
    // Create physical elements
    String[] legNames = new String[] { // $NON-NLS-1$ //$NON-NLS-2$
    "LEGID", // $NON-NLS-1$ //$NON-NLS-2$
    "NOTATIONAL", // $NON-NLS-1$ //$NON-NLS-2$
    "NAME", // $NON-NLS-1$ //$NON-NLS-2$
    "TRADEID" };
    String[] legTypes = new String[] { DataTypeManager.DefaultDataTypes.LONG, DataTypeManager.DefaultDataTypes.DOUBLE, DataTypeManager.DefaultDataTypes.STRING, DataTypeManager.DefaultDataTypes.LONG };
    List<Column> legcols = RealMetadataFactory.createElements(leg, legNames, legTypes);
    // Set name in source on each column
    String[] legnameInSource = new String[] { "LegId", "Notational", "Name", "TradeId" };
    for (int i = 0; i < legnameInSource.length; i++) {
        legcols.get(i).setNameInSource(legnameInSource[i]);
    }
    legcols.get(3).setSelectable(false);
    legcols.get(3).setUpdatable(false);
    List<Column> legkeys = new ArrayList(1);
    keys.add(legcols.get(0));
    RealMetadataFactory.createKey(Type.Primary, "Leg_ID_PK", leg, legkeys);
    List<Column> foreignkey = new ArrayList(1);
    foreignkey.add(legcols.get(3));
    ForeignKey fk = RealMetadataFactory.createForeignKey("TRADE_FK", leg, foreignkey, trade_pk);
    fk.setNameInSource("Legs");
    fk.setParent(trade);
    // Set column-specific properties
    // cols.get(0).setSelectable(false);
    // cols.get(0).setSearchType(SearchType.Unsearchable);
    Schema tradeview = RealMetadataFactory.createVirtualModel("Trade_View", metadataStore);
    QueryNode qn = new QueryNode("SELECT Trade_Object.Trade.TradeID, Trade_Object.Trade.Name, Trade_Object.Leg.LegID, Trade_Object.Leg.Notational, Trade_Object.Leg.Name AS LegName " + " FROM Trade_Object.Trade, Trade_Object.Leg " + "WHERE	Trade_Object.Trade.TradeID = Trade_Object.Leg.TradeID " + "SELECT * FROM Trade.Trad " + " WHERE Trade.Trade.TradeID = Trade.Trade.TradeID");
    Table trades = RealMetadataFactory.createVirtualGroup("Trades", tradeview, qn);
    return new TranslationUtility(RealMetadataFactory.createTransformationMetadata(metadataStore, "Trade"));
}
Also used : Table(org.teiid.metadata.Table) Schema(org.teiid.metadata.Schema) ArrayList(java.util.ArrayList) TranslationUtility(org.teiid.cdk.api.TranslationUtility) ForeignKey(org.teiid.metadata.ForeignKey) MetadataStore(org.teiid.metadata.MetadataStore) KeyRecord(org.teiid.metadata.KeyRecord) Column(org.teiid.metadata.Column) QueryNode(org.teiid.query.mapping.relational.QueryNode)

Example 47 with Schema

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

the class AccessInfo method restore.

/**
 * Restore reconnects to the live metadata objects
 * @throws TeiidComponentException
 * @throws TeiidProcessingException
 */
void restore() throws TeiidComponentException, TeiidProcessingException {
    if (this.objectsAccessed != null) {
        return;
    }
    VDBMetaData vdb = DQPWorkContext.getWorkContext().getVDB();
    TransformationMetadata tm = vdb.getAttachment(TransformationMetadata.class);
    GlobalTableStore globalStore = vdb.getAttachment(GlobalTableStore.class);
    if (!externalNames.isEmpty()) {
        this.objectsAccessed = new HashSet<Object>(externalNames.size());
        for (List<String> key : this.externalNames) {
            if (key.size() == 1) {
                String matTableName = key.get(0);
                TempMetadataID id = globalStore.getGlobalTempTableMetadataId(matTableName);
                if (id == null) {
                    // if the id is null, then create a local instance
                    String viewFullName = matTableName.substring(RelationalPlanner.MAT_PREFIX.length());
                    id = globalStore.getGlobalTempTableMetadataId(tm.getGroupID(viewFullName));
                }
                this.objectsAccessed.add(id);
            } else {
                Schema s = tm.getMetadataStore().getSchema(key.get(0));
                Modifiable m = s.getTables().get(key.get(1));
                if (m == null) {
                    m = s.getProcedures().get(key.get(1));
                }
                if (m != null) {
                    this.objectsAccessed.add(m);
                }
            }
        }
    } else {
        this.objectsAccessed = Collections.emptySet();
    }
    this.externalNames = null;
}
Also used : TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) GlobalTableStore(org.teiid.query.tempdata.GlobalTableStore) VDBMetaData(org.teiid.adminapi.impl.VDBMetaData) Schema(org.teiid.metadata.Schema) TempMetadataID(org.teiid.query.metadata.TempMetadataID) DataModifiable(org.teiid.metadata.AbstractMetadataRecord.DataModifiable) Modifiable(org.teiid.metadata.AbstractMetadataRecord.Modifiable)

Example 48 with Schema

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

the class TestDDLStringVisitor method testFK.

@Test
public void testFK() throws Exception {
    String ddl = "CREATE FOREIGN TABLE G1(\"g1-e1\" integer, g1e2 varchar, PRIMARY KEY(\"g1-e1\", g1e2));\n" + "CREATE FOREIGN TABLE G2( g2e1 integer, g2e2 varchar, " + "FOREIGN KEY (g2e1, g2e2) REFERENCES G1 (\"g1-e1\", g1e2))";
    String expected = "CREATE FOREIGN TABLE G1 (\n" + "	\"g1-e1\" integer,\n" + "	g1e2 string,\n" + "	PRIMARY KEY(\"g1-e1\", g1e2)\n" + ");\n" + "\n" + "CREATE FOREIGN TABLE G2 (\n" + "	g2e1 integer,\n" + "	g2e2 string,\n" + "	FOREIGN KEY(g2e1, g2e2) REFERENCES G1 (\"g1-e1\", g1e2)\n" + ");";
    TransformationMetadata vdb = RealMetadataFactory.fromDDL(ddl, "x", "y");
    Schema s = vdb.getModelID("y");
    String metadataDDL = DDLStringVisitor.getDDLString(s, null, null);
    assertEquals(expected, metadataDDL);
}
Also used : Schema(org.teiid.metadata.Schema) Test(org.junit.Test)

Example 49 with Schema

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

the class EvaluatorIterator method createTransformationMetadata.

public static TransformationMetadata createTransformationMetadata(String ddl) {
    MetadataStore mds = new MetadataStore();
    MetadataFactory mf = new MetadataFactory("vdb", 1, IMPLICIT_MODEL_NAME, SystemMetadata.getInstance().getRuntimeTypeMap(), new Properties(), null);
    QueryParser.getQueryParser().parseDDL(mf, ddl);
    mf.mergeInto(mds);
    CompositeMetadataStore store = new CompositeMetadataStore(mds);
    VDBMetaData vdbMetaData = new VDBMetaData();
    // $NON-NLS-1$
    vdbMetaData.setName("vdb");
    vdbMetaData.setVersion(1);
    List<FunctionTree> udfs = new ArrayList<FunctionTree>();
    for (Schema schema : store.getSchemas().values()) {
        vdbMetaData.addModel(createModel(schema.getName(), schema.isPhysical()));
    }
    TransformationMetadata metadata = new TransformationMetadata(vdbMetaData, store, null, SFM.getSystemFunctions(), udfs);
    vdbMetaData.addAttchment(TransformationMetadata.class, metadata);
    vdbMetaData.addAttchment(QueryMetadataInterface.class, metadata);
    return metadata;
}
Also used : CompositeMetadataStore(org.teiid.query.metadata.CompositeMetadataStore) MetadataStore(org.teiid.metadata.MetadataStore) TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) CompositeMetadataStore(org.teiid.query.metadata.CompositeMetadataStore) FunctionTree(org.teiid.query.function.FunctionTree) MetadataFactory(org.teiid.metadata.MetadataFactory) VDBMetaData(org.teiid.adminapi.impl.VDBMetaData) Schema(org.teiid.metadata.Schema) ArrayList(java.util.ArrayList) Properties(java.util.Properties)

Example 50 with Schema

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

the class MarshallerBuilder method getWireMap.

public static TreeMap<Integer, TableWireFormat> getWireMap(Table parentTbl, RuntimeMetadata metadata) throws TranslatorException {
    TreeMap<Integer, TableWireFormat> wireMap = buildWireMap(parentTbl, false, metadata);
    Schema schema = parentTbl.getParent();
    for (Table table : schema.getTables().values()) {
        if (table.equals(parentTbl)) {
            continue;
        }
        String mergeName = ProtobufMetadataProcessor.getMerge(table);
        if (mergeName != null && mergeName.equals(parentTbl.getFullName())) {
            // one 2 many relation
            int parentTag = ProtobufMetadataProcessor.getParentTag(table);
            String childName = ProtobufMetadataProcessor.getMessageName(table);
            TableWireFormat child = new TableWireFormat(childName, parentTag);
            wireMap.put(child.getReadTag(), child);
            TreeMap<Integer, TableWireFormat> childWireMap = buildWireMap(table, true, metadata);
            for (TableWireFormat twf : childWireMap.values()) {
                child.addNested(twf);
            }
        }
    }
    return wireMap;
}
Also used : Table(org.teiid.metadata.Table) Schema(org.teiid.metadata.Schema) TableWireFormat(org.teiid.infinispan.api.TableWireFormat)

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