Search in sources :

Example 31 with ModelMetaData

use of org.teiid.adminapi.impl.ModelMetaData in project teiid by teiid.

the class AccessNode method openInternal.

private void openInternal() throws TeiidComponentException, TeiidProcessingException {
    // TODO: support a partitioning concept with multi-source and full dependent join pushdown
    if (subPlans != null) {
        if (this.evaluatedPlans == null) {
            this.evaluatedPlans = new HashMap<GroupSymbol, SubqueryState>();
            for (Map.Entry<GroupSymbol, RelationalPlan> entry : subPlans.entrySet()) {
                SubqueryState state = new SubqueryState();
                RelationalPlan value = entry.getValue();
                value.reset();
                state.processor = new QueryProcessor(value, getContext().clone(), getBufferManager(), getDataManager());
                state.collector = state.processor.createBatchCollector();
                this.evaluatedPlans.put(entry.getKey(), state);
            }
        }
        BlockedException be = null;
        for (SubqueryState state : evaluatedPlans.values()) {
            try {
                state.collector.collectTuples();
            } catch (BlockedException e) {
                be = e;
            }
        }
        if (be != null) {
            throw be;
        }
    }
    /*
		 * Check to see if we need a multi-source expansion.  If the connectorBindingExpression != null, then 
		 * the logic below will handle that case
		 */
    if (multiSource && connectorBindingExpression == null) {
        synchronized (this) {
            // the description can be obtained asynchly, so we need to synchronize
            VDBMetaData vdb = getContext().getVdb();
            ModelMetaData model = vdb.getModel(getModelName());
            List<String> sources = model.getSourceNames();
            // make sure that we have the right nodes
            if (this.getChildCount() != 0 && (this.sourceNames == null || !this.sourceNames.equals(sources))) {
                this.childCount--;
                this.getChildren()[0] = null;
            }
            if (this.getChildCount() == 0) {
                sourceNames = sources;
                RelationalNode node = multiSourceModify(this, connectorBindingExpression, getContext().getMetadata(), sourceNames);
                RelationalPlan.connectExternal(node, getContext(), getDataManager(), getBufferManager());
                this.addChild(node);
            }
        }
        this.getChildren()[0].open();
        return;
    }
    // Copy command and resolve references if necessary
    if (processingCommand == null) {
        processingCommand = command;
        isUpdate = RelationalNodeUtil.isUpdate(command);
    }
    boolean needProcessing = true;
    if (this.connectorBindingExpression != null && connectorBindingId == null) {
        this.connectorBindingId = (String) getEvaluator(Collections.emptyMap()).evaluate(this.connectorBindingExpression, null);
        VDBMetaData vdb = getContext().getVdb();
        ModelMetaData model = vdb.getModel(getModelName());
        List<String> sources = model.getSourceNames();
        String replacement = this.connectorBindingId;
        if (!sources.contains(this.connectorBindingId)) {
            shouldExecute = false;
            if (command instanceof StoredProcedure) {
                StoredProcedure sp = (StoredProcedure) command;
                if (sp.returnParameters() && sp.getProjectedSymbols().size() > sp.getResultSetColumns().size()) {
                    throw new TeiidProcessingException(QueryPlugin.Event.TEIID30561, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30561, command));
                }
            }
            return;
        }
        if (!(command instanceof StoredProcedure || command instanceof Insert)) {
            processingCommand = (Command) command.clone();
            MultiSourceElementReplacementVisitor.visit(replacement, getContext().getMetadata(), processingCommand);
        }
    }
    do {
        Command atomicCommand = nextCommand();
        if (shouldEvaluate) {
            needProcessing = prepareNextCommand(atomicCommand);
            nextCommand = null;
        } else {
            needProcessing = RelationalNodeUtil.shouldExecute(atomicCommand, true);
        }
        if (needProcessing) {
            registerRequest(atomicCommand);
        }
    // We use an upper limit here to the currency because these commands have potentially large in-memory value sets
    } while (!processCommandsIndividually() && hasNextCommand() && this.tupleSources.size() < Math.max(Math.min(MAX_CONCURRENT, this.getContext().getUserRequestSourceConcurrency()), this.getContext().getUserRequestSourceConcurrency() / 2));
}
Also used : SubqueryState(org.teiid.query.processor.relational.SubqueryAwareEvaluator.SubqueryState) Insert(org.teiid.query.sql.lang.Insert) BlockedException(org.teiid.common.buffer.BlockedException) QueryProcessor(org.teiid.query.processor.QueryProcessor) ModelMetaData(org.teiid.adminapi.impl.ModelMetaData) TeiidProcessingException(org.teiid.core.TeiidProcessingException) StoredProcedure(org.teiid.query.sql.lang.StoredProcedure) QueryCommand(org.teiid.query.sql.lang.QueryCommand) Command(org.teiid.query.sql.lang.Command) WithQueryCommand(org.teiid.query.sql.lang.WithQueryCommand) VDBMetaData(org.teiid.adminapi.impl.VDBMetaData) GroupSymbol(org.teiid.query.sql.symbol.GroupSymbol) SymbolMap(org.teiid.query.sql.util.SymbolMap)

Example 32 with ModelMetaData

use of org.teiid.adminapi.impl.ModelMetaData in project teiid by teiid.

the class RealMetadataFactory method exampleMultiBindingVDB.

public static VDBMetaData exampleMultiBindingVDB() {
    VDBMetaData vdb = new VDBMetaData();
    vdb.setName("exampleMultiBinding");
    vdb.setVersion(1);
    ModelMetaData model = new ModelMetaData();
    model.setName("MultiModel");
    model.setModelType(Model.Type.PHYSICAL);
    model.setVisible(true);
    model.setSupportsMultiSourceBindings(true);
    vdb.addModel(model);
    vdb.addModel(RealMetadataFactory.createModel("Virt", false));
    return vdb;
}
Also used : VDBMetaData(org.teiid.adminapi.impl.VDBMetaData) ModelMetaData(org.teiid.adminapi.impl.ModelMetaData)

Example 33 with ModelMetaData

use of org.teiid.adminapi.impl.ModelMetaData in project teiid by teiid.

the class TestASTQueries method setUp.

@BeforeClass
public static void setUp() throws Exception {
    server = new EmbeddedServer();
    server.start(new EmbeddedConfiguration());
    LoopbackExecutionFactory loopy = new LoopbackExecutionFactory();
    loopy.setRowCount(10);
    loopy.start();
    server.addTranslator("l", loopy);
    String DDL = "CREATE FOREIGN TABLE G1 (e1 string, e2 integer);";
    ModelMetaData model = new ModelMetaData();
    model.setName("PM1");
    model.setModelType(Model.Type.PHYSICAL);
    model.setSchemaSourceType("DDL");
    model.setSchemaText(DDL);
    SourceMappingMetadata sm = new SourceMappingMetadata();
    sm.setName("loopy");
    sm.setTranslatorName("l");
    model.addSourceMapping(sm);
    server.deployVDB("test", model);
}
Also used : SourceMappingMetadata(org.teiid.adminapi.impl.SourceMappingMetadata) EmbeddedServer(org.teiid.runtime.EmbeddedServer) LoopbackExecutionFactory(org.teiid.translator.loopback.LoopbackExecutionFactory) EmbeddedConfiguration(org.teiid.runtime.EmbeddedConfiguration) ModelMetaData(org.teiid.adminapi.impl.ModelMetaData) BeforeClass(org.junit.BeforeClass)

Example 34 with ModelMetaData

use of org.teiid.adminapi.impl.ModelMetaData in project teiid by teiid.

the class TestDynamicImportedMetaData method testMultipleFK.

@Test
public void testMultipleFK() throws Exception {
    ModelMetaData mmd = new ModelMetaData();
    mmd.addSourceMetadata("ddl", "create foreign table x (y integer, z integer, primary key (y, z));" + "create foreign table z (y integer, z integer, y1 integer, z1 integer, foreign key (y, z) references x (y, z), foreign key (y1, z1) references x (y, z))");
    mmd.setName("foo");
    mmd.addSourceMapping("x", "x", "x");
    server.addTranslator("x", new ExecutionFactory());
    server.deployVDB("vdb", mmd);
    // $NON-NLS-1$
    Connection conn = server.createConnection("jdbc:teiid:vdb");
    Properties importProperties = new Properties();
    importProperties.setProperty("importer.importKeys", "true");
    MetadataFactory mf = getMetadata(importProperties, conn);
    Table t = mf.asMetadataStore().getSchemas().get("test").getTables().get("vdb.foo.z");
    List<ForeignKey> fks = t.getForeignKeys();
    assertEquals(2, fks.size());
}
Also used : Table(org.teiid.metadata.Table) MetadataFactory(org.teiid.metadata.MetadataFactory) Connection(java.sql.Connection) OracleExecutionFactory(org.teiid.translator.jdbc.oracle.OracleExecutionFactory) ExecutionFactory(org.teiid.translator.ExecutionFactory) TeiidExecutionFactory(org.teiid.translator.jdbc.teiid.TeiidExecutionFactory) Properties(java.util.Properties) ForeignKey(org.teiid.metadata.ForeignKey) ModelMetaData(org.teiid.adminapi.impl.ModelMetaData) Test(org.junit.Test)

Example 35 with ModelMetaData

use of org.teiid.adminapi.impl.ModelMetaData in project teiid by teiid.

the class TestDynamicImportedMetaData method testMultiSource.

@Test
public void testMultiSource() throws Exception {
    ModelMetaData mmd = new ModelMetaData();
    mmd.addSourceMetadata("ddl", "create foreign table x (y integer primary key);");
    mmd.setName("foo");
    mmd.addSourceMapping("x", "x", "x");
    server.addTranslator("x", new ExecutionFactory());
    server.deployVDB("vdb", mmd);
    TeiidExecutionFactory tef = new TeiidExecutionFactory() {

        @Override
        public void closeConnection(Connection connection, DataSource factory) {
        }
    };
    tef.setSupportsDirectQueryProcedure(true);
    tef.start();
    server.addTranslator("teiid", tef);
    DataSource ds = Mockito.mock(DataSource.class);
    Mockito.stub(ds.getConnection()).toReturn(server.getDriver().connect("jdbc:teiid:vdb", null));
    server.addConnectionFactory("teiid1", ds);
    server.addConnectionFactory("teiid2", ds);
    server.deployVDB(new FileInputStream(UnitTestUtil.getTestDataFile("multi.xml")));
    Connection c = server.createConnection("jdbc:teiid:multi", null);
    Statement s = c.createStatement();
    s.execute("call native('select ?', 'b')");
    ResultSet rs = s.getResultSet();
    assertTrue(rs.next());
    assertTrue(rs.next());
    assertFalse(rs.next());
    s.execute("call native(request=>'select ?', variable=>('b',), target=>'teiid1')");
    rs = s.getResultSet();
    assertTrue(rs.next());
    Object[] result = (Object[]) rs.getArray(1).getArray();
    assertArrayEquals(new Object[] { "b" }, result);
    assertFalse(rs.next());
}
Also used : TeiidExecutionFactory(org.teiid.translator.jdbc.teiid.TeiidExecutionFactory) Statement(java.sql.Statement) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) OracleExecutionFactory(org.teiid.translator.jdbc.oracle.OracleExecutionFactory) ExecutionFactory(org.teiid.translator.ExecutionFactory) TeiidExecutionFactory(org.teiid.translator.jdbc.teiid.TeiidExecutionFactory) FileInputStream(java.io.FileInputStream) ModelMetaData(org.teiid.adminapi.impl.ModelMetaData) DataSource(javax.sql.DataSource) Test(org.junit.Test)

Aggregations

ModelMetaData (org.teiid.adminapi.impl.ModelMetaData)191 Test (org.junit.Test)131 Properties (java.util.Properties)50 ContentResponse (org.eclipse.jetty.client.api.ContentResponse)45 HardCodedExecutionFactory (org.teiid.runtime.HardCodedExecutionFactory)43 VDBMetaData (org.teiid.adminapi.impl.VDBMetaData)36 Connection (java.sql.Connection)23 MetadataFactory (org.teiid.metadata.MetadataFactory)21 Statement (java.sql.Statement)19 ResultSet (java.sql.ResultSet)18 CallableStatement (java.sql.CallableStatement)16 TransformationMetadata (org.teiid.query.metadata.TransformationMetadata)15 ArrayList (java.util.ArrayList)13 StringContentProvider (org.eclipse.jetty.client.util.StringContentProvider)11 SourceMappingMetadata (org.teiid.adminapi.impl.SourceMappingMetadata)11 Table (org.teiid.metadata.Table)11 RealMetadataFactory (org.teiid.query.unittest.RealMetadataFactory)11 List (java.util.List)9 ConnectorManager (org.teiid.dqp.internal.datamgr.ConnectorManager)9 ConnectorManagerRepository (org.teiid.dqp.internal.datamgr.ConnectorManagerRepository)9