use of org.apache.hadoop.hive.ql.history.HiveHistory.QueryInfo in project hive by apache.
the class HiveHistoryViewer method handle.
/**
* Implementation Listener interface function.
*
* @see org.apache.hadoop.hive.ql.history.HiveHistory.Listener#handle(org.apache.hadoop.hive.ql.history.HiveHistory.RecordTypes,
* java.util.Map)
*/
public void handle(RecordTypes recType, Map<String, String> values) {
if (recType == RecordTypes.SessionStart) {
sessionId = values.get(Keys.SESSION_ID.name());
} else if (recType == RecordTypes.QueryStart || recType == RecordTypes.QueryEnd) {
String key = values.get(Keys.QUERY_ID.name());
QueryInfo ji;
if (jobInfoMap.containsKey(key)) {
ji = jobInfoMap.get(key);
ji.hm.putAll(values);
} else {
ji = new QueryInfo();
ji.hm = new HashMap<String, String>();
ji.hm.putAll(values);
jobInfoMap.put(key, ji);
}
} else if (recType == RecordTypes.TaskStart || recType == RecordTypes.TaskEnd || recType == RecordTypes.TaskProgress) {
String jobid = values.get(Keys.QUERY_ID.name());
String taskid = values.get(Keys.TASK_ID.name());
String key = jobid + ":" + taskid;
TaskInfo ti;
if (taskInfoMap.containsKey(key)) {
ti = taskInfoMap.get(key);
ti.hm.putAll(values);
} else {
ti = new TaskInfo();
ti.hm = new HashMap<String, String>();
ti.hm.putAll(values);
taskInfoMap.put(key, ti);
}
}
}
use of org.apache.hadoop.hive.ql.history.HiveHistory.QueryInfo in project hive by apache.
the class TestHiveHistory method testSimpleQuery.
/**
* Check history file output for this query.
*/
@Test
public void testSimpleQuery() {
new LineageInfo();
try {
// before any of the other core hive classes are loaded
try {
LogUtils.initHiveLog4j();
} catch (LogInitializationException e) {
}
HiveConf hconf = new HiveConf(SessionState.class);
hconf.setBoolVar(ConfVars.HIVE_SESSION_HISTORY_ENABLED, true);
CliSessionState ss = new CliSessionState(hconf);
ss.in = System.in;
try {
ss.out = new SessionStream(System.out, true, "UTF-8");
ss.err = new SessionStream(System.err, true, "UTF-8");
} catch (UnsupportedEncodingException e) {
System.exit(3);
}
SessionState.start(ss);
String cmd = "select a.key+1 from src a";
IDriver d = DriverFactory.newDriver(conf);
d.run(cmd);
HiveHistoryViewer hv = new HiveHistoryViewer(SessionState.get().getHiveHistory().getHistFileName());
Map<String, QueryInfo> jobInfoMap = hv.getJobInfoMap();
Map<String, TaskInfo> taskInfoMap = hv.getTaskInfoMap();
if (jobInfoMap.size() != 1) {
fail("jobInfo Map size not 1");
}
if (taskInfoMap.size() != 1) {
fail("jobInfo Map size not 1");
}
cmd = (String) jobInfoMap.keySet().toArray()[0];
QueryInfo ji = jobInfoMap.get(cmd);
if (!ji.hm.get(Keys.QUERY_NUM_TASKS.name()).equals("1")) {
fail("Wrong number of tasks");
}
} catch (Exception e) {
e.printStackTrace();
fail("Failed");
}
}
Aggregations