use of com.airbnb.spinaltap.mysql.schema.ColumnInfo in project SpinalTap by airbnb.
the class TableCache method fetchTable.
private Table fetchTable(long tableId, String databaseName, String tableName, BinlogFilePos binlogFilePos, List<ColumnDataType> columnTypes) throws Exception {
List<ColumnInfo> tableSchema = schemaStore.query(databaseName, tableName, binlogFilePos).getColumnInfo();
Iterator<ColumnInfo> schemaIterator = tableSchema.iterator();
if (tableSchema.size() != columnTypes.size()) {
log.error("Schema length {} and Column length {} don't match", tableSchema.size(), columnTypes.size());
}
List<ColumnMetadata> columnMetadata = new ArrayList<>();
for (int position = 0; position < columnTypes.size() && schemaIterator.hasNext(); position++) {
ColumnInfo colInfo = schemaIterator.next();
columnMetadata.add(new ColumnMetadata(colInfo.getName(), columnTypes.get(position), colInfo.isPrimaryKey(), position));
}
List<String> primaryColumns = tableSchema.stream().filter(ColumnInfo::isPrimaryKey).map(ColumnInfo::getName).collect(Collectors.toList());
return new Table(tableId, tableName, databaseName, columnMetadata, primaryColumns);
}
Aggregations