{
checkNotNull(connectorId, "connectorId is null");
checkNotNull(tpchIndexSpec, "tpchIndexSpec is null");
TpchMetadata tpchMetadata = new TpchMetadata(connectorId);
TpchRecordSetProvider tpchRecordSetProvider = new TpchRecordSetProvider();
ImmutableMap.Builder<Set<TpchScaledColumn>, IndexedTable> indexedTablesBuilder = ImmutableMap.builder();
Set<TpchScaledTable> tables = tpchIndexSpec.listIndexedTables();
for (TpchScaledTable table : tables) {
SchemaTableName tableName = new SchemaTableName("sf" + table.getScaleFactor(), table.getTableName());
TpchTableHandle tableHandle = tpchMetadata.getTableHandle(null, tableName);
Map<String, ConnectorColumnHandle> columnHandles = new LinkedHashMap<>(tpchMetadata.getColumnHandles(tableHandle));
for (Set<String> columnNames : tpchIndexSpec.getColumnIndexes(table)) {
List<String> keyColumnNames = ImmutableList.copyOf(columnNames); // Finalize the key order
Set<TpchScaledColumn> keyColumns = FluentIterable.from(keyColumnNames)
.transform(TpchScaledColumn.columnFunction(table))
.toSet();
TpchTable<?> tpchTable = TpchTable.getTable(table.getTableName());
RecordSet recordSet = tpchRecordSetProvider.getRecordSet(tpchTable, ImmutableList.copyOf(columnHandles.values()), table.getScaleFactor(), 0, 1);
IndexedTable indexedTable = indexTable(recordSet, ImmutableList.copyOf(columnHandles.keySet()), keyColumnNames);
indexedTablesBuilder.put(keyColumns, indexedTable);
}
}