Search in sources :

Example 1 with Command

use of org.teiid.query.sql.lang.Command 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 Command

use of org.teiid.query.sql.lang.Command in project teiid by teiid.

the class TestDataTierManager method testCheckForUpdatesWithBatched.

@Test
public void testCheckForUpdatesWithBatched() throws Exception {
    helpSetupDataTierManager();
    QueryMetadataInterface metadata = RealMetadataFactory.exampleBQTCached();
    AtomicRequestMessage request = helpSetupRequest("delete from bqt1.smalla", 1, metadata);
    Command command = helpGetCommand("insert into bqt1.smalla (stringkey) values ('1')", metadata);
    BatchedUpdateCommand bac = new BatchedUpdateCommand(Arrays.asList(request.getCommand(), command));
    request.setCommand(bac);
    DataTierTupleSource dtts = new DataTierTupleSource(request, workItem, connectorManager.registerRequest(request), dtm, limit);
    pullTuples(dtts, 2);
}
Also used : Command(org.teiid.query.sql.lang.Command) BatchedUpdateCommand(org.teiid.query.sql.lang.BatchedUpdateCommand) QueryMetadataInterface(org.teiid.query.metadata.QueryMetadataInterface) BatchedUpdateCommand(org.teiid.query.sql.lang.BatchedUpdateCommand) AtomicRequestMessage(org.teiid.dqp.message.AtomicRequestMessage) Test(org.junit.Test)

Example 3 with Command

use of org.teiid.query.sql.lang.Command 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 4 with Command

use of org.teiid.query.sql.lang.Command in project teiid by teiid.

the class TestDataTierManager method helpGetCommand.

private static Command helpGetCommand(String sql, QueryMetadataInterface metadata) throws Exception {
    Command command = QueryParser.getQueryParser().parseCommand(sql);
    QueryResolver.resolveCommand(command, metadata);
    return command;
}
Also used : Command(org.teiid.query.sql.lang.Command) BatchedUpdateCommand(org.teiid.query.sql.lang.BatchedUpdateCommand)

Example 5 with Command

use of org.teiid.query.sql.lang.Command in project teiid by teiid.

the class TestPreparedPlanCache method helpPutPreparedPlans.

// ====Help methods====//
private void helpPutPreparedPlans(SessionAwareCache<PreparedPlan> cache, DQPWorkContext session, int start, int count) {
    for (int i = 0; i < count; i++) {
        Command dummy;
        try {
            dummy = QueryParser.getQueryParser().parseCommand(EXAMPLE_QUERY + (start + i));
        } catch (QueryParserException e) {
            throw new RuntimeException(e);
        }
        CacheID id = new CacheID(session, pi, dummy.toString());
        PreparedPlan pPlan = new PreparedPlan();
        cache.put(id, Determinism.SESSION_DETERMINISTIC, pPlan, null);
        pPlan.setCommand(dummy);
        pPlan.setPlan(new RelationalPlan(new ProjectNode(i)), new CommandContext());
        AnalysisRecord analysisRecord = new AnalysisRecord(true, false);
        pPlan.setAnalysisRecord(analysisRecord);
        ArrayList<Reference> refs = new ArrayList<Reference>();
        refs.add(new Reference(1));
        pPlan.setReferences(refs);
    }
}
Also used : QueryParserException(org.teiid.api.exception.query.QueryParserException) AnalysisRecord(org.teiid.query.analysis.AnalysisRecord) CommandContext(org.teiid.query.util.CommandContext) Reference(org.teiid.query.sql.symbol.Reference) ArrayList(java.util.ArrayList) RelationalPlan(org.teiid.query.processor.relational.RelationalPlan) Command(org.teiid.query.sql.lang.Command) CacheID(org.teiid.dqp.internal.process.SessionAwareCache.CacheID) ProjectNode(org.teiid.query.processor.relational.ProjectNode)

Aggregations

Command (org.teiid.query.sql.lang.Command)232 Test (org.junit.Test)142 QueryMetadataInterface (org.teiid.query.metadata.QueryMetadataInterface)90 BasicSourceCapabilities (org.teiid.query.optimizer.capabilities.BasicSourceCapabilities)73 FakeCapabilitiesFinder (org.teiid.query.optimizer.capabilities.FakeCapabilitiesFinder)66 List (java.util.List)64 CommandContext (org.teiid.query.util.CommandContext)38 ArrayList (java.util.ArrayList)37 BatchedUpdateCommand (org.teiid.query.sql.lang.BatchedUpdateCommand)36 BigInteger (java.math.BigInteger)29 DefaultCapabilitiesFinder (org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder)25 AnalysisRecord (org.teiid.query.analysis.AnalysisRecord)21 GroupSymbol (org.teiid.query.sql.symbol.GroupSymbol)20 ProcessorPlan (org.teiid.query.processor.ProcessorPlan)19 TransformationMetadata (org.teiid.query.metadata.TransformationMetadata)16 LinkedList (java.util.LinkedList)10 QueryParser (org.teiid.query.parser.QueryParser)10 RelationalPlan (org.teiid.query.processor.relational.RelationalPlan)10 QueryCommand (org.teiid.query.sql.lang.QueryCommand)10 StoredProcedure (org.teiid.query.sql.lang.StoredProcedure)10