Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import org.apache.hadoop.hive.ql.session.SessionState.LogHelper;
import org.apache.hadoop.hive.serde2.SerDeUtils;
import org.apache.hadoop.hive.shims.Utils;
import org.apache.hive.service.rpc.thrift.TOperationState;
import org.apache.tez.common.counters.DAGCounter;
import org.apache.tez.common.counters.TaskCounter;
import org.apache.tez.common.counters.TezCounters;
Expand Down Expand Up @@ -89,7 +90,7 @@ public void testSimpleFlush() throws Exception {
service.start();

// prepare the source object from which the QueryHistoryService will obtain query information
QueryInfo queryInfo = spy(new QueryInfo(DummyRecord.QUERY_STATE, DummyRecord.END_USER,
QueryInfo queryInfo = spy(new QueryInfo(TOperationState.INITIALIZED_STATE, DummyRecord.END_USER,
DummyRecord.EXECUTION_ENGINE, DummyRecord.SESSION_ID,
DummyRecord.OPERATION_ID));
// elapsed time is calculated from System.currentTimeMillis(), let's mock it here for unit test convenience's sake
Expand Down
43 changes: 39 additions & 4 deletions ql/src/java/org/apache/hadoop/hive/ql/QueryInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package org.apache.hadoop.hive.ql;

import org.apache.hadoop.hive.conf.HiveConf;
import org.apache.hive.service.rpc.thrift.TOperationState;

/**
* The class is synchronized, as WebUI may access information about a running query.
Expand All @@ -31,12 +32,13 @@ public class QueryInfo {
private final String operationId;
private Long runtime; // tracks only running portion of the query.
private Long endTime;
private String state;
private TOperationState state;
private QueryDisplay queryDisplay;

private String operationLogLocation;

public QueryInfo(String state, String userName, String executionEngine, String sessionId, String operationId) {
public QueryInfo(TOperationState state, String userName, String executionEngine, String sessionId,
String operationId) {
this.state = state;
this.userName = userName;
this.executionEngine = executionEngine;
Expand All @@ -46,7 +48,7 @@ public QueryInfo(String state, String userName, String executionEngine, String s
}

public static QueryInfo getFromConf(HiveConf conf) {
return new QueryInfo("INITIALIZED", conf.get(DriverContext.DEFAULT_USER_NAME_PROP),
return new QueryInfo(TOperationState.INITIALIZED_STATE, conf.get(DriverContext.DEFAULT_USER_NAME_PROP),
conf.getVar(HiveConf.ConfVars.HIVE_EXECUTION_ENGINE), HiveConf.getVar(conf, HiveConf.ConfVars.HIVE_SESSION_ID),
conf.get(DriverContext.DEFAULT_OPERATION_ID_PROP));
}
Expand Down Expand Up @@ -80,6 +82,10 @@ public String getExecutionEngine() {
}

public synchronized String getState() {
return getDisplayState(state);
}

public synchronized TOperationState getOperationState() {
return state;
}

Expand All @@ -91,7 +97,7 @@ public synchronized Long getEndTime() {
return endTime;
}

public synchronized void updateState(String state) {
public synchronized void updateState(TOperationState state) {
this.state = state;
}

Expand Down Expand Up @@ -122,4 +128,33 @@ public String getOperationLogLocation() {
public void setOperationLogLocation(String operationLogLocation) {
this.operationLogLocation = operationLogLocation;
}

private static String getDisplayState(TOperationState state) {
if (state == null) {
return "UNKNOWN";
}

switch (state) {
case INITIALIZED_STATE:
return "INITIALIZED";
case RUNNING_STATE:
return "RUNNING";
case FINISHED_STATE:
return "FINISHED";
case CANCELED_STATE:
return "CANCELED";
case CLOSED_STATE:
return "CLOSED";
case ERROR_STATE:
return "ERROR";
case UKNOWN_STATE:
return "UNKNOWN";
case PENDING_STATE:
return "PENDING";
case TIMEDOUT_STATE:
return "TIMEDOUT";
default:
return "UNKNOWN";
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public SQLOperation(HiveSession parentSession, String statement, Map<String, Str

setupSessionIO(parentSession.getSessionState());

queryInfo = new QueryInfo(getState().toString(), getParentSession().getUserName(),
queryInfo = new QueryInfo(getState().toTOperationState(), getParentSession().getUserName(),
getExecutionEngine(), getParentSession().getSessionHandle().getHandleIdentifier().toString(),
getHandle().getHandleIdentifier().toString());

Expand Down Expand Up @@ -628,7 +628,7 @@ protected void onNewState(final OperationState state, final OperationState prevS
if (metrics.isPresent() && submittedQryScp.isPresent()) {
metrics.get().endScope(submittedQryScp.get());
}
queryInfo.updateState(state.toString());
queryInfo.updateState(state.toTOperationState());
break;
case CLOSED:
queryInfo.setEndTime();
Expand All @@ -639,15 +639,15 @@ protected void onNewState(final OperationState state, final OperationState prevS
metrics.get().endScope(submittedQryScp.get());
}
markQueryMetric(MetricsFactory.getInstance(), MetricsConstant.HS2_FAILED_QUERIES);
queryInfo.updateState(state.toString());
queryInfo.updateState(state.toTOperationState());
break;
case FINISHED:
queryInfo.setRuntime(getOperationComplete() - getOperationStart());
if (metrics.isPresent() && submittedQryScp.isPresent()) {
metrics.get().endScope(submittedQryScp.get());
}
markQueryMetric(MetricsFactory.getInstance(), MetricsConstant.HS2_SUCCEEDED_QUERIES);
queryInfo.updateState(state.toString());
queryInfo.updateState(state.toTOperationState());
break;
case INITIALIZED:
/* fall through */
Expand All @@ -660,7 +660,7 @@ protected void onNewState(final OperationState state, final OperationState prevS
case UNKNOWN:
/* fall through */
default:
queryInfo.updateState(state.toString());
queryInfo.updateState(state.toTOperationState());
break;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@
import org.apache.hive.service.cli.operation.OperationManager;
import org.apache.hive.service.cli.session.HiveSession;
import org.apache.hive.service.cli.session.SessionManager;
import org.apache.hive.service.rpc.thrift.TOperationState;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.Version;
Expand Down Expand Up @@ -141,6 +143,7 @@ private void sendAsJson(
response.setContentType("application/json");
response.setStatus(HttpServletResponse.SC_OK);
ObjectMapper mapper = new ObjectMapper();
mapper.addMixIn(QueryInfo.class, QueryInfoJsonMixin.class);
SimpleModule module = new SimpleModule("CustomSessionModule", new Version(1, 0, 0, null, null, null));
module.addSerializer(HiveSession.class, new HiveSessionSerializer());
mapper.registerModule(module);
Expand All @@ -157,6 +160,11 @@ private void sendAsJson(
}
}

private abstract static class QueryInfoJsonMixin {
@JsonIgnore
abstract TOperationState getOperationState();
}

private static class HiveSessionSerializer extends JsonSerializer<HiveSession> {
@Override
public void serialize(
Expand Down
Loading