diff --git a/itests/hive-unit/src/test/java/org/apache/hive/jdbc/TestJdbcDriver2.java b/itests/hive-unit/src/test/java/org/apache/hive/jdbc/TestJdbcDriver2.java index c0823b6ef67c6c2cdc0484abac99ed81bac541ba..e4b9cd7e7dfb8de8a5889c8a089f6a533c2a4dcb 100644 --- a/itests/hive-unit/src/test/java/org/apache/hive/jdbc/TestJdbcDriver2.java +++ b/itests/hive-unit/src/test/java/org/apache/hive/jdbc/TestJdbcDriver2.java @@ -2334,6 +2334,26 @@ public void run() { verifyFetchedLog(incrementalLogs, expectedLogs); } + /** + * Test getting query log when HS2 disable logging. + * + * @throws Exception + */ + @Test + public void testGetQueryLogOnDisabledLog() throws Exception { + Statement setStmt = con.createStatement(); + setStmt.execute("set hive.server2.logging.operation.enabled = false"); + String sql = "select count(*) from " + tableName; + HiveStatement stmt = (HiveStatement)con.createStatement(); + assertNotNull("Statement is null", stmt); + stmt.executeQuery(sql); + List logs = stmt.getQueryLog(false, 10); + stmt.close(); + assertTrue(logs.size() == 0); + setStmt.execute("set hive.server2.logging.operation.enabled = true"); + setStmt.close(); + } + private void verifyFetchedLog(List logs, String[] expectedLogs) { StringBuilder stringBuilder = new StringBuilder(); diff --git a/service/src/java/org/apache/hive/service/cli/operation/OperationManager.java b/service/src/java/org/apache/hive/service/cli/operation/OperationManager.java index 92c340a29c1071725184e194c12001ecdd9c45ba..9b0a51958adb54f2521f9752edfe5a9d9735ce41 100644 --- a/service/src/java/org/apache/hive/service/cli/operation/OperationManager.java +++ b/service/src/java/org/apache/hive/service/cli/operation/OperationManager.java @@ -27,6 +27,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.hadoop.hive.conf.HiveConf; +import org.apache.hadoop.hive.conf.HiveConf.ConfVars; import org.apache.hadoop.hive.metastore.api.FieldSchema; import org.apache.hadoop.hive.metastore.api.Schema; import org.apache.hadoop.hive.ql.session.OperationLog; @@ -221,14 +222,22 @@ public RowSet getOperationNextRowSet(OperationHandle opHandle, } public RowSet getOperationLogRowSet(OperationHandle opHandle, - FetchOrientation orientation, long maxRows) + FetchOrientation orientation, long maxRows, HiveConf hConf) throws HiveSQLException { + TableSchema tableSchema = new TableSchema(getLogSchema()); + RowSet rowSet = RowSetFactory.create(tableSchema, getOperation(opHandle).getProtocolVersion()); + + if (hConf.getBoolVar(ConfVars.HIVE_SERVER2_LOGGING_OPERATION_ENABLED) == false) { + LOG.warn("Try to get operation log when hive.server2.logging.operation.enabled is false, no log will be returned. "); + return rowSet; + } // get the OperationLog object from the operation OperationLog operationLog = getOperation(opHandle).getOperationLog(); if (operationLog == null) { throw new HiveSQLException("Couldn't find log associated with operation handle: " + opHandle); } + // read logs List logs; try { @@ -239,8 +248,6 @@ public RowSet getOperationLogRowSet(OperationHandle opHandle, // convert logs to RowSet - TableSchema tableSchema = new TableSchema(getLogSchema()); - RowSet rowSet = RowSetFactory.create(tableSchema, getOperation(opHandle).getProtocolVersion()); for (String log : logs) { rowSet.addRow(new String[] {log}); } diff --git a/service/src/java/org/apache/hive/service/cli/session/HiveSessionImpl.java b/service/src/java/org/apache/hive/service/cli/session/HiveSessionImpl.java index cc3e807e7a8401c9e3351d7ed2c14f227e4e63bf..343c68effce3ca134638476d243c7913aab67163 100644 --- a/service/src/java/org/apache/hive/service/cli/session/HiveSessionImpl.java +++ b/service/src/java/org/apache/hive/service/cli/session/HiveSessionImpl.java @@ -684,7 +684,7 @@ public RowSet fetchResults(OperationHandle opHandle, FetchOrientation orientatio if (fetchType == FetchType.QUERY_OUTPUT) { return operationManager.getOperationNextRowSet(opHandle, orientation, maxRows); } - return operationManager.getOperationLogRowSet(opHandle, orientation, maxRows); + return operationManager.getOperationLogRowSet(opHandle, orientation, maxRows, hiveConf); } finally { release(true); }