diff --git itests/hive-unit/src/test/java/org/apache/hadoop/hive/ql/security/authorization/plugin/TestHiveAuthorizerCheckInvocation.java itests/hive-unit/src/test/java/org/apache/hadoop/hive/ql/security/authorization/plugin/TestHiveAuthorizerCheckInvocation.java index 09d142a61a..37bb6aded3 100644 --- itests/hive-unit/src/test/java/org/apache/hadoop/hive/ql/security/authorization/plugin/TestHiveAuthorizerCheckInvocation.java +++ itests/hive-unit/src/test/java/org/apache/hadoop/hive/ql/security/authorization/plugin/TestHiveAuthorizerCheckInvocation.java @@ -98,6 +98,7 @@ public static void beforeTest() throws Exception { conf.setBoolVar(ConfVars.HIVE_SERVER2_ENABLE_DOAS, false); conf.setBoolVar(ConfVars.HIVE_SUPPORT_CONCURRENCY, true); conf.setVar(ConfVars.HIVE_TXN_MANAGER, DbTxnManager.class.getName()); + conf.setBoolVar(ConfVars.HIVE_QUERY_RESULTS_CACHE_ENABLED, true); conf.setVar(HiveConf.ConfVars.HIVEMAPREDMODE, "nonstrict"); SessionState.start(conf); @@ -160,6 +161,19 @@ public void testInputSomeColumnsUsedView() throws Exception { getSortedList(tableObj.getColumns())); } + @Test + public void testQueryCacheIgnored() throws Exception { + + reset(mockedAuthorizer); + int status = driver.compile("select i from " + acidTableName + + " where i > 0 ", true); + assertEquals(0, status); + List outputs = getHivePrivilegeObjectInputs().getRight(); + List inputs = getHivePrivilegeObjectInputs().getLeft(); + assertEquals("No outputs for a select", 0, outputs.size()); + assertEquals("One input for this select", 1, inputs.size()); + } + @Test public void testInputSomeColumnsUsedJoin() throws Exception { diff --git ql/src/java/org/apache/hadoop/hive/ql/Context.java ql/src/java/org/apache/hadoop/hive/ql/Context.java index a85b94c475..fd627c69e8 100644 --- ql/src/java/org/apache/hadoop/hive/ql/Context.java +++ ql/src/java/org/apache/hadoop/hive/ql/Context.java @@ -727,6 +727,22 @@ public boolean isMRTmpFileURI(String uriStr) { (uriStr.indexOf(MR_PREFIX) != -1); } + /** + * Check if the path is a result cache dir for this query. This doesn't work unless the result + * paths have already been set in SemanticAnalyzer::getDestinationFilePath to prevent someone from + * overriding LOCATION in a create table command to overwrite cached results + * + * @param destinationPath + * @return true if the path is a result cache dir + */ + + public boolean isResultCacheDir(Path destinationPath) { + if (this.fsResultCacheDirs != null) { + return this.fsResultCacheDirs.equals(destinationPath); + } + return false; + } + public Path getMRTmpPath(URI uri) { return new Path(getStagingDir(new Path(uri), !isExplainSkipExecution()), MR_PREFIX + nextPathId()); } diff --git ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java index 5fcc367cc9..b70b7d47fa 100644 --- ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java +++ ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java @@ -7704,7 +7704,9 @@ protected Operator genFileSinkPlan(String dest, QB qb, Operator input) } boolean isDestTempFile = true; - if (!ctx.isMRTmpFileURI(destinationPath.toUri().toString())) { + if (ctx.isMRTmpFileURI(destinationPath.toUri().toString()) == false + && ctx.isResultCacheDir(destinationPath) == false) { + // not a temp dir and not a result cache dir idToTableNameMap.put(String.valueOf(destTableId), destinationPath.toUri().toString()); currentTableId = destTableId; destTableId++;