Search in sources :

Example 1 with TaskInfo

use of org.apache.hadoop.hive.ql.history.HiveHistory.TaskInfo 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);
        }
    }
}
Also used : TaskInfo(org.apache.hadoop.hive.ql.history.HiveHistory.TaskInfo) HashMap(java.util.HashMap) QueryInfo(org.apache.hadoop.hive.ql.history.HiveHistory.QueryInfo)

Example 2 with TaskInfo

use of org.apache.hadoop.hive.ql.history.HiveHistory.TaskInfo 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");
    }
}
Also used : UnsupportedEncodingException(java.io.UnsupportedEncodingException) QueryInfo(org.apache.hadoop.hive.ql.history.HiveHistory.QueryInfo) LineageInfo(org.apache.hadoop.hive.ql.tools.LineageInfo) CliSessionState(org.apache.hadoop.hive.cli.CliSessionState) LogInitializationException(org.apache.hadoop.hive.common.LogUtils.LogInitializationException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) TaskInfo(org.apache.hadoop.hive.ql.history.HiveHistory.TaskInfo) SessionStream(org.apache.hadoop.hive.common.io.SessionStream) LogInitializationException(org.apache.hadoop.hive.common.LogUtils.LogInitializationException) IDriver(org.apache.hadoop.hive.ql.IDriver) HiveConf(org.apache.hadoop.hive.conf.HiveConf) Test(org.junit.Test)

Aggregations

QueryInfo (org.apache.hadoop.hive.ql.history.HiveHistory.QueryInfo)2 TaskInfo (org.apache.hadoop.hive.ql.history.HiveHistory.TaskInfo)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 HashMap (java.util.HashMap)1 CliSessionState (org.apache.hadoop.hive.cli.CliSessionState)1 LogInitializationException (org.apache.hadoop.hive.common.LogUtils.LogInitializationException)1 SessionStream (org.apache.hadoop.hive.common.io.SessionStream)1 HiveConf (org.apache.hadoop.hive.conf.HiveConf)1 IDriver (org.apache.hadoop.hive.ql.IDriver)1 LineageInfo (org.apache.hadoop.hive.ql.tools.LineageInfo)1 Test (org.junit.Test)1