ColumnAccessInfo columnAccessInfo = hookContext.getQueryPlan().getColumnAccessInfo();
if (columnAccessInfo == null) {
return;
}
LogHelper console = SessionState.getConsole();
Map<String, Set<String>> tableToColumnAccessMap =
columnAccessInfo.getTableToColumnAccessMap();
// We need a new map to ensure output is always produced in the same order.
// This makes tests that use this hook deterministic.
Map<String, String> outputOrderedMap = new HashMap<String, String>();
for (Map.Entry<String, Set<String>> tableAccess : tableToColumnAccessMap.entrySet()) {
StringBuilder perTableInfo = new StringBuilder();
perTableInfo.append("Table:").append(tableAccess.getKey()).append("\n");
// Sort columns to make output deterministic
String[] columns = new String[tableAccess.getValue().size()];
tableAccess.getValue().toArray(columns);
Arrays.sort(columns);
perTableInfo.append("Columns:").append(StringUtils.join(columns, ','))
.append("\n");
outputOrderedMap.put(tableAccess.getKey(), perTableInfo.toString());
}
for (String perOperatorInfo : outputOrderedMap.values()) {
console.printError(perOperatorInfo);
}
}