Пример #1
0
 private static List<String> runCommand(HiveClient hive, String command)
     throws DataAccessException {
   try {
     hive.execute(command);
     return hive.fetchAll();
   } catch (Exception ex) {
     try {
       hive.clean();
     } catch (Exception exc) {
     }
     if (ex instanceof HiveServerException) {
       throw convert((HiveServerException) ex);
     }
     throw convert((TException) ex);
   }
 }
  private static void runScript(HiveClient hive, Resource resource, String encoding)
      throws Exception {
    InputStream stream = resource.getInputStream();
    BufferedReader reader =
        new BufferedReader(
            (StringUtils.hasText(encoding)
                ? new InputStreamReader(stream, encoding)
                : new InputStreamReader(stream)));

    String line = null;
    try {
      String command = "";
      while ((line = reader.readLine()) != null) {
        // strip whitespace
        line = line.trim();
        // ignore comments
        if (!line.startsWith("--")) {
          for (String token : line.split(";")) {
            token = token.trim();
            // skip empty lines
            if (!StringUtils.hasText(token)) {
              continue;
            }
            if (token.endsWith("\\")) {
              command.concat(token);
              continue;
            } else {
              command = token;
            }

            runCommand(hive, command);
            command = "";
          }
        }
      }
    } catch (Exception ex) {
      try {
        hive.clean();
      } catch (Exception exc) {
      }
    } finally {
      IOUtils.closeStream(reader);
    }
  }