private HiveHookEventProtoPartialBuilder getPreHookEvent(HookContext hookContext) {
      QueryPlan plan = hookContext.getQueryPlan();
      LOG.info("Received pre-hook notification for: " + plan.getQueryId());

      // Make a copy so that we do not modify hookContext conf.
      HiveConf conf = new HiveConf(hookContext.getConf());
      List<ExecDriver> mrTasks = Utilities.getMRTasks(plan.getRootTasks());
      List<TezTask> tezTasks = Utilities.getTezTasks(plan.getRootTasks());
      ExecutionMode executionMode = getExecutionMode(plan, mrTasks, tezTasks);

      Map<OtherInfoType, JSONObject> otherInfo = new HashMap<>();
      HiveHookEventProto.Builder builder = HiveHookEventProto.newBuilder();
      builder.setEventType(EventType.QUERY_SUBMITTED.name());
      builder.setTimestamp(plan.getQueryStartTime());
      builder.setHiveQueryId(plan.getQueryId());
      builder.setUser(getUser(hookContext));
      builder.setRequestUser(getRequestUser(hookContext));
      String queueName = getQueueName(executionMode, conf);
      if (queueName != null) {
        builder.setQueue(queueName);
      }
      builder.setExecutionMode(executionMode.name());
      builder.addAllTablesRead(getTablesFromEntitySet(hookContext.getInputs()));
      builder.addAllTablesWritten(getTablesFromEntitySet(hookContext.getOutputs()));
      if (hookContext.getOperationId() != null) {
        builder.setOperationId(hookContext.getOperationId());
      }

      addMapEntry(builder, OtherInfoType.TEZ, Boolean.toString(tezTasks.size() > 0));
      addMapEntry(builder, OtherInfoType.MAPRED, Boolean.toString(mrTasks.size() > 0));
      addMapEntry(builder, OtherInfoType.SESSION_ID, hookContext.getSessionId());
      String logID = conf.getLogIdVar(hookContext.getSessionId());
      addMapEntry(builder, OtherInfoType.INVOKER_INFO, logID);
      addMapEntry(builder, OtherInfoType.THREAD_NAME, hookContext.getThreadId());
      addMapEntry(builder, OtherInfoType.VERSION, Integer.toString(VERSION));
      addMapEntry(builder, OtherInfoType.CLIENT_IP_ADDRESS, hookContext.getIpAddress());

      String hiveInstanceAddress = hookContext.getHiveInstanceAddress();
      if (hiveInstanceAddress == null) {
        try {
          hiveInstanceAddress = InetAddress.getLocalHost().getHostAddress();
        } catch (UnknownHostException e) {
          LOG.error("Error tyring to get localhost address: ", e);
        }
      }
      addMapEntry(builder, OtherInfoType.HIVE_ADDRESS, hiveInstanceAddress);

      String hiveInstanceType = hookContext.isHiveServerQuery() ? "HS2" : "CLI";
      addMapEntry(builder, OtherInfoType.HIVE_INSTANCE_TYPE, hiveInstanceType);

      ApplicationId llapId = determineLlapId(conf, executionMode);
      if (llapId != null) {
        addMapEntry(builder, OtherInfoType.LLAP_APP_ID, llapId.toString());
      }

      conf.stripHiddenConfigurations(conf);
      JSONObject confObj = new JSONObject();
      for (Map.Entry<String, String> setting : conf) {
        confObj.put(setting.getKey(), setting.getValue());
      }
      otherInfo.put(OtherInfoType.CONF, confObj);

      ExplainConfiguration explainConfig = new ExplainConfiguration();
      explainConfig.setFormatted(true);
      ExplainWork explainWork = new ExplainWork(null, // resFile
              null, // pCtx
              plan.getRootTasks(), // RootTasks
              plan.getFetchTask(), // FetchTask
              null, null, // analyzer
              explainConfig, // explainConfig
              plan.getCboInfo(), // cboInfo,
              plan.getOptimizedQueryString(),
              plan.getOptimizedCBOPlan());
      return new HiveHookEventProtoPartialBuilder(
              builder, explainWork, otherInfo, plan.getQueryStr(), conf.getVar(ConfVars.HIVE_STAGE_ID_REARRANGE));
    }
Log events from hive hook using protobuf serialized format, partitioned by date.
ql/src/java/org/apache/hadoop/hive/ql/hooks/HiveProtoLoggingHook.java