in automation/src/main/java/org/greenplum/pxf/automation/utils/tables/ComparisonUtils.java [368:471]
public static boolean comparePsqlDescribeHive(String psqlOutput,
List<HiveTable> hiveTables) throws Exception {
boolean isEquals = true;
int totalFieldsNum = 0;
// clean up
psqlOutput = psqlOutput.replaceAll("\\r\\n\\r", "");
psqlOutput = psqlOutput.replaceAll("\\n\\r", "\r\n");
String psqlLines[] = psqlOutput.split("\\r?\\n");
Collections.sort(hiveTables, new Comparator<HiveTable>() {
public int compare(HiveTable table1, HiveTable table2) {
int compareSchemas;
// compare schema names
compareSchemas = (table1.getSchema() == null ? "default"
: table1.getSchema())
.compareTo(table2.getSchema() == null ? "default"
: table2.getSchema());
if (compareSchemas != 0)
return compareSchemas;
// compare table names
return table1.getName().compareTo(table2.getName());
}
});
// skip table's and command header
int i = PSQL_DESCRIBE_HEADER_OFFSET + PSQL_DESCRIBE_HEADER_TABLE_OFFSET;
for (HiveTable hiveTable : hiveTables) {
if (i >= psqlLines.length) {
ReportUtils.report(null, ComparisonUtils.class,
"Psql output has less tables than expected.");
isEquals = false;
break;
}
for (String field : hiveTable.getFields()) {
String hiveColumnName;
String hiveColumnType;
try {
hiveColumnName = field.substring(0, field.indexOf(' ')).trim();
hiveColumnType = field.substring(field.indexOf(' ') + 1).trim();
} catch (Exception e) {
ReportUtils.report(null, ComparisonUtils.class,
e.getMessage(), Reporter.FAIL);
ReportUtils.report(null, ComparisonUtils.class,
"Cannot parse expected field type, field definition - "
+ field);
isEquals = false;
break;
}
if (!psqlLines[i].contains("|")) {
ReportUtils.report(null, ComparisonUtils.class,
"Cannot parse field from psql output - "
+ psqlLines[i]);
isEquals = false;
break;
}
String[] psqlNameAndType = psqlLines[i].split("\\|");
psqlNameAndType[0] = psqlNameAndType[0].trim();
psqlNameAndType[1] = psqlNameAndType[1].trim();
isEquals = psqlNameAndType[0].equals(hiveColumnName)
&& psqlNameAndType[1]
.equals(EnumHiveToGpdbType.getGpdbType(hiveColumnType));
if (!isEquals) {
ReportUtils.report(null, ComparisonUtils.class, "Expected column: "
+ hiveColumnName + " " + hiveColumnType
+ ", actual column in psql output: "
+ psqlNameAndType[0] + " " + psqlNameAndType[1]);
break;
}
i++;
totalFieldsNum++;
}
// skip header
i += PSQL_DESCRIBE_HEADER_TABLE_OFFSET;
}
if ((isEquals && PSQL_DESCRIBE_HEADER_OFFSET + hiveTables.size()
* PSQL_DESCRIBE_HEADER_TABLE_OFFSET + totalFieldsNum
+ PSQL_DESCRIBE_FOOTER_OFFSET != psqlLines.length)
|| hiveTables.size() == 0 && psqlLines.length != 0) {
ReportUtils.report(null, ComparisonUtils.class,
"Psql output has more output than expected.");
isEquals = false;
}
return isEquals;
}