コード例 #1
0
 private static void runCommand(HiveClient hive, String command)
     throws HiveServerException, TException {
   int batchSize = 80;
   hive.execute(command);
   List<String> results;
   do {
     results = hive.fetchN(batchSize);
   } while (results.size() == batchSize);
 }
コード例 #2
0
ファイル: HiveUtils.java プロジェクト: bfung/spring-hadoop
 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);
   }
 }
コード例 #3
0
ファイル: HiveUtils.java プロジェクト: bfung/spring-hadoop
 static List<String> run(HiveClient hive, Iterable<HiveScript> scripts, boolean closeHive)
     throws DataAccessException {
   List<String> results = new ArrayList<String>();
   try {
     for (HiveScript hiveScript : scripts) {
       results.addAll(run(hive, hiveScript));
     }
   } finally {
     try {
       if (closeHive) {
         hive.shutdown();
       }
     } catch (Exception ex) {
     }
   }
   return results;
 }
コード例 #4
0
  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);
    }
  }