Search in sources :

Example 1 with RegisterRequestParameter

use of org.teiid.query.processor.RegisterRequestParameter in project teiid by teiid.

the class TestTupleSourceCache method testNodeId.

@Test
public void testNodeId() throws Exception {
    TupleSourceCache tsc = new TupleSourceCache();
    HardcodedDataManager pdm = new HardcodedDataManager() {

        @Override
        public TupleSource registerRequest(CommandContext context, Command command, String modelName, RegisterRequestParameter parameterObject) throws TeiidComponentException {
            assertEquals(1, parameterObject.nodeID);
            return Mockito.mock(TupleSource.class);
        }
    };
    CommandContext context = TestProcessor.createCommandContext();
    BufferManagerImpl bufferMgr = BufferManagerFactory.createBufferManager();
    Command command = new Insert();
    RegisterRequestParameter parameterObject = new RegisterRequestParameter("z", 1, 1);
    parameterObject.info = new RegisterRequestParameter.SharedAccessInfo();
    tsc.getSharedTupleSource(context, command, "x", parameterObject, bufferMgr, pdm);
}
Also used : CommandContext(org.teiid.query.util.CommandContext) BufferManagerImpl(org.teiid.common.buffer.impl.BufferManagerImpl) HardcodedDataManager(org.teiid.query.processor.HardcodedDataManager) Command(org.teiid.query.sql.lang.Command) Insert(org.teiid.query.sql.lang.Insert) RegisterRequestParameter(org.teiid.query.processor.RegisterRequestParameter) Test(org.junit.Test)

Example 2 with RegisterRequestParameter

use of org.teiid.query.processor.RegisterRequestParameter in project teiid by teiid.

the class TestDataTierManager method testCaching.

@Test
public void testCaching() throws Exception {
    assertEquals(0, connectorManager.getExecuteCount().get());
    QueryMetadataInterface metadata = RealMetadataFactory.exampleBQTCached();
    CacheDirective cd = new CacheDirective();
    this.connectorManager.cacheDirective = cd;
    helpSetupDataTierManager();
    Command command = helpSetupRequest("SELECT stringkey from bqt1.smalla", 1, metadata).getCommand();
    RegisterRequestParameter rrp = new RegisterRequestParameter();
    rrp.connectorBindingId = "x";
    TupleSource ts = dtm.registerRequest(context, command, "foo", rrp);
    assertTrue(ts instanceof CachingTupleSource);
    assertEquals(10, pullTuples(ts, -1));
    assertEquals(1, connectorManager.getExecuteCount().get());
    assertFalse(rrp.doNotCache);
    assertFalse(((CachingTupleSource) ts).dtts.errored);
    assertNull(((CachingTupleSource) ts).dtts.scope);
    ts.closeSource();
    assertEquals(1, this.rm.getRsCache().getCachePutCount());
    assertEquals(1, this.rm.getRsCache().getTotalCacheEntries());
    // same session, should be cached
    command = helpSetupRequest("SELECT stringkey from bqt1.smalla", 1, metadata).getCommand();
    rrp = new RegisterRequestParameter();
    rrp.connectorBindingId = "x";
    ts = dtm.registerRequest(context, command, "foo", rrp);
    assertFalse(ts instanceof CachingTupleSource);
    assertEquals(10, pullTuples(ts, -1));
    assertEquals(1, connectorManager.getExecuteCount().get());
    assertTrue(rrp.doNotCache);
    // switch sessions
    command = helpSetupRequest("SELECT stringkey from bqt1.smalla", 1, metadata).getCommand();
    this.context.getSession().setSessionId("different");
    rrp = new RegisterRequestParameter();
    rrp.connectorBindingId = "x";
    ts = dtm.registerRequest(context, command, "foo", rrp);
    assertTrue(ts instanceof CachingTupleSource);
    assertEquals(9, pullTuples(ts, 9));
    assertEquals(2, connectorManager.getExecuteCount().get());
    assertFalse(rrp.doNotCache);
    // should force read all
    ts.closeSource();
    assertFalse(((CachingTupleSource) ts).dtts.errored);
    assertNull(((CachingTupleSource) ts).dtts.scope);
    assertEquals(2, this.rm.getRsCache().getCachePutCount());
    assertEquals(2, this.rm.getRsCache().getTotalCacheEntries());
    // proactive invalidation, removes immediately
    command = helpSetupRequest("SELECT stringkey from bqt1.smalla", 1, metadata).getCommand();
    cd.setInvalidation(Invalidation.IMMEDIATE);
    rrp = new RegisterRequestParameter();
    rrp.connectorBindingId = "x";
    ts = dtm.registerRequest(context, command, "foo", rrp);
    assertTrue(ts instanceof CachingTupleSource);
    assertEquals(10, pullTuples(ts, -1));
    assertEquals(3, connectorManager.getExecuteCount().get());
    assertFalse(rrp.doNotCache);
}
Also used : CacheDirective(org.teiid.translator.CacheDirective) Command(org.teiid.query.sql.lang.Command) BatchedUpdateCommand(org.teiid.query.sql.lang.BatchedUpdateCommand) TupleSource(org.teiid.common.buffer.TupleSource) QueryMetadataInterface(org.teiid.query.metadata.QueryMetadataInterface) RegisterRequestParameter(org.teiid.query.processor.RegisterRequestParameter) Test(org.junit.Test)

Example 3 with RegisterRequestParameter

use of org.teiid.query.processor.RegisterRequestParameter in project teiid by teiid.

the class TestSubqueryPushdown method testSubqueryProducingBuffer.

@Test
public void testSubqueryProducingBuffer() throws Exception {
    TransformationMetadata tm = RealMetadataFactory.example1Cached();
    String sql = "SELECT e1, (select e2 from pm2.g1 where e1 = pm1.g1.e1 order by e2 limit 1) from pm1.g1 limit 1";
    BasicSourceCapabilities bsc = getTypicalCapabilities();
    bsc.setCapabilitySupport(Capability.QUERY_ORDERBY, false);
    ProcessorPlan plan = // $NON-NLS-1$
    TestOptimizer.helpPlan(// $NON-NLS-1$
    sql, tm, null, new DefaultCapabilitiesFinder(bsc), new String[] { "SELECT g_0.e1 FROM pm1.g1 AS g_0" }, // $NON-NLS-1$
    ComparisonMode.EXACT_COMMAND_STRING);
    HardcodedDataManager hdm = new HardcodedDataManager(tm) {

        @Override
        public TupleSource registerRequest(CommandContext context, Command command, String modelName, RegisterRequestParameter parameterObject) throws TeiidComponentException {
            if (command.toString().equals("SELECT g_0.e2 FROM pm2.g1 AS g_0 WHERE g_0.e1 = 'a'")) {
                return new TupleSource() {

                    @Override
                    public List<?> nextTuple() throws TeiidComponentException, TeiidProcessingException {
                        throw new TeiidProcessingException("something's wrong");
                    }

                    @Override
                    public void closeSource() {
                    }
                };
            }
            return super.registerRequest(context, command, modelName, parameterObject);
        }
    };
    hdm.addData("SELECT g_0.e1 FROM g1 AS g_0", Arrays.asList("a"));
    hdm.setBlockOnce(true);
    CommandContext cc = TestProcessor.createCommandContext();
    cc.setMetadata(tm);
    try {
        TestProcessor.helpProcess(plan, cc, hdm, new List[] { Arrays.asList(2) });
        fail();
    } catch (TeiidProcessingException e) {
        assert (e.getMessage().contains("something's wrong"));
    }
}
Also used : TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) CommandContext(org.teiid.query.util.CommandContext) BasicSourceCapabilities(org.teiid.query.optimizer.capabilities.BasicSourceCapabilities) HardcodedDataManager(org.teiid.query.processor.HardcodedDataManager) Command(org.teiid.query.sql.lang.Command) TupleSource(org.teiid.common.buffer.TupleSource) ProcessorPlan(org.teiid.query.processor.ProcessorPlan) DefaultCapabilitiesFinder(org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder) RegisterRequestParameter(org.teiid.query.processor.RegisterRequestParameter) TeiidProcessingException(org.teiid.core.TeiidProcessingException) Test(org.junit.Test)

Example 4 with RegisterRequestParameter

use of org.teiid.query.processor.RegisterRequestParameter in project teiid by teiid.

the class AccessNode method registerRequest.

private void registerRequest(Command atomicCommand) throws TeiidComponentException, TeiidProcessingException {
    if (shouldEvaluate) {
        projection = null;
        minimizeProject(atomicCommand);
    }
    int limit = -1;
    if (getParent() instanceof LimitNode) {
        LimitNode parent = (LimitNode) getParent();
        if (parent.getLimit() > 0) {
            limit = parent.getLimit() + parent.getOffset();
        }
    }
    RegisterRequestParameter param = new RegisterRequestParameter(connectorBindingId, getID(), limit);
    param.info = info;
    param.fetchSize = this.getBatchSize();
    RowBasedSecurityHelper.checkConstraints(atomicCommand, getEvaluator(Collections.emptyMap()));
    tupleSources.add(getDataManager().registerRequest(getContext(), atomicCommand, modelName, param));
    if (tupleSources.size() > 1) {
        reserved += getBufferManager().reserveBuffers(schemaSize, BufferReserveMode.FORCE);
    }
}
Also used : RegisterRequestParameter(org.teiid.query.processor.RegisterRequestParameter)

Example 5 with RegisterRequestParameter

use of org.teiid.query.processor.RegisterRequestParameter in project teiid by teiid.

the class TupleSourceCache method getSharedTupleSource.

public TupleSource getSharedTupleSource(CommandContext context, Command command, String modelName, RegisterRequestParameter parameterObject, BufferManager bufferMgr, ProcessorDataManager pdm) throws TeiidComponentException, TeiidProcessingException {
    if (sharedStates == null) {
        sharedStates = new HashMap<Integer, SharedState>();
    }
    SharedState state = sharedStates.get(parameterObject.info.id);
    if (state == null) {
        state = new SharedState();
        state.expectedReaders = parameterObject.info.sharingCount;
        RegisterRequestParameter param = new RegisterRequestParameter(parameterObject.connectorBindingId, parameterObject.nodeID, -1);
        param.fetchSize = parameterObject.fetchSize;
        param.copyStreamingLobs = true;
        state.ts = pdm.registerRequest(context, command, modelName, param);
        if (param.doNotCache) {
            return state.ts;
        }
        state.tb = bufferMgr.createTupleBuffer(command.getProjectedSymbols(), context.getConnectionId(), TupleSourceType.PROCESSOR);
        state.id = parameterObject.info.id;
        sharedStates.put(parameterObject.info.id, state);
    }
    return new SharedTupleSource(state);
}
Also used : RegisterRequestParameter(org.teiid.query.processor.RegisterRequestParameter)

Aggregations

RegisterRequestParameter (org.teiid.query.processor.RegisterRequestParameter)10 Command (org.teiid.query.sql.lang.Command)8 Test (org.junit.Test)6 TupleSource (org.teiid.common.buffer.TupleSource)6 CommandContext (org.teiid.query.util.CommandContext)5 HardcodedDataManager (org.teiid.query.processor.HardcodedDataManager)4 ProcessorPlan (org.teiid.query.processor.ProcessorPlan)4 ArrayList (java.util.ArrayList)3 List (java.util.List)3 BufferManagerImpl (org.teiid.common.buffer.impl.BufferManagerImpl)3 BatchedUpdateCommand (org.teiid.query.sql.lang.BatchedUpdateCommand)3 TeiidProcessingException (org.teiid.core.TeiidProcessingException)2 QueryMetadataInterface (org.teiid.query.metadata.QueryMetadataInterface)2 Insert (org.teiid.query.sql.lang.Insert)2 CacheDirective (org.teiid.translator.CacheDirective)2 Clob (java.sql.Clob)1 SQLException (java.sql.SQLException)1 LinkedList (java.util.LinkedList)1 QueryProcessingException (org.teiid.api.exception.query.QueryProcessingException)1 BlockedException (org.teiid.common.buffer.BlockedException)1