in automation/src/main/java/org/greenplum/pxf/automation/utils/tables/ComparisonUtils.java [121:215]
private static boolean checkColData(int colType, String dataColT1, String dataColT2, Reporter report) throws ParseException {
try {
if ((dataColT1.equals("null") && dataColT2.equals("")) || (dataColT2.equals("null") && dataColT1.equals(""))) {
return true;
}
// Hive mark for Null
if ((dataColT1.equals("\\N") && dataColT2.equals("null")) || (dataColT2.equals("\\N") && dataColT1.equals("null"))) {
return true;
}
if (dataColT1.equals(dataColT2)) {
return true;
}
// Numeric is Java's BigDecimal, using Double to convert from String and comparing int
// value
if (colType == Types.NUMERIC) {
if (Double.valueOf(dataColT1).intValue() == Double.valueOf(dataColT2).intValue()) {
return true;
}
}
if (colType == Types.INTEGER || colType == Types.BIGINT || colType == Types.SMALLINT) {
if (Long.valueOf(dataColT1).longValue() == Long.valueOf(dataColT2).longValue()) {
return true;
}
}
if (colType == Types.DOUBLE) {
if (Double.valueOf(dataColT1).doubleValue() == Double.valueOf(dataColT2).doubleValue()) {
return true;
}
}
if (colType == Types.FLOAT || colType == Types.REAL) {
if (Float.valueOf(dataColT1).floatValue() == Float.valueOf(dataColT2).floatValue()) {
return true;
}
}
if (colType == Types.BOOLEAN || colType == Types.BIT) {
String tempDataColT1 = (dataColT1.startsWith("t") ? "true" : "false");
String tempDataColT2 = (dataColT2.startsWith("t") ? "true" : "false");
if (Boolean.parseBoolean(tempDataColT1) == Boolean.parseBoolean(tempDataColT2)) {
return true;
}
}
if (colType == Types.TIMESTAMP) {
String t1FormatedTS = dataColT1.replaceAll("-", "/");
String t2FormatedTS = dataColT2.replaceAll("-", "/");
if (t1FormatedTS.contains(".")) {
t1FormatedTS = t1FormatedTS.substring(0, t1FormatedTS.indexOf("."));
}
if (t2FormatedTS.contains(".")) {
t2FormatedTS = t2FormatedTS.substring(0, t2FormatedTS.indexOf("."));
}
DateFormat dateFormater = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
if (dateFormater.parse(t1FormatedTS).getTime() == dateFormater.parse(t2FormatedTS).getTime()) {
return true;
}
}
if (colType == Types.BINARY) {
ReportUtils.report(report, ComparisonUtils.class, dataColT1);
ReportUtils.report(report, ComparisonUtils.class, Arrays.toString(dataColT1.getBytes()));
ReportUtils.report(report, ComparisonUtils.class, dataColT2);
ReportUtils.report(report, ComparisonUtils.class, Arrays.toString(dataColT2.getBytes()));
if ((Arrays.equals(dataColT1.getBytes(), dataColT2.getBytes("UTF-8"))) || (Arrays.equals(dataColT1.getBytes("UTF-8"), "?".getBytes())) || (Arrays.equals("?".getBytes(), dataColT2.getBytes()))) {
return true;
}
}
} catch (Exception e) {
ReportUtils.report(report, ComparisonUtils.class.getClass(), e.getMessage());
}
return false;
}