@Test public void testPutPreparedPlan(){ SessionAwareCache<PreparedPlan> cache = new SessionAwareCache<PreparedPlan>("preparedplan", DefaultCacheFactory.INSTANCE, SessionAwareCache.Type.PREPAREDPLAN, 0); CacheID id = new CacheID(token, pi, EXAMPLE_QUERY + 1); //No PreparedPlan at the begining assertNull(cache.get(id)); //create one cache.put(id, Determinism.SESSION_DETERMINISTIC, new PreparedPlan(), null); //should have one now assertNotNull("Unable to get prepared plan from cache", cache.get(id)); //$NON-NLS-1$ }
private MetadataResult obtainMetadataForPreparedSql(String sql, DQPWorkContext workContext, boolean isDoubleQuotedVariablesAllowed) throws QueryParserException, QueryResolverException, TeiidComponentException { Command command = null; ParseInfo info = new ParseInfo(); // Defect 19747 - the parser needs the following connection property to decide whether to treat double-quoted strings as variable names info.ansiQuotedIdentifiers = isDoubleQuotedVariablesAllowed; CacheID id = new CacheID(workContext, info, sql); PreparedPlan plan = planCache.get(id); if(plan != null) { command = plan.getCommand(); } else { command = QueryParser.getQueryParser().parseCommand(sql, info); QueryResolver.resolveCommand(command, this.metadata); } return getMetadataForCommand(command); }
private MetadataResult obtainMetadataForPreparedSql(String sql, DQPWorkContext workContext, boolean isDoubleQuotedVariablesAllowed) throws QueryParserException, QueryResolverException, TeiidComponentException { Command command = null; ParseInfo info = new ParseInfo(); // Defect 19747 - the parser needs the following connection property to decide whether to treat double-quoted strings as variable names info.ansiQuotedIdentifiers = isDoubleQuotedVariablesAllowed; CacheID id = new CacheID(workContext, info, sql); PreparedPlan plan = planCache.get(id); if(plan != null) { command = plan.getCommand(); } else { command = QueryParser.getQueryParser().parseCommand(sql, info); QueryResolver.resolveCommand(command, this.metadata); } return getMetadataForCommand(command); }
private MetadataResult obtainMetadataForPreparedSql(String sql, DQPWorkContext workContext, boolean isDoubleQuotedVariablesAllowed) throws QueryParserException, QueryResolverException, TeiidComponentException { Command command = null; ParseInfo info = new ParseInfo(); // Defect 19747 - the parser needs the following connection property to decide whether to treat double-quoted strings as variable names info.ansiQuotedIdentifiers = isDoubleQuotedVariablesAllowed; CacheID id = new CacheID(workContext, info, sql); PreparedPlan plan = planCache.get(id); if(plan != null) { command = plan.getCommand(); } else { command = QueryParser.getQueryParser().parseCommand(sql, info); QueryResolver.resolveCommand(command, this.metadata); } return getMetadataForCommand(command); }
@Test public void testClearAll(){ SessionAwareCache<PreparedPlan> cache = new SessionAwareCache<PreparedPlan>("preparedplan", DefaultCacheFactory.INSTANCE, SessionAwareCache.Type.PREPAREDPLAN, 0); //create one for each session token helpPutPreparedPlans(cache, token, 1, 1); helpPutPreparedPlans(cache, token2, 1, 1); //should have one assertNotNull("Unable to get prepared plan from cache for token", cache.get(new CacheID(token, pi, EXAMPLE_QUERY + 1))); //$NON-NLS-1$ cache.clearAll(); //should not exist for token assertNull("Failed remove from cache", cache.get(new CacheID(token, pi, EXAMPLE_QUERY + 1))); //$NON-NLS-1$ //should not exist for token2 assertNull("Unable to get prepared plan from cache for token2", cache.get(new CacheID(token2, pi, EXAMPLE_QUERY + 1))); //$NON-NLS-1$ }
public PreparedPlan getPlan(String key) { if (this.globalState.planCache == null) { return null; } CacheID id = new CacheID(new ParseInfo(), key, getVdbName(), getVdbVersion(), getConnectionId(), getUserName()); PreparedPlan pp = this.globalState.planCache.get(id); if (pp != null) { if (id.getSessionId() != null) { setDeterminismLevel(Determinism.USER_DETERMINISTIC); } else if (id.getUserName() != null) { setDeterminismLevel(Determinism.SESSION_DETERMINISTIC); } return pp; } return null; }
public PreparedPlan getPlan(String key) { if (this.globalState.planCache == null) { return null; } CacheID id = new CacheID(new ParseInfo(), key, getVdbName(), getVdbVersion(), getConnectionId(), getUserName()); PreparedPlan pp = this.globalState.planCache.get(id); if (pp != null) { if (id.getSessionId() != null) { setDeterminismLevel(Determinism.USER_DETERMINISTIC); } else if (id.getUserName() != null) { setDeterminismLevel(Determinism.SESSION_DETERMINISTIC); } return pp; } return null; }
@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); }
public PreparedPlan getPlan(String key) { if (this.globalState.planCache == null) { return null; } CacheID id = new CacheID(new ParseInfo(), key, getVdbName(), getVdbVersion(), getConnectionId(), getUserName()); PreparedPlan pp = this.globalState.planCache.get(id); if (pp != null) { if (id.getSessionId() != null) { setDeterminismLevel(Determinism.USER_DETERMINISTIC); } else if (id.getUserName() != null) { setDeterminismLevel(Determinism.SESSION_DETERMINISTIC); } return pp; } return null; }
@Test public void testRemove() { 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); id = new CacheID(buildWorkContext(), new ParseInfo(), "SELECT * FROM FOO"); cache.put(id, Determinism.VDB_DETERMINISTIC, result, null); Object c = cache.get(id); assertTrue(result==c); assertTrue(cache.remove(id, Determinism.VDB_DETERMINISTIC) != null); assertNull(cache.get(id)); //session scope cache.put(id, Determinism.SESSION_DETERMINISTIC, result, null); assertTrue(cache.get(id) != null); assertTrue(cache.remove(id, Determinism.SESSION_DETERMINISTIC) != null); assertNull(cache.get(id)); }
@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); }
@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); }
@Test public void testVDBRemoval() { 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); id = new CacheID(buildWorkContext(), new ParseInfo(), "SELECT * FROM FOO"); cache.put(id, Determinism.VDB_DETERMINISTIC, result, null); Object c = cache.get(id); assertTrue(result==c); cache.clearForVDB("vdb-name", "1"); assertNull(cache.get(id)); }
context.getVdbVersion(), context.getConnectionId(), context.getUserName()); cid.setParameters(vals); CachedResults results = cache.get(cid); if (results != null) { TupleBuffer buffer = results.getResults();
context.getVdbVersion(), context.getConnectionId(), context.getUserName()); cid.setParameters(vals); CachedResults results = cache.get(cid); if (results != null) { TupleBuffer buffer = results.getResults();
context.getVdbVersion(), context.getConnectionId(), context.getUserName()); cid.setParameters(vals); CachedResults results = cache.get(cid); if (results != null) { TupleBuffer buffer = results.getResults();
@Test public void testGet(){ SessionAwareCache<PreparedPlan> cache = new SessionAwareCache<PreparedPlan>("preparedplan", DefaultCacheFactory.INSTANCE, SessionAwareCache.Type.PREPAREDPLAN, 0); helpPutPreparedPlans(cache, token, 0, 10); helpPutPreparedPlans(cache, token2, 0, 15); //read an entry for session2 (token2) PreparedPlan pPlan = cache.get(new CacheID(token2, pi, EXAMPLE_QUERY + 12)); assertNotNull("Unable to get prepared plan from cache", pPlan); //$NON-NLS-1$ assertEquals("Error getting plan from cache", new RelationalPlan(new ProjectNode(12)).toString(), pPlan.getPlan().toString()); //$NON-NLS-1$ assertEquals("Error getting command from cache", EXAMPLE_QUERY + 12, pPlan.getCommand().toString()); //$NON-NLS-1$ assertNotNull("Error getting plan description from cache", pPlan.getAnalysisRecord()); //$NON-NLS-1$ assertEquals("Error gettting reference from cache", new Reference(1), pPlan.getReferences().get(0)); //$NON-NLS-1$ }
prepPlan = prepPlanCache.get(id);
prepPlan = prepPlanCache.get(id);
prepPlan = prepPlanCache.get(id);