use of org.apache.hive.service.cli.OperationHandle in project hive by apache.
the class TestSessionManagerMetrics method testActiveSessionTimeMetrics.
@Test
public void testActiveSessionTimeMetrics() throws Exception {
final CyclicBarrier ready = new CyclicBarrier(2);
CyclicBarrier completed = new CyclicBarrier(2);
String json = metrics.dumpJson();
MetricsTestUtils.verifyMetricsJson(json, MetricsTestUtils.GAUGE, MetricsConstant.HS2_AVG_ACTIVE_SESSION_TIME, "NaN");
SessionHandle handle = sm.openSession(TProtocolVersion.HIVE_CLI_SERVICE_PROTOCOL_V9, "user", "passw", "127.0.0.1", new HashMap<String, String>());
final HiveSession session = sm.getSession(handle);
OperationManager operationManager = mock(OperationManager.class);
when(operationManager.newGetTablesOperation(session, "catalog", "schema", "table", null)).thenReturn(new BlockingOperation(session, OperationType.GET_TABLES, ready, completed));
session.setOperationManager(operationManager);
long sessionActivateTime = System.currentTimeMillis();
new Thread(new Runnable() {
@Override
public void run() {
try {
Hive.set(session.getSessionHive());
OperationHandle handle = session.getTables("catalog", "schema", "table", null);
session.closeOperation(handle);
} catch (Exception e) {
throw new RuntimeException(e);
} finally {
try {
ready.await();
} catch (InterruptedException | BrokenBarrierException e) {
// ignore
}
}
}
}).start();
ready.await(2, TimeUnit.SECONDS);
ready.reset();
json = metrics.dumpJson();
MetricsTestUtils.verifyMetricsJson(json, MetricsTestUtils.GAUGE, MetricsConstant.HS2_AVG_ACTIVE_SESSION_TIME, (double) System.currentTimeMillis() - sessionActivateTime, 100d);
completed.await(2, TimeUnit.SECONDS);
ready.await(2, TimeUnit.SECONDS);
json = metrics.dumpJson();
MetricsTestUtils.verifyMetricsJson(json, MetricsTestUtils.GAUGE, MetricsConstant.HS2_AVG_ACTIVE_SESSION_TIME, "NaN");
}
use of org.apache.hive.service.cli.OperationHandle in project hive by apache.
the class ThriftCLIServiceTest method testExecuteStatementAsync.
/**
* Test asynchronous query execution and error reporting to the client
* @throws Exception
*/
@Test
public void testExecuteStatementAsync() throws Exception {
Map<String, String> opConf = new HashMap<String, String>();
// Open a new client session
SessionHandle sessHandle = client.openSession(USERNAME, PASSWORD, opConf);
// Session handle should not be null
assertNotNull("Session handle should not be null", sessHandle);
OperationHandle opHandle;
OperationStatus opStatus;
OperationState state = null;
// Change lock manager to embedded mode
String queryString = "SET hive.lock.manager=" + "org.apache.hadoop.hive.ql.lockmgr.EmbeddedLockManager";
client.executeStatement(sessHandle, queryString, opConf);
// Drop the table if it exists
queryString = "DROP TABLE IF EXISTS TEST_EXEC_ASYNC_THRIFT";
client.executeStatement(sessHandle, queryString, opConf);
// Create a test table
queryString = "CREATE TABLE TEST_EXEC_ASYNC_THRIFT(ID STRING)";
client.executeStatement(sessHandle, queryString, opConf);
// Execute another query
queryString = "SELECT ID+1 FROM TEST_EXEC_ASYNC_THRIFT";
System.out.println("Will attempt to execute: " + queryString);
opHandle = client.executeStatementAsync(sessHandle, queryString, opConf);
assertNotNull(opHandle);
// Poll on the operation status till the query is completed
boolean isQueryRunning = true;
long pollTimeout = System.currentTimeMillis() + 100000;
while (isQueryRunning) {
// Break if polling times out
if (System.currentTimeMillis() > pollTimeout) {
System.out.println("Polling timed out");
break;
}
opStatus = client.getOperationStatus(opHandle, false);
assertNotNull(opStatus);
state = opStatus.getState();
System.out.println("Current state: " + state);
if (state == OperationState.CANCELED || state == OperationState.CLOSED || state == OperationState.FINISHED || state == OperationState.ERROR) {
isQueryRunning = false;
}
Thread.sleep(1000);
}
// Expect query to be successfully completed now
assertEquals("Query should be finished", OperationState.FINISHED, state);
// Execute a malformed query
// This query will give a runtime error
queryString = "CREATE TABLE NON_EXISTING_TAB (ID STRING) location 'hdfs://localhost:10000/a/b/c'";
System.out.println("Will attempt to execute: " + queryString);
opHandle = client.executeStatementAsync(sessHandle, queryString, opConf);
assertNotNull(opHandle);
opStatus = client.getOperationStatus(opHandle, false);
assertNotNull(opStatus);
isQueryRunning = true;
pollTimeout = System.currentTimeMillis() + 100000;
while (isQueryRunning) {
// Break if polling times out
if (System.currentTimeMillis() > pollTimeout) {
System.out.println("Polling timed out");
break;
}
state = opStatus.getState();
System.out.println("Current state: " + state);
if (state == OperationState.CANCELED || state == OperationState.CLOSED || state == OperationState.FINISHED || state == OperationState.ERROR) {
isQueryRunning = false;
}
Thread.sleep(1000);
opStatus = client.getOperationStatus(opHandle, false);
}
// Expect query to return an error state
assertEquals("Operation should be in error state", OperationState.ERROR, state);
// sqlState, errorCode should be set to appropriate values
assertEquals(opStatus.getOperationException().getSQLState(), "08S01");
assertEquals(opStatus.getOperationException().getErrorCode(), 40000);
// Cleanup
queryString = "DROP TABLE TEST_EXEC_ASYNC_THRIFT";
client.executeStatement(sessHandle, queryString, opConf);
client.closeSession(sessHandle);
}
use of org.apache.hive.service.cli.OperationHandle in project hive by apache.
the class ThriftCLIServiceTest method testGetFunctions.
@Test
public void testGetFunctions() throws Exception {
SessionHandle sessHandle = client.openSession(USERNAME, PASSWORD, new HashMap<String, String>());
assertNotNull("Session handle should not be null", sessHandle);
String catalogName = null;
String schemaName = null;
String functionName = "*";
OperationHandle opHandle = client.getFunctions(sessHandle, catalogName, schemaName, functionName);
assertNotNull("Operation handle should not be null", opHandle);
client.closeSession(sessHandle);
}
use of org.apache.hive.service.cli.OperationHandle in project hive by apache.
the class TestQueryDisplay method checkWebuiExplainOutput.
/**
* Test for the HiveConf option HIVE_SERVER2_WEBUI_EXPLAIN_OUTPUT.
*/
@Test
public void checkWebuiExplainOutput() throws Exception {
// check cases when HIVE_SERVER2_WEBUI_EXPLAIN_OUTPUT is set and not set
boolean[] webuiExplainConfValues = new boolean[] { true, false };
for (boolean confValue : webuiExplainConfValues) {
conf.setBoolVar(HiveConf.ConfVars.HIVE_SERVER2_WEBUI_EXPLAIN_OUTPUT, confValue);
HiveSession session = sessionManager.createSession(new SessionHandle(TProtocolVersion.HIVE_CLI_SERVICE_PROTOCOL_V8), TProtocolVersion.HIVE_CLI_SERVICE_PROTOCOL_V8, "testuser", "", "", new HashMap<String, String>(), false, "");
SessionState.start(conf);
OperationHandle opHandle = session.executeStatement("show tables", null);
session.closeOperation(opHandle);
// STAGE PLANS is something which will be shown as part of EXPLAIN query
verifyDDLHtml("STAGE PLANS", opHandle.getHandleIdentifier().toString(), confValue);
// Check that the following message is not shown when this option is set
verifyDDLHtml("Set configuration hive.server2.webui.explain.output to true to view future query plans", opHandle.getHandleIdentifier().toString(), !confValue);
session.close();
}
}
use of org.apache.hive.service.cli.OperationHandle in project hive by apache.
the class TestQueryDisplay method checkWebUIShowStats.
/**
* Test for the HiveConf option HIVE_SERVER2_WEBUI_SHOW_STATS, which is available for MapReduce
* jobs only.
*/
@Test
public void checkWebUIShowStats() throws Exception {
// WebUI-related boolean confs must be set before build. HIVE_SERVER2_WEBUI_SHOW_STATS depends
// on HIVE_SERVER2_WEBUI_EXPLAIN_OUTPUT and HIVE_SERVER2_WEBUI_SHOW_GRAPH being set to true.
conf.setVar(HiveConf.ConfVars.HIVE_EXECUTION_ENGINE, "mr");
conf.setBoolVar(HiveConf.ConfVars.HIVE_SERVER2_WEBUI_EXPLAIN_OUTPUT, true);
conf.setBoolVar(HiveConf.ConfVars.HIVE_SERVER2_WEBUI_SHOW_GRAPH, true);
conf.setIntVar(HiveConf.ConfVars.HIVE_SERVER2_WEBUI_MAX_GRAPH_SIZE, 40);
conf.setBoolVar(HiveConf.ConfVars.HIVE_SERVER2_WEBUI_SHOW_STATS, true);
HiveSession session = sessionManager.createSession(new SessionHandle(TProtocolVersion.HIVE_CLI_SERVICE_PROTOCOL_V8), TProtocolVersion.HIVE_CLI_SERVICE_PROTOCOL_V8, "testuser", "", "", new HashMap<String, String>(), false, "");
SessionState.start(conf);
OperationHandle opHandleSetup = session.executeStatement("CREATE TABLE statsTable (i int)", null);
session.closeOperation(opHandleSetup);
OperationHandle opHandleMrQuery = session.executeStatement("INSERT INTO statsTable VALUES (0)", null);
session.closeOperation(opHandleMrQuery);
// INSERT queries include a MapReduce task.
verifyDDLHtml("Counters", opHandleMrQuery.getHandleIdentifier().toString(), true);
session.close();
resetConfToDefaults();
}
Aggregations