Search in sources :

Example 96 with SessionState

use of org.apache.hadoop.hive.ql.session.SessionState in project phoenix by apache.

the class HiveTestUtil method executeDiffCommand.

private static int executeDiffCommand(String inFileName, String outFileName, boolean ignoreWhiteSpace, boolean sortResults) throws Exception {
    int result = 0;
    if (sortResults) {
        // sort will try to open the output file in write mode on windows. We need to
        // close it first.
        SessionState ss = SessionState.get();
        if (ss != null && ss.out != null && ss.out != System.out) {
            ss.out.close();
        }
        String inSorted = inFileName + SORT_SUFFIX;
        String outSorted = outFileName + SORT_SUFFIX;
        result = sortFiles(inFileName, inSorted);
        result |= sortFiles(outFileName, outSorted);
        if (result != 0) {
            LOG.error("ERROR: Could not sort files before comparing");
            return result;
        }
        inFileName = inSorted;
        outFileName = outSorted;
    }
    ArrayList<String> diffCommandArgs = new ArrayList<String>();
    diffCommandArgs.add("diff");
    // Text file comparison
    diffCommandArgs.add("-a");
    // Ignore changes in the amount of white space
    if (ignoreWhiteSpace || Shell.WINDOWS) {
        diffCommandArgs.add("-b");
    }
    // spaces at the end of the line.
    if (Shell.WINDOWS) {
        // Strip trailing carriage return on input
        diffCommandArgs.add("--strip-trailing-cr");
        // Ignore changes whose lines are all blank
        diffCommandArgs.add("-B");
    }
    // Add files to compare to the arguments list
    diffCommandArgs.add(getQuotedString(inFileName));
    diffCommandArgs.add(getQuotedString(outFileName));
    result = executeCmd(diffCommandArgs);
    if (sortResults) {
        new File(inFileName).delete();
        new File(outFileName).delete();
    }
    return result;
}
Also used : SessionState(org.apache.hadoop.hive.ql.session.SessionState) CliSessionState(org.apache.hadoop.hive.cli.CliSessionState) ArrayList(java.util.ArrayList) File(java.io.File)

Aggregations

SessionState (org.apache.hadoop.hive.ql.session.SessionState)96 IOException (java.io.IOException)24 HiveConf (org.apache.hadoop.hive.conf.HiveConf)19 HiveException (org.apache.hadoop.hive.ql.metadata.HiveException)13 ArrayList (java.util.ArrayList)12 LinkedList (java.util.LinkedList)11 Path (org.apache.hadoop.fs.Path)11 CliSessionState (org.apache.hadoop.hive.cli.CliSessionState)11 MetaException (org.apache.hadoop.hive.metastore.api.MetaException)10 File (java.io.File)9 FileNotFoundException (java.io.FileNotFoundException)9 Map (java.util.Map)8 Test (org.junit.Test)8 PrintStream (java.io.PrintStream)7 ExecutionException (java.util.concurrent.ExecutionException)6 FileStatus (org.apache.hadoop.fs.FileStatus)6 URI (java.net.URI)5 FileSystem (org.apache.hadoop.fs.FileSystem)5 Driver (org.apache.hadoop.hive.ql.Driver)5 SerDeException (org.apache.hadoop.hive.serde2.SerDeException)5