void replaceLocationForProtoLogTables(String sqlScriptFile) throws IOException {
    TezConfiguration tezConf = new TezConfiguration(true);
    boolean hiveProtoLoggingEnabled = true;
    boolean tezProtoLoggingEnabled = true;
    String hiveProtoBaseDir = HiveConf.getVar(conf, HiveConf.ConfVars.HIVE_PROTO_EVENTS_BASE_PATH);
    String tezProtoBaseDir = tezConf.get(TezConfiguration.TEZ_HISTORY_LOGGING_PROTO_BASE_DIR);
    String hiveLocation = "/tmp/query_data"; // if Hive protologging is not enabled, use dummy location for Hive protolog tables
    String tezLocation = "/tmp"; // if Tez protologging is not enabled, use dummy location for Tez protolog tables
    String line;
    StringBuilder newLine = new StringBuilder();
    Map<String, String> replacements = new HashMap<>();

    if (isEmpty(hiveProtoBaseDir)) {
      LOG.warn("Hive conf variable hive.hook.proto.base-directory is not set for creating protologging tables");
      hiveProtoLoggingEnabled = false;
    }
    if (isEmpty(tezProtoBaseDir)) {
      LOG.warn("Tez conf variable tez.history.logging.proto-base-dir is not set for creating protologging tables");
      tezProtoLoggingEnabled = false;
    }

    if (hiveProtoLoggingEnabled) {
      String hiveProtoScheme = new Path(hiveProtoBaseDir).getFileSystem(conf).getScheme() + ":///";
      hiveLocation = new Path(hiveProtoBaseDir).getFileSystem(conf).getUri().isAbsolute() ? hiveProtoBaseDir : hiveProtoScheme + hiveProtoBaseDir;
    }
    if (tezProtoLoggingEnabled) {
      String tezProtoScheme = new Path(tezProtoBaseDir).getFileSystem(tezConf).getScheme() + ":///";
      tezLocation = new Path(tezProtoBaseDir).getFileSystem(tezConf).getUri().isAbsolute() ? tezProtoBaseDir : tezProtoScheme + tezProtoBaseDir;
    }

    replacements.put("_REPLACE_WITH_QUERY_DATA_LOCATION_", hiveLocation);
    replacements.put("_REPLACE_WITH_APP_DATA_LOCATION_", tezLocation + "/app_data");
    replacements.put("_REPLACE_WITH_DAG_DATA_LOCATION_", tezLocation + "/dag_data");
    replacements.put("_REPLACE_WITH_DAG_META_LOCATION_", tezLocation + "/dag_meta");

    try (BufferedReader reader = new BufferedReader(new FileReader(sqlScriptFile))) {
      while ((line = reader.readLine()) != null) {
        for (Map.Entry<String, String> entry : replacements.entrySet()) {
          if (line.contains(entry.getKey())) {
            line = line.replace(entry.getKey(), entry.getValue());
          }
        }
        newLine.append(line).append("\n");
      }
    }

    try (BufferedWriter writer = new BufferedWriter(new FileWriter(sqlScriptFile))) {
      writer.write(newLine.toString());
    }
  }
Run beeline with the given metastore script. Flatten the nested scripts
into single file.
beeline/src/java/org/apache/hive/beeline/schematool/HiveSchemaTool.java