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;
}
Aggregations