@Override
    public void run(HookContext hookContext) throws Exception {
      HiveConf conf = hookContext.getConf();
      Set<ReadEntity> inputs = hookContext.getQueryPlan().getInputs();

      Hive db;
      try {
        db = Hive.get(conf);
      } catch (HiveException e) {
        // ignore
        db = null;
        return;
      }

      int lastAccessTime = (int) (System.currentTimeMillis()/1000);

      for(ReadEntity re: inputs) {
        // Set the last query time
        ReadEntity.Type typ = re.getType();
        switch(typ) {
        // It is possible that read and write entities contain a old version
        // of the object, before it was modified by StatsTask.
        // Get the latest versions of the object
        case TABLE: {
          if(re.getTable().getTableName().equals("_dummy_table")){
            break;
          }
          String dbName = re.getTable().getDbName();
          String tblName = re.getTable().getTableName();
          Table t = db.getTable(dbName, tblName);
          t.setLastAccessTime(lastAccessTime);
          EnvironmentContext ec = new EnvironmentContext();
          /*we are not modifying any data so stats should be exactly the same*/
          ec.putToProperties(StatsSetupConst.DO_NOT_UPDATE_STATS, StatsSetupConst.TRUE);
          db.alterTable(dbName + "." + tblName, t, false, ec, false);
          break;
        }
        case PARTITION: {
          String dbName = re.getTable().getDbName();
          String tblName = re.getTable().getTableName();
          Partition p = re.getPartition();
          Table t = db.getTable(dbName, tblName);
          p = db.getPartition(t, p.getSpec(), false);
          p.setLastAccessTime(lastAccessTime);
          db.alterPartition(null, dbName, tblName, p, null, false);
          t.setLastAccessTime(lastAccessTime);
          EnvironmentContext ec = new EnvironmentContext();
          /*we are not modifying any data so stats should be exactly the same*/
          ec.putToProperties(StatsSetupConst.DO_NOT_UPDATE_STATS, StatsSetupConst.TRUE);
          db.alterTable(dbName + "." + tblName, t, false, ec, false);
          break;
        }
        default:
          // ignore dummy inputs
          break;
        }
      }
    }
Implementation of a pre execute hook that updates the access
times for all the inputs.
ql/src/java/org/apache/hadoop/hive/ql/hooks/UpdateInputAccessTimeHook.java