Search in sources :

Example 81 with TeiidProcessingException

use of org.teiid.core.TeiidProcessingException in project teiid by teiid.

the class DeferredMetadataProvider method loadFullMetadata.

private void loadFullMetadata() throws SQLException {
    MetadataResult results;
    try {
        results = this.statement.getDQP().getMetadata(this.requestID);
    } catch (TeiidComponentException e) {
        throw TeiidSQLException.create(e);
    } catch (TeiidProcessingException e) {
        throw TeiidSQLException.create(e);
    }
    this.metadata = results.getColumnMetadata();
}
Also used : TeiidComponentException(org.teiid.core.TeiidComponentException) MetadataResult(org.teiid.client.metadata.MetadataResult) TeiidProcessingException(org.teiid.core.TeiidProcessingException)

Example 82 with TeiidProcessingException

use of org.teiid.core.TeiidProcessingException in project teiid by teiid.

the class TestFunctionPushdown method testMustPushdownOverGrouping.

@Test
public void testMustPushdownOverGrouping() throws Exception {
    TransformationMetadata tm = RealMetadataFactory.fromDDL("create foreign function func (param integer) returns integer; create foreign table g1 (e1 integer)", "x", "y");
    BasicSourceCapabilities bsc = new BasicSourceCapabilities();
    bsc.setCapabilitySupport(Capability.SELECT_WITHOUT_FROM, true);
    bsc.setCapabilitySupport(Capability.QUERY_SELECT_EXPRESSION, true);
    final DefaultCapabilitiesFinder capFinder = new DefaultCapabilitiesFinder(bsc);
    CommandContext cc = TestProcessor.createCommandContext();
    cc.setQueryProcessorFactory(new QueryProcessor.ProcessorFactory() {

        @Override
        public PreparedPlan getPreparedPlan(String query, String recursionGroup, CommandContext commandContext, QueryMetadataInterface metadata) throws TeiidProcessingException, TeiidComponentException {
            return null;
        }

        @Override
        public CapabilitiesFinder getCapabiltiesFinder() {
            return capFinder;
        }

        @Override
        public QueryProcessor createQueryProcessor(String query, String recursionGroup, CommandContext commandContext, Object... params) throws TeiidProcessingException, TeiidComponentException {
            // TODO Auto-generated method stub
            return null;
        }
    });
    cc.setMetadata(tm);
    // $NON-NLS-1$
    String sql = "select func(e1) from g1 group by e1";
    ProcessorPlan plan = helpPlan(sql, tm, null, capFinder, new String[] { "SELECT y.g1.e1 FROM y.g1" }, // $NON-NLS-1$
    ComparisonMode.EXACT_COMMAND_STRING);
    HardcodedDataManager dataManager = new HardcodedDataManager();
    dataManager.addData("SELECT y.g1.e1 FROM y.g1", new List[] { Arrays.asList(1), Arrays.asList(2) });
    dataManager.addData("SELECT func(1)", new List[] { Arrays.asList(2) });
    dataManager.addData("SELECT func(2)", new List[] { Arrays.asList(3) });
    TestProcessor.helpProcess(plan, cc, dataManager, new List[] { Arrays.asList(2), Arrays.asList(3) });
}
Also used : TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) CommandContext(org.teiid.query.util.CommandContext) BasicSourceCapabilities(org.teiid.query.optimizer.capabilities.BasicSourceCapabilities) DefaultCapabilitiesFinder(org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder) TeiidProcessingException(org.teiid.core.TeiidProcessingException) FakeCapabilitiesFinder(org.teiid.query.optimizer.capabilities.FakeCapabilitiesFinder) CapabilitiesFinder(org.teiid.query.optimizer.capabilities.CapabilitiesFinder) DefaultCapabilitiesFinder(org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder) PreparedPlan(org.teiid.dqp.internal.process.PreparedPlan) TeiidComponentException(org.teiid.core.TeiidComponentException) QueryMetadataInterface(org.teiid.query.metadata.QueryMetadataInterface) Test(org.junit.Test)

Example 83 with TeiidProcessingException

use of org.teiid.core.TeiidProcessingException in project teiid by teiid.

the class TestInsertProcessing method helpInsertIntoWithSubquery.

public void helpInsertIntoWithSubquery(Capability cap, boolean txn) throws Exception {
    FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
    BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
    caps.setCapabilitySupport(cap, true);
    caps.setCapabilitySupport(Capability.QUERY_FROM_GROUP_ALIAS, false);
    // $NON-NLS-1$
    capFinder.addCapabilities("pm1", caps);
    QueryMetadataInterface metadata = RealMetadataFactory.example1Cached();
    HardcodedDataManager dataManager = new HardcodedDataManager() {

        @Override
        public TupleSource registerRequest(CommandContext context, Command command, String modelName, RegisterRequestParameter parameterObject) throws TeiidComponentException {
            if (command instanceof Insert) {
                Insert insert = (Insert) command;
                if (insert.getTupleSource() != null) {
                    commandHistory.add(insert);
                    TupleSource ts = insert.getTupleSource();
                    int count = 0;
                    try {
                        while (ts.nextTuple() != null) {
                            count++;
                        }
                        return CollectionTupleSource.createUpdateCountArrayTupleSource(count);
                    } catch (TeiidProcessingException e) {
                        throw new RuntimeException(e);
                    }
                }
            }
            return super.registerRequest(context, command, modelName, parameterObject);
        }
    };
    List[] data = new List[txn ? 2 : 50];
    for (int i = 1; i <= data.length; i++) {
        data[i - 1] = Arrays.asList(String.valueOf(i), i, (i % 2 == 0) ? Boolean.TRUE : Boolean.FALSE, Double.valueOf(i));
    }
    // $NON-NLS-1$
    dataManager.addData(// $NON-NLS-1$
    "SELECT pm1.g1.e1, pm1.g1.e2, pm1.g1.e3, pm1.g1.e4 FROM pm1.g1", data);
    if (cap != null) {
        switch(cap) {
            case BATCHED_UPDATES:
                // $NON-NLS-1$
                dataManager.addData(// $NON-NLS-1$
                "BatchedUpdate{I,I}", new List[] { Arrays.asList(1), Arrays.asList(1) });
                break;
            case INSERT_WITH_QUERYEXPRESSION:
                // $NON-NLS-1$
                dataManager.addData(// $NON-NLS-1$
                "INSERT INTO pm1.g2 (e1, e2, e3, e4) SELECT pm1.g1.e1, pm1.g1.e2, pm1.g1.e3, pm1.g1.e4 FROM pm1.g1", new List[] { Arrays.asList(new Object[] { 2 }) });
                break;
        }
    } else {
        // $NON-NLS-1$
        dataManager.addData(// $NON-NLS-1$
        "INSERT INTO pm1.g2 (e1, e2, e3, e4) VALUES ('1', 1, FALSE, 1.0)", new List[] { Arrays.asList(new Object[] { new Integer(1) }) });
        // $NON-NLS-1$
        dataManager.addData(// $NON-NLS-1$
        "INSERT INTO pm1.g2 (e1, e2, e3, e4) VALUES ('2', 2, TRUE, 2.0)", new List[] { Arrays.asList(new Object[] { new Integer(1) }) });
    }
    // $NON-NLS-1$
    String sql = "INSERT INTO pm1.g2 SELECT pm1.g1.e1, pm1.g1.e2, pm1.g1.e3, pm1.g1.e4 from pm1.g1";
    Command command = helpParse(sql);
    ProcessorPlan plan = helpGetPlan(command, metadata, capFinder);
    List<?>[] expected = new List[] { Arrays.asList(txn ? 2 : 50) };
    CommandContext cc = TestProcessor.createCommandContext();
    if (!txn) {
        TransactionContext tc = new TransactionContext();
        cc.setTransactionContext(tc);
        cc.setBufferManager(null);
        cc.setProcessorBatchSize(2);
    }
    helpProcess(plan, cc, dataManager, expected);
    // check the command hist to ensure it contains the expected commands
    if (cap == Capability.BATCHED_UPDATES) {
        BatchedUpdateCommand bu = (BatchedUpdateCommand) dataManager.getCommandHistory().get(1);
        assertEquals(2, bu.getUpdateCommands().size());
        // $NON-NLS-1$
        assertEquals("INSERT INTO pm1.g2 (e1, e2, e3, e4) VALUES ('1', 1, FALSE, 1.0)", bu.getUpdateCommands().get(0).toString());
        // $NON-NLS-1$
        assertEquals("INSERT INTO pm1.g2 (e1, e2, e3, e4) VALUES ('2', 2, TRUE, 2.0)", bu.getUpdateCommands().get(1).toString());
    } else if (cap == Capability.INSERT_WITH_ITERATOR) {
        assertEquals(txn ? 6 : 9, dataManager.getCommandHistory().size());
    }
}
Also used : FakeCapabilitiesFinder(org.teiid.query.optimizer.capabilities.FakeCapabilitiesFinder) CommandContext(org.teiid.query.util.CommandContext) BasicSourceCapabilities(org.teiid.query.optimizer.capabilities.BasicSourceCapabilities) Insert(org.teiid.query.sql.lang.Insert) BatchedUpdateCommand(org.teiid.query.sql.lang.BatchedUpdateCommand) TeiidProcessingException(org.teiid.core.TeiidProcessingException) TeiidRuntimeException(org.teiid.core.TeiidRuntimeException) Command(org.teiid.query.sql.lang.Command) BatchedUpdateCommand(org.teiid.query.sql.lang.BatchedUpdateCommand) TupleSource(org.teiid.common.buffer.TupleSource) TransactionContext(org.teiid.dqp.service.TransactionContext) List(java.util.List) QueryMetadataInterface(org.teiid.query.metadata.QueryMetadataInterface)

Example 84 with TeiidProcessingException

use of org.teiid.core.TeiidProcessingException in project teiid by teiid.

the class TestBatchIterator method testNoSaveForwardOnly.

@Test
public void testNoSaveForwardOnly() throws Exception {
    BatchIterator bi = new BatchIterator(new FakeRelationalNode(1, new List[] { Arrays.asList(1), Arrays.asList(1), Arrays.asList(1), Arrays.asList(1) }, 2) {

        @Override
        public TupleBatch nextBatchDirect() throws BlockedException, TeiidComponentException, TeiidProcessingException {
            TupleBatch tb = super.nextBatchDirect();
            tb.setRowOffset(tb.getBeginRow() + 3);
            return tb;
        }
    });
    BufferManager bm = BufferManagerFactory.getStandaloneBufferManager();
    TupleBuffer tb = bm.createTupleBuffer(Arrays.asList(new ElementSymbol("x", null, DataTypeManager.DefaultDataClasses.INTEGER)), "test", TupleSourceType.PROCESSOR);
    tb.setForwardOnly(true);
    // $NON-NLS-1$
    bi.setBuffer(tb, false);
    tb.addTuple(Arrays.asList(2));
    tb.addTuple(Arrays.asList(2));
    tb.addTuple(Arrays.asList(2));
    assertEquals(3, bi.getBuffer().getManagedRowCount());
    bi.nextTuple();
    // pull the first batch
    assertEquals(2, bi.available());
    assertEquals(0, bi.getBuffer().getManagedRowCount());
    for (int i = 0; i < 2; i++) {
        assertNotNull(bi.nextTuple());
        assertEquals(0, bi.getBuffer().getManagedRowCount());
    }
    bi.readAhead(3);
    assertEquals(2, bi.getBuffer().getManagedRowCount());
    for (int i = 0; i < 4; i++) {
        assertNotNull(bi.nextTuple());
        assertEquals(0, bi.getBuffer().getManagedRowCount());
    }
    assertNull(bi.nextTuple());
    assertEquals(0, bi.getBuffer().getManagedRowCount());
}
Also used : ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) TupleBuffer(org.teiid.common.buffer.TupleBuffer) List(java.util.List) TeiidComponentException(org.teiid.core.TeiidComponentException) FakeRelationalNode(org.teiid.query.processor.relational.FakeRelationalNode) BufferManager(org.teiid.common.buffer.BufferManager) BlockedException(org.teiid.common.buffer.BlockedException) TeiidProcessingException(org.teiid.core.TeiidProcessingException) TupleBatch(org.teiid.common.buffer.TupleBatch) Test(org.junit.Test)

Example 85 with TeiidProcessingException

use of org.teiid.core.TeiidProcessingException in project teiid by teiid.

the class TestProcedureProcessor method testBeginAtomic.

@Test
public void testBeginAtomic() throws Exception {
    String proc = // $NON-NLS-1$
    "CREATE VIRTUAL PROCEDURE " + // $NON-NLS-1$
    "BEGIN ATOMIC" + // $NON-NLS-1$
    " select e1, e2, e3, e4 into #t1 from pm1.g1;\n" + // $NON-NLS-1$
    " update #t1 set e1 = 1 where e4 < 2;\n" + // $NON-NLS-1$
    " delete from #t1 where e4 > 2;\n" + // $NON-NLS-1$
    " select e2/\"in\" from #t1;\n" + // $NON-NLS-1$
    "END";
    TransformationMetadata tm = RealMetadataFactory.example1();
    addProc(tm, "sq1", proc, new String[] { "e1" }, new String[] { DataTypeManager.DefaultDataTypes.INTEGER }, new String[] { "in" }, new String[] { DataTypeManager.DefaultDataTypes.INTEGER });
    FakeDataManager dataMgr = exampleDataManager(tm);
    // $NON-NLS-1$
    CommandContext context = new CommandContext("pID", null, null, null, 1);
    QueryMetadataInterface metadata = new TempMetadataAdapter(tm, new TempMetadataStore());
    context.setMetadata(metadata);
    TransactionContext tc = new TransactionContext();
    TransactionService ts = Mockito.mock(TransactionService.class);
    context.setTransactionService(ts);
    context.setTransactionContext(tc);
    // $NON-NLS-1$
    String userQuery = "EXEC pm1.sq1(1)";
    ProcessorPlan plan = getProcedurePlan(userQuery, tm, TestOptimizer.getGenericFinder());
    List[] expected = new List[] { Arrays.asList(5) };
    TestProcessor.helpProcess(plan, context, dataMgr, expected);
    Mockito.verify(ts, Mockito.times(3)).begin(tc);
    Mockito.verify(ts, Mockito.times(3)).commit(tc);
    tc = new TransactionContext();
    ts = Mockito.mock(TransactionService.class);
    context.setTransactionService(ts);
    context.setTransactionContext(tc);
    // $NON-NLS-1$
    userQuery = "EXEC pm1.sq1(0)";
    plan = getProcedurePlan(userQuery, tm, TestOptimizer.getGenericFinder());
    expected = null;
    try {
        TestProcessor.helpProcess(plan, context, dataMgr, expected);
        fail();
    } catch (TeiidProcessingException e) {
    }
    Mockito.verify(ts).begin(tc);
    Mockito.verify(ts, Mockito.times(2)).resume(tc);
    Mockito.verify(ts, Mockito.times(0)).commit(tc);
    Mockito.verify(ts).rollback(tc);
}
Also used : TempMetadataAdapter(org.teiid.query.metadata.TempMetadataAdapter) TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) CommandContext(org.teiid.query.util.CommandContext) TransactionService(org.teiid.dqp.service.TransactionService) FakeDataManager(org.teiid.query.processor.FakeDataManager) TeiidProcessingException(org.teiid.core.TeiidProcessingException) TransactionContext(org.teiid.dqp.service.TransactionContext) List(java.util.List) ArrayList(java.util.ArrayList) QueryMetadataInterface(org.teiid.query.metadata.QueryMetadataInterface) ProcessorPlan(org.teiid.query.processor.ProcessorPlan) TempMetadataStore(org.teiid.query.metadata.TempMetadataStore) Test(org.junit.Test)

Aggregations

TeiidProcessingException (org.teiid.core.TeiidProcessingException)92 TeiidComponentException (org.teiid.core.TeiidComponentException)30 IOException (java.io.IOException)17 ArrayList (java.util.ArrayList)17 TeiidRuntimeException (org.teiid.core.TeiidRuntimeException)17 SQLException (java.sql.SQLException)16 BlockedException (org.teiid.common.buffer.BlockedException)16 Test (org.junit.Test)14 CommandContext (org.teiid.query.util.CommandContext)14 LanguageObject (org.teiid.query.sql.LanguageObject)13 ElementSymbol (org.teiid.query.sql.symbol.ElementSymbol)13 GroupSymbol (org.teiid.query.sql.symbol.GroupSymbol)12 List (java.util.List)11 QueryMetadataInterface (org.teiid.query.metadata.QueryMetadataInterface)10 TransformationMetadata (org.teiid.query.metadata.TransformationMetadata)10 QueryPlannerException (org.teiid.api.exception.query.QueryPlannerException)9 TupleSource (org.teiid.common.buffer.TupleSource)9 TupleBatch (org.teiid.common.buffer.TupleBatch)8 CollectionTupleSource (org.teiid.query.processor.CollectionTupleSource)7 BasicSourceCapabilities (org.teiid.query.optimizer.capabilities.BasicSourceCapabilities)6