Repository: hive Updated Branches: refs/heads/master bb777512f -> 670e49fd5
HIVE-20834: Hive QueryResultCache entries keeping reference to SemanticAnalyzer from cached query (Jason Dere, reviewed by GopalV) Project: http://git-wip-us.apache.org/repos/asf/hive/repo Commit: http://git-wip-us.apache.org/repos/asf/hive/commit/670e49fd Tree: http://git-wip-us.apache.org/repos/asf/hive/tree/670e49fd Diff: http://git-wip-us.apache.org/repos/asf/hive/diff/670e49fd Branch: refs/heads/master Commit: 670e49fd5c7d9f6759d01c2d5d5b79f6ad3a0e4b Parents: bb77751 Author: Jason Dere <jd...@hortonworks.com> Authored: Sat Nov 3 17:16:33 2018 -0700 Committer: Jason Dere <jd...@hortonworks.com> Committed: Sat Nov 3 17:16:33 2018 -0700 ---------------------------------------------------------------------- .../hadoop/hive/ql/parse/SemanticAnalyzer.java | 55 ++++++++++---------- 1 file changed, 27 insertions(+), 28 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/hive/blob/670e49fd/ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java ---------------------------------------------------------------------- diff --git a/ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java b/ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java index eed875e..1a2777b 100644 --- a/ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java +++ b/ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java @@ -14895,37 +14895,36 @@ public class SemanticAnalyzer extends BaseSemanticAnalyzer { } } - private QueryResultsCache.LookupInfo createLookupInfoForQuery(ASTNode astNode) { + private ValidTxnWriteIdList getQueryValidTxnWriteIdList() throws SemanticException { + // TODO: Once HIVE-18948 is in, should be able to retrieve writeIdList from the conf. + //cachedWriteIdList = AcidUtils.getValidTxnWriteIdList(conf); + // + List<String> transactionalTables = tablesFromReadEntities(inputs) + .stream() + .filter(table -> AcidUtils.isTransactionalTable(table)) + .map(table -> table.getFullyQualifiedName()) + .collect(Collectors.toList()); + if (transactionalTables.size() > 0) { + try { + String txnString = conf.get(ValidTxnList.VALID_TXNS_KEY); + return getTxnMgr().getValidWriteIds(transactionalTables, txnString); + } catch (Exception err) { + String msg = "Error while getting the txnWriteIdList for tables " + transactionalTables + + " and validTxnList " + conf.get(ValidTxnList.VALID_TXNS_KEY); + throw new SemanticException(msg, err); + } + } + + // No transactional tables. + return null; + } + + private QueryResultsCache.LookupInfo createLookupInfoForQuery(ASTNode astNode) throws SemanticException { QueryResultsCache.LookupInfo lookupInfo = null; String queryString = getQueryStringForCache(astNode); if (queryString != null) { - lookupInfo = new QueryResultsCache.LookupInfo(queryString, - new Supplier<ValidTxnWriteIdList>() { - ValidTxnWriteIdList cachedWriteIdList = null; - @Override - public ValidTxnWriteIdList get() { - if (cachedWriteIdList == null) { - // TODO: Once HIVE-18948 is in, should be able to retrieve writeIdList from the conf. - //cachedWriteIdList = AcidUtils.getValidTxnWriteIdList(conf); - // - List<String> transactionalTables = tablesFromReadEntities(inputs) - .stream() - .filter(table -> AcidUtils.isTransactionalTable(table)) - .map(table -> table.getFullyQualifiedName()) - .collect(Collectors.toList()); - try { - String txnString = conf.get(ValidTxnList.VALID_TXNS_KEY); - cachedWriteIdList = - getTxnMgr().getValidWriteIds(transactionalTables, txnString); - } catch (Exception err) { - String msg = "Error while getting the txnWriteIdList for tables " + transactionalTables - + " and validTxnList " + conf.get(ValidTxnList.VALID_TXNS_KEY); - throw new RuntimeException(msg, err); - } - } - return cachedWriteIdList; - } - }); + ValidTxnWriteIdList writeIdList = getQueryValidTxnWriteIdList(); + lookupInfo = new QueryResultsCache.LookupInfo(queryString, () -> { return writeIdList; }); } return lookupInfo; }