public CacheHint clone() { CacheHint copy = new CacheHint(); copy.setInvalidation(this.getInvalidation()); copy.setPrefersMemory(this.getPrefersMemory()); copy.setReadAll(this.getReadAll()); copy.setScope(this.getScope()); copy.setTtl(this.getTtl()); copy.setUpdatable(this.getUpdatable()); copy.setMinRows(this.getMinRows()); return copy; }
continue; CacheHint hint = new CacheHint(); if (match.group(2) !=null) { hint.setPrefersMemory(true); hint.setTtl(Long.valueOf(ttl.substring(4))); hint.setUpdatable(true); hint.setScope(scope); hint.setMinRows(Long.valueOf(min.substring(4)));
CacheHint hint = c.getCacheHint(); if (hint != null) { hint = hint.clone(); } else { hint = new CacheHint(); hint.setTtl(null); //will be managed by the scheduler } else if (ttlString != null) { hint.setTtl(Long.parseLong(ttlString)); hint.setPrefersMemory(Boolean.valueOf(memString)); hint.setUpdatable(Boolean.valueOf(updatableString)); hint.setScope(scope);
if (originalCommand.getCacheHint().getMinRows() != null && resultsBuffer.getRowCount() <= originalCommand.getCacheHint().getMinRows()) { LogManager.logDetail(LogConstants.CTX_DQP, requestID, "Not caching result as there are fewer rows than needed", resultsBuffer.getRowCount()); //$NON-NLS-1$ return; resultsBuffer.setPrefersMemory(originalCommand.getCacheHint().isPrefersMemory()); if (originalCommand.getCacheHint().getDeterminism() != null) { determinismLevel = originalCommand.getCacheHint().getDeterminism(); LogManager.logTrace(LogConstants.CTX_DQP, new Object[] { "Cache hint modified the query determinism from ",processor.getContext().getDeterminismLevel(), " to ", determinismLevel }); //$NON-NLS-1$ //$NON-NLS-2$ if (!originalCommand.getCacheHint().isUpdatable(true)) { cr.getAccessInfo().setSensitiveToMetadataChanges(false); cr.getAccessInfo().getObjectsAccessed().clear(); LogManager.logDetail(LogConstants.CTX_DQP, e, QueryPlugin.Util.getString("failed_to_cache")); //$NON-NLS-1$ dqpCore.getRsCache().put(cid, determinismLevel, cr, originalCommand.getCacheHint() != null?originalCommand.getCacheHint().getTtl():null);
append(CacheHint.CACHE); boolean addParens = false; if (obj.isPrefersMemory()) { append(Tokens.LPAREN); addParens = true; append(CacheHint.PREF_MEM); if (obj.getTtl() != null) { if (!addParens) { append(Tokens.LPAREN); append(obj.getTtl()); if (obj.getUpdatable() != null) { if (!addParens) { append(Tokens.LPAREN); if (obj.getScope() != null) { if (!addParens) { append(Tokens.LPAREN); append(obj.getScope()); if (obj.getMinRows() != null) { if (!addParens) { append(Tokens.LPAREN); append(obj.getMinRows());
@Test public void testExpandedCacheHint() { String sql = "/*+ cache( pref_mem ttl:2000) */ SELECT * FROM t1"; //$NON-NLS-1$ Query query = new Query(); Select select = new Select(); select.addSymbol(new MultipleElementSymbol()); query.setSelect(select); From from = new From(); UnaryFromClause ufc = new UnaryFromClause(); from.addClause(ufc); ufc.setGroup(new GroupSymbol("t1")); //$NON-NLS-1$ query.setFrom(from); CacheHint hint = new CacheHint(); hint.setPrefersMemory(true); hint.setTtl(Long.valueOf(2000)); query.setCacheHint(hint); TestParser.helpTest(sql, "/*+ cache(pref_mem ttl:2000) */ SELECT * FROM t1", query); //$NON-NLS-1$ }
@Test public void testCacheScope() { String sql = "/*+ cache(pref_mem scope:session) */ SELECT * FROM t1"; //$NON-NLS-1$ Query query = new Query(); Select select = new Select(); select.addSymbol(new MultipleElementSymbol()); query.setSelect(select); From from = new From(); UnaryFromClause ufc = new UnaryFromClause(); from.addClause(ufc); ufc.setGroup(new GroupSymbol("t1")); //$NON-NLS-1$ query.setFrom(from); CacheHint hint = new CacheHint(); hint.setScope(Scope.SESSION); hint.setPrefersMemory(true); query.setCacheHint(hint); TestParser.helpTest(sql, "/*+ cache(pref_mem scope:SESSION) */ SELECT * FROM t1", query); //$NON-NLS-1$ }
if (cacheHint != null && cacheHint.getScope() != null && cacheHint.getScope() != org.teiid.translator.CacheDirective.Scope.VDB) { log(report, model, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31116, t.getFullName())); Long ttl = -1L; if (cacheHint != null) { if (cacheHint.getTtl() != null && t.getProperty(MaterializationMetadataRepository.MATVIEW_TTL, false) == null) { ttl = cacheHint.getTtl(); t.setProperty(MaterializationMetadataRepository.MATVIEW_TTL, String.valueOf(ttl)); if (cacheHint.getUpdatable() != null && t.getProperty(MaterializationMetadataRepository.MATVIEW_UPDATABLE, false) == null) { t.setProperty(MaterializationMetadataRepository.MATVIEW_UPDATABLE, String.valueOf(cacheHint.getUpdatable())); if (cacheHint.getPrefersMemory() != null && t.getProperty(MaterializationMetadataRepository.MATVIEW_PREFER_MEMORY, false) == null) { t.setProperty(MaterializationMetadataRepository.MATVIEW_PREFER_MEMORY, String.valueOf(cacheHint.getPrefersMemory())); if (cacheHint.getScope() != null && t.getProperty(MaterializationMetadataRepository.MATVIEW_SHARE_SCOPE, false) == null) { log(report, model, Severity.WARNING, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31252, t.getName(), cacheHint.getScope().name())); t.setProperty(MaterializationMetadataRepository.MATVIEW_SHARE_SCOPE, MaterializationMetadataRepository.Scope.IMPORTED.name());
@Test public void testCache1() { String sql = "/*+ cache */ execute foo()"; //$NON-NLS-1$ StoredProcedure sp = new StoredProcedure(); sp.setCacheHint(new CacheHint()); sp.setProcedureName("foo"); //$NON-NLS-1$ TestParser.helpTest(sql, "/*+ cache */ EXEC foo()", sp); //$NON-NLS-1$ }
@Override protected TupleSource createTupleSource() throws TeiidComponentException, TeiidProcessingException { TupleBuffer tb = bc.collectTuples(); CachedResults cr = new CachedResults(); cr.setResults(tb, qp.getProcessorPlan()); Determinism determinismLevel = qp.getContext().getDeterminismLevel(); if (hint != null && hint.getDeterminism() != null) { LogManager.logTrace(LogConstants.CTX_DQP, new Object[] { "Cache hint modified the query determinism from ",determinismLevel, " to ", hint.getDeterminism() }); //$NON-NLS-1$ //$NON-NLS-2$ determinismLevel = hint.getDeterminism(); } cache.put(cid, determinismLevel, cr, hint != null?hint.getTtl():null); context.setDeterminismLevel(determinismLevel); success = true; return tb.createIndexedTupleSource(); }
@Test public void testCacheHintUnion() { String sql = "/*+ cache( pref_mem) */ SELECT * FROM t1 union select * from t2"; //$NON-NLS-1$ Query query = new Query(); Select select = new Select(); select.addSymbol(new MultipleElementSymbol()); query.setSelect(select); From from = new From(); UnaryFromClause ufc = new UnaryFromClause(); from.addClause(ufc); ufc.setGroup(new GroupSymbol("t1")); //$NON-NLS-1$ query.setFrom(from); Query query1 = new Query(); select = new Select(); select.addSymbol(new MultipleElementSymbol()); query1.setSelect(select); from = new From(); ufc = new UnaryFromClause(); from.addClause(ufc); ufc.setGroup(new GroupSymbol("t2")); //$NON-NLS-1$ query1.setFrom(from); SetQuery sq = new SetQuery(Operation.UNION, false, query, query1); CacheHint hint = new CacheHint(); hint.setPrefersMemory(true); sq.setCacheHint(hint); TestParser.helpTest(sql, "/*+ cache(pref_mem) */ SELECT * FROM t1 UNION SELECT * FROM t2", sq); //$NON-NLS-1$ }
public boolean isPrefersMemory() { if (getPrefersMemory() != null) { return getPrefersMemory(); } return false; }
CacheHint hint = c.getCacheHint(); if (hint != null) { hint = hint.clone(); } else { hint = new CacheHint(); hint.setTtl(null); //will be managed by the scheduler } else if (ttlString != null) { hint.setTtl(Long.parseLong(ttlString)); hint.setPrefersMemory(Boolean.valueOf(memString)); hint.setUpdatable(Boolean.valueOf(updatableString)); hint.setScope(scope);
continue; CacheHint hint = new CacheHint(); if (match.group(2) !=null) { hint.setPrefersMemory(true); hint.setTtl(Long.valueOf(ttl.substring(4))); hint.setUpdatable(true); hint.setScope(scope); hint.setMinRows(Long.valueOf(min.substring(4)));
if (originalCommand.getCacheHint().getMinRows() != null && resultsBuffer.getRowCount() <= originalCommand.getCacheHint().getMinRows()) { LogManager.logDetail(LogConstants.CTX_DQP, requestID, "Not caching result as there are fewer rows than needed", resultsBuffer.getRowCount()); //$NON-NLS-1$ return; resultsBuffer.setPrefersMemory(originalCommand.getCacheHint().isPrefersMemory()); if (originalCommand.getCacheHint().getDeterminism() != null) { determinismLevel = originalCommand.getCacheHint().getDeterminism(); LogManager.logTrace(LogConstants.CTX_DQP, new Object[] { "Cache hint modified the query determinism from ",processor.getContext().getDeterminismLevel(), " to ", determinismLevel }); //$NON-NLS-1$ //$NON-NLS-2$ if (!originalCommand.getCacheHint().isUpdatable(true)) { cr.getAccessInfo().setSensitiveToMetadataChanges(false); cr.getAccessInfo().getObjectsAccessed().clear(); LogManager.logDetail(LogConstants.CTX_DQP, e, QueryPlugin.Util.getString("failed_to_cache")); //$NON-NLS-1$ dqpCore.getRsCache().put(cid, determinismLevel, cr, originalCommand.getCacheHint() != null?originalCommand.getCacheHint().getTtl():null);
append(CacheHint.CACHE); boolean addParens = false; if (obj.isPrefersMemory()) { append(Tokens.LPAREN); addParens = true; append(CacheHint.PREF_MEM); if (obj.getTtl() != null) { if (!addParens) { append(Tokens.LPAREN); append(obj.getTtl()); if (obj.getUpdatable() != null) { if (!addParens) { append(Tokens.LPAREN); if (obj.getScope() != null) { if (!addParens) { append(Tokens.LPAREN); append(obj.getScope()); if (obj.getMinRows() != null) { if (!addParens) { append(Tokens.LPAREN); append(obj.getMinRows());
if (cacheHint != null && cacheHint.getScope() != null && cacheHint.getScope() != org.teiid.translator.CacheDirective.Scope.VDB) { log(report, model, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31116, t.getFullName())); Long ttl = -1L; if (cacheHint != null) { if (cacheHint.getTtl() != null && t.getProperty(MaterializationMetadataRepository.MATVIEW_TTL, false) == null) { ttl = cacheHint.getTtl(); t.setProperty(MaterializationMetadataRepository.MATVIEW_TTL, String.valueOf(ttl)); if (cacheHint.getUpdatable() != null && t.getProperty(MaterializationMetadataRepository.MATVIEW_UPDATABLE, false) == null) { t.setProperty(MaterializationMetadataRepository.MATVIEW_UPDATABLE, String.valueOf(cacheHint.getUpdatable())); if (cacheHint.getPrefersMemory() != null && t.getProperty(MaterializationMetadataRepository.MATVIEW_PREFER_MEMORY, false) == null) { t.setProperty(MaterializationMetadataRepository.MATVIEW_PREFER_MEMORY, String.valueOf(cacheHint.getPrefersMemory())); if (cacheHint.getScope() != null && t.getProperty(MaterializationMetadataRepository.MATVIEW_SHARE_SCOPE, false) == null) { log(report, model, Severity.WARNING, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31252, t.getName(), cacheHint.getScope().name())); t.setProperty(MaterializationMetadataRepository.MATVIEW_SHARE_SCOPE, MaterializationMetadataRepository.Scope.IMPORTED.name());
@Test public void testCacheProc() { String sql = "/*+ cache */ CREATE VIRTUAL PROCEDURE BEGIN END"; //$NON-NLS-1$ CreateProcedureCommand command = new CreateProcedureCommand(new Block()); command.setCacheHint(new CacheHint()); TestParser.helpTest(sql, "/*+ cache */ BEGIN\nEND", command); //$NON-NLS-1$ }