Search in sources :

Example 1 with ParseInfo

use of org.teiid.query.parser.ParseInfo in project teiid by teiid.

the class TestSessionAwareCache method testSessionSpecfic.

@Test
public void testSessionSpecfic() {
    SessionAwareCache<Cachable> cache = new SessionAwareCache<Cachable>("resultset", DefaultCacheFactory.INSTANCE, SessionAwareCache.Type.RESULTSET, 0);
    CacheID id = new CacheID(buildWorkContext(), new ParseInfo(), "SELECT * FROM FOO");
    Cachable result = Mockito.mock(Cachable.class);
    id = new CacheID(buildWorkContext(), new ParseInfo(), "SELECT * FROM FOO");
    cache.put(id, Determinism.SESSION_DETERMINISTIC, result, null);
    // make sure that in the case of session specific; we do not call prepare
    // as session is local only call for distributed
    Mockito.verify(result, times(0)).prepare((BufferManager) anyObject());
    Object c = cache.get(id);
    Mockito.verify(result, times(0)).restore((BufferManager) anyObject());
    assertTrue(result == c);
}
Also used : CacheID(org.teiid.dqp.internal.process.SessionAwareCache.CacheID) ParseInfo(org.teiid.query.parser.ParseInfo) Cachable(org.teiid.cache.Cachable) Test(org.junit.Test)

Example 2 with ParseInfo

use of org.teiid.query.parser.ParseInfo in project teiid by teiid.

the class TestSessionAwareCache method testTtl.

@Test
public void testTtl() {
    SessionAwareCache<Cachable> cache = new SessionAwareCache<Cachable>("resultset", DefaultCacheFactory.INSTANCE, SessionAwareCache.Type.RESULTSET, 0);
    CacheID id = new CacheID(buildWorkContext(), new ParseInfo(), "SELECT * FROM FOO");
    Cachable result = Mockito.mock(Cachable.class);
    // make sure defaults are returned
    assertNull(cache.computeTtl(id, result, null));
    assertEquals(Long.valueOf(1), cache.computeTtl(id, result, 1l));
    AccessInfo ai = new AccessInfo();
    Mockito.stub(result.getAccessInfo()).toReturn(ai);
    Table t = new Table();
    t.setProperty(DataModifiable.DATA_TTL, "2");
    ai.addAccessedObject(t);
    assertEquals(Long.valueOf(2), cache.computeTtl(id, result, null));
    Table t1 = new Table();
    Schema s = new Schema();
    t1.setParent(s);
    s.setProperty(DataModifiable.DATA_TTL, "0");
    ai.addAccessedObject(t1);
    // ensure that the min and the parent are used
    assertEquals(Long.valueOf(0), cache.computeTtl(id, result, null));
}
Also used : Table(org.teiid.metadata.Table) CacheID(org.teiid.dqp.internal.process.SessionAwareCache.CacheID) Schema(org.teiid.metadata.Schema) ParseInfo(org.teiid.query.parser.ParseInfo) Cachable(org.teiid.cache.Cachable) Test(org.junit.Test)

Example 3 with ParseInfo

use of org.teiid.query.parser.ParseInfo in project teiid by teiid.

the class TestSessionAwareCache method testNoScope.

@Test
public void testNoScope() {
    SessionAwareCache<Cachable> cache = new SessionAwareCache<Cachable>("resultset", DefaultCacheFactory.INSTANCE, SessionAwareCache.Type.RESULTSET, 0);
    CacheID id = new CacheID(buildWorkContext(), new ParseInfo(), "SELECT * FROM FOO");
    Cachable result = Mockito.mock(Cachable.class);
    Mockito.stub(result.prepare((BufferManager) anyObject())).toReturn(true);
    Mockito.stub(result.restore((BufferManager) anyObject())).toReturn(true);
    cache.put(id, Determinism.VDB_DETERMINISTIC, result, null);
    // make sure that in the case of session specific; we do not call prepare
    // as session is local only call for distributed
    Mockito.verify(result, times(1)).prepare((BufferManager) anyObject());
    id = new CacheID(buildWorkContext(), new ParseInfo(), "SELECT * FROM FOO");
    Object c = cache.get(id);
    Mockito.verify(result, times(1)).restore((BufferManager) anyObject());
    assertTrue(result == c);
}
Also used : CacheID(org.teiid.dqp.internal.process.SessionAwareCache.CacheID) ParseInfo(org.teiid.query.parser.ParseInfo) Cachable(org.teiid.cache.Cachable) Test(org.junit.Test)

Example 4 with ParseInfo

use of org.teiid.query.parser.ParseInfo in project teiid by teiid.

the class TestSessionAwareCache method testUserSpecfic.

@Test
public void testUserSpecfic() {
    SessionAwareCache<Cachable> cache = new SessionAwareCache<Cachable>("resultset", DefaultCacheFactory.INSTANCE, SessionAwareCache.Type.RESULTSET, 0);
    CacheID id = new CacheID(buildWorkContext(), new ParseInfo(), "SELECT * FROM FOO");
    Cachable result = Mockito.mock(Cachable.class);
    Mockito.stub(result.prepare((BufferManager) anyObject())).toReturn(true);
    Mockito.stub(result.restore((BufferManager) anyObject())).toReturn(true);
    cache.put(id, Determinism.USER_DETERMINISTIC, result, null);
    // make sure that in the case of session specific; we do not call prepare
    // as session is local only call for distributed
    Mockito.verify(result, times(1)).prepare((BufferManager) anyObject());
    id = new CacheID(buildWorkContext(), new ParseInfo(), "SELECT * FROM FOO");
    Object c = cache.get(id);
    Mockito.verify(result, times(1)).restore((BufferManager) anyObject());
    assertTrue(result == c);
}
Also used : CacheID(org.teiid.dqp.internal.process.SessionAwareCache.CacheID) ParseInfo(org.teiid.query.parser.ParseInfo) Cachable(org.teiid.cache.Cachable) Test(org.junit.Test)

Example 5 with ParseInfo

use of org.teiid.query.parser.ParseInfo in project teiid by teiid.

the class Request method parseCommand.

private Command parseCommand() throws QueryParserException {
    if (requestMsg.getCommand() != null) {
        return (Command) requestMsg.getCommand();
    }
    String[] commands = requestMsg.getCommands();
    ParseInfo parseInfo = createParseInfo(this.requestMsg, this.workContext.getSession());
    QueryParser queryParser = QueryParser.getQueryParser();
    if (requestMsg.isPreparedStatement() || requestMsg.isCallableStatement() || !requestMsg.isBatchedUpdate()) {
        String commandStr = commands[0];
        if (preParser != null) {
            commandStr = preParser.preParse(commandStr, this.context);
        }
        return queryParser.parseCommand(commandStr, parseInfo);
    }
    List<Command> parsedCommands = new ArrayList<Command>(commands.length);
    for (int i = 0; i < commands.length; i++) {
        String updateCommand = commands[i];
        if (preParser != null) {
            updateCommand = preParser.preParse(updateCommand, this.context);
        }
        parsedCommands.add(queryParser.parseCommand(updateCommand, parseInfo));
    }
    return new BatchedUpdateCommand(parsedCommands);
}
Also used : QueryParser(org.teiid.query.parser.QueryParser) CreateProcedureCommand(org.teiid.query.sql.proc.CreateProcedureCommand) Command(org.teiid.query.sql.lang.Command) QueryCommand(org.teiid.query.sql.lang.QueryCommand) BatchedUpdateCommand(org.teiid.query.sql.lang.BatchedUpdateCommand) ArrayList(java.util.ArrayList) ParseInfo(org.teiid.query.parser.ParseInfo) BatchedUpdateCommand(org.teiid.query.sql.lang.BatchedUpdateCommand)

Aggregations

ParseInfo (org.teiid.query.parser.ParseInfo)16 CacheID (org.teiid.dqp.internal.process.SessionAwareCache.CacheID)11 Test (org.junit.Test)6 Cachable (org.teiid.cache.Cachable)6 Command (org.teiid.query.sql.lang.Command)4 ArrayList (java.util.ArrayList)3 Client (org.teiid.odata.api.Client)2 BatchCollector (org.teiid.query.processor.BatchCollector)2 Reference (org.teiid.query.sql.symbol.Reference)2 LinkedList (java.util.LinkedList)1 List (java.util.List)1 BlockedException (org.teiid.common.buffer.BlockedException)1 TupleBatch (org.teiid.common.buffer.TupleBatch)1 TupleBuffer (org.teiid.common.buffer.TupleBuffer)1 TeiidComponentException (org.teiid.core.TeiidComponentException)1 TeiidProcessingException (org.teiid.core.TeiidProcessingException)1 TransformationException (org.teiid.core.types.TransformationException)1 CachedResults (org.teiid.dqp.internal.process.CachedResults)1 PreparedPlan (org.teiid.dqp.internal.process.PreparedPlan)1 TransactionContext (org.teiid.dqp.service.TransactionContext)1