Search in sources :

Example 1 with ColumnInfo

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);
}
Also used : ColumnMetadata(com.airbnb.spinaltap.mysql.mutation.schema.ColumnMetadata) Table(com.airbnb.spinaltap.mysql.mutation.schema.Table) ArrayList(java.util.ArrayList) ColumnInfo(com.airbnb.spinaltap.mysql.schema.ColumnInfo)

Aggregations

ColumnMetadata (com.airbnb.spinaltap.mysql.mutation.schema.ColumnMetadata)1 Table (com.airbnb.spinaltap.mysql.mutation.schema.Table)1 ColumnInfo (com.airbnb.spinaltap.mysql.schema.ColumnInfo)1 ArrayList (java.util.ArrayList)1