Search in sources :

Example 6 with Row

use of com.airbnb.spinaltap.mysql.mutation.schema.Row in project SpinalTap by airbnb.

the class MysqlUpdateMutationTest method testAsColumnValues.

@Test
public void testAsColumnValues() throws Exception {
    Table table = new Table(1, "table_name", "db_name", ImmutableList.of(new ColumnMetadata("id", ColumnDataType.LONGLONG, false, 0)), ImmutableList.of());
    Row row = new Row(table, ImmutableMap.of("id", new Column(table.getColumns().get("id"), 2)));
    assertEquals(ImmutableMap.of("id", 2), MysqlUpdateMutation.asColumnValues(row));
}
Also used : ColumnMetadata(com.airbnb.spinaltap.mysql.mutation.schema.ColumnMetadata) Table(com.airbnb.spinaltap.mysql.mutation.schema.Table) Column(com.airbnb.spinaltap.mysql.mutation.schema.Column) Row(com.airbnb.spinaltap.mysql.mutation.schema.Row) Test(org.junit.Test)

Example 7 with Row

use of com.airbnb.spinaltap.mysql.mutation.schema.Row in project SpinalTap by airbnb.

the class RowTest method testSinglePrimaryKey.

@Test
public void testSinglePrimaryKey() throws Exception {
    Table table = new Table(TABLE_ID, TABLE_NAME, DB_NAME, ImmutableList.of(new ColumnMetadata(ID_COLUMN, ColumnDataType.LONGLONG, true, 0), new ColumnMetadata(NAME_COLUMN, ColumnDataType.VARCHAR, false, 1)), ImmutableList.of(ID_COLUMN));
    Row row = new Row(table, ImmutableMap.of(ID_COLUMN, new Column(table.getColumns().get(ID_COLUMN), 1), NAME_COLUMN, new Column(table.getColumns().get(NAME_COLUMN), "Bob")));
    assertEquals("1", row.getPrimaryKeyValue());
}
Also used : ColumnMetadata(com.airbnb.spinaltap.mysql.mutation.schema.ColumnMetadata) Table(com.airbnb.spinaltap.mysql.mutation.schema.Table) Column(com.airbnb.spinaltap.mysql.mutation.schema.Column) Row(com.airbnb.spinaltap.mysql.mutation.schema.Row) Test(org.junit.Test)

Example 8 with Row

use of com.airbnb.spinaltap.mysql.mutation.schema.Row in project SpinalTap by airbnb.

the class RowTest method testCompositePrimaryKey.

@Test
public void testCompositePrimaryKey() throws Exception {
    Table table = new Table(TABLE_ID, TABLE_NAME, DB_NAME, ImmutableList.of(new ColumnMetadata(ID_COLUMN, ColumnDataType.LONGLONG, true, 0), new ColumnMetadata(NAME_COLUMN, ColumnDataType.VARCHAR, true, 1)), ImmutableList.of(ID_COLUMN, NAME_COLUMN));
    Row row = new Row(table, ImmutableMap.of(ID_COLUMN, new Column(table.getColumns().get(ID_COLUMN), 1), NAME_COLUMN, new Column(table.getColumns().get(NAME_COLUMN), "Bob")));
    assertEquals("1Bob", row.getPrimaryKeyValue());
}
Also used : ColumnMetadata(com.airbnb.spinaltap.mysql.mutation.schema.ColumnMetadata) Table(com.airbnb.spinaltap.mysql.mutation.schema.Table) Column(com.airbnb.spinaltap.mysql.mutation.schema.Column) Row(com.airbnb.spinaltap.mysql.mutation.schema.Row) Test(org.junit.Test)

Example 9 with Row

use of com.airbnb.spinaltap.mysql.mutation.schema.Row in project SpinalTap by airbnb.

the class RowTest method testNullPrimaryKey.

@Test
public void testNullPrimaryKey() throws Exception {
    Table table = new Table(TABLE_ID, TABLE_NAME, DB_NAME, ImmutableList.of(new ColumnMetadata(ID_COLUMN, ColumnDataType.LONGLONG, true, 0)), ImmutableList.of(ID_COLUMN));
    Row row = new Row(table, ImmutableMap.of(ID_COLUMN, new Column(table.getColumns().get(ID_COLUMN), null)));
    assertEquals("null", row.getPrimaryKeyValue());
}
Also used : ColumnMetadata(com.airbnb.spinaltap.mysql.mutation.schema.ColumnMetadata) Table(com.airbnb.spinaltap.mysql.mutation.schema.Table) Column(com.airbnb.spinaltap.mysql.mutation.schema.Column) Row(com.airbnb.spinaltap.mysql.mutation.schema.Row) Test(org.junit.Test)

Example 10 with Row

use of com.airbnb.spinaltap.mysql.mutation.schema.Row in project SpinalTap by airbnb.

the class DeleteMutationMapper method mapEvent.

@Override
protected List<MysqlDeleteMutation> mapEvent(Table table, DeleteEvent event) {
    Collection<ColumnMetadata> cols = table.getColumns().values();
    List<MysqlDeleteMutation> mutations = new ArrayList<>();
    List<Serializable[]> rows = event.getRows();
    for (int position = 0; position < rows.size(); position++) {
        mutations.add(new MysqlDeleteMutation(createMetadata(table, event, position), new Row(table, zip(rows.get(position), cols))));
    }
    return mutations;
}
Also used : MysqlDeleteMutation(com.airbnb.spinaltap.mysql.mutation.MysqlDeleteMutation) ColumnMetadata(com.airbnb.spinaltap.mysql.mutation.schema.ColumnMetadata) ArrayList(java.util.ArrayList) Row(com.airbnb.spinaltap.mysql.mutation.schema.Row)

Aggregations

Row (com.airbnb.spinaltap.mysql.mutation.schema.Row)22 Test (org.junit.Test)17 ColumnMetadata (com.airbnb.spinaltap.mysql.mutation.schema.ColumnMetadata)9 Column (com.airbnb.spinaltap.mysql.mutation.schema.Column)8 Table (com.airbnb.spinaltap.mysql.mutation.schema.Table)7 MysqlInsertMutation (com.airbnb.spinaltap.mysql.mutation.MysqlInsertMutation)6 Serializable (java.io.Serializable)6 BinlogEvent (com.airbnb.spinaltap.mysql.event.BinlogEvent)5 MysqlDeleteMutation (com.airbnb.spinaltap.mysql.mutation.MysqlDeleteMutation)5 MysqlUpdateMutation (com.airbnb.spinaltap.mysql.mutation.MysqlUpdateMutation)4 UpdateEvent (com.airbnb.spinaltap.mysql.event.UpdateEvent)3 MysqlMutation (com.airbnb.spinaltap.mysql.mutation.MysqlMutation)3 MysqlMutationMetadata (com.airbnb.spinaltap.mysql.mutation.MysqlMutationMetadata)3 AbstractMap (java.util.AbstractMap)3 Map (java.util.Map)3 ArrayList (java.util.ArrayList)2 Mutation (com.airbnb.jitney.event.spinaltap.v1.Mutation)1 SourceState (com.airbnb.spinaltap.common.source.SourceState)1 BinlogFilePos (com.airbnb.spinaltap.mysql.BinlogFilePos)1 DataSource (com.airbnb.spinaltap.mysql.DataSource)1