diff --git a/ql/src/java/org/apache/hadoop/hive/ql/cache/results/QueryResultsCache.java b/ql/src/java/org/apache/hadoop/hive/ql/cache/results/QueryResultsCache.java index 11b9c27126..d29c4da5ec 100644 --- a/ql/src/java/org/apache/hadoop/hive/ql/cache/results/QueryResultsCache.java +++ b/ql/src/java/org/apache/hadoop/hive/ql/cache/results/QueryResultsCache.java @@ -540,6 +540,12 @@ public boolean setEntryValid(CacheEntry cacheEntry, FetchWork fetchWork) { } else { // No actual result directory, no need to move anything. cachedResultsPath = zeroRowsPath; + // Even if there are no results to move, at least check that we have permission + // to check the existence of zeroRowsPath, or the read using the cache will fail. + // A failure here will cause this query to not be added to the cache. + FileSystem cacheFs = cachedResultsPath.getFileSystem(conf); + boolean fakePathExists = cacheFs.exists(zeroRowsPath); + resultSize = 0; requiresMove = false; } 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 2e055aba4b..521afe6231 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 @@ -12129,7 +12129,7 @@ void analyzeInternal(ASTNode ast, PlannerContextFactory pcf) throws SemanticExce // If no masking/filtering required, then we can check the cache now, before // generating the operator tree and going through CBO. // Otherwise we have to wait until after the masking/filtering step. - boolean isCacheEnabled = conf.getBoolVar(HiveConf.ConfVars.HIVE_QUERY_RESULTS_CACHE_ENABLED); + boolean isCacheEnabled = isResultsCacheEnabled(); QueryResultsCache.LookupInfo lookupInfo = null; boolean needsTransform = needsTransform(); if (isCacheEnabled && !needsTransform && queryTypeCanUseCache()) { @@ -14659,6 +14659,11 @@ public ValidTxnWriteIdList get() { return lookupInfo; } + private boolean isResultsCacheEnabled() { + return conf.getBoolVar(HiveConf.ConfVars.HIVE_QUERY_RESULTS_CACHE_ENABLED) && + !(SessionState.get().isHiveServerQuery() && conf.getBoolVar(HiveConf.ConfVars.HIVE_SERVER2_ENABLE_DOAS)); + } + /** * Set the query plan to use cache entry passed in to return the query results. * @param cacheEntry The results cache entry that will be used to resolve the query.