Search in sources :

Example 11 with ColumnMetadata

use of com.airbnb.spinaltap.mysql.mutation.schema.ColumnMetadata 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)11 Row (com.airbnb.spinaltap.mysql.mutation.schema.Row)9 Column (com.airbnb.spinaltap.mysql.mutation.schema.Column)7 Table (com.airbnb.spinaltap.mysql.mutation.schema.Table)7 Test (org.junit.Test)5 MysqlDeleteMutation (com.airbnb.spinaltap.mysql.mutation.MysqlDeleteMutation)3 MysqlInsertMutation (com.airbnb.spinaltap.mysql.mutation.MysqlInsertMutation)3 ArrayList (java.util.ArrayList)3 MysqlMutation (com.airbnb.spinaltap.mysql.mutation.MysqlMutation)2 MysqlMutationMetadata (com.airbnb.spinaltap.mysql.mutation.MysqlMutationMetadata)2 MysqlUpdateMutation (com.airbnb.spinaltap.mysql.mutation.MysqlUpdateMutation)2 Mutation (com.airbnb.jitney.event.spinaltap.v1.Mutation)1 BinlogFilePos (com.airbnb.spinaltap.mysql.BinlogFilePos)1 DataSource (com.airbnb.spinaltap.mysql.DataSource)1 ColumnInfo (com.airbnb.spinaltap.mysql.schema.ColumnInfo)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 Serializable (java.io.Serializable)1