use of com.airbnb.spinaltap.mysql.mutation.schema.Table 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));
}
use of com.airbnb.spinaltap.mysql.mutation.schema.Table 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());
}
use of com.airbnb.spinaltap.mysql.mutation.schema.Table 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());
}
use of com.airbnb.spinaltap.mysql.mutation.schema.Table 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());
}
use of com.airbnb.spinaltap.mysql.mutation.schema.Table in project SpinalTap by airbnb.
the class MysqlKeyProvider method get.
/**
* This is currently a replication of the logic to get the partition for a Mysql table mutation in
* {@link com.airbnb.jitney.helpers.SpinaltapHelper}
*/
@Override
public String get(Mutation<?> mutation) {
Preconditions.checkState(mutation instanceof MysqlMutation);
MysqlMutation mysqlMutation = (MysqlMutation) mutation;
Table table = mysqlMutation.getMetadata().getTable();
Row row = mysqlMutation.getRow();
return String.format("%s:%s:%s", table.getDatabase(), table.getName(), row.getPrimaryKeyValue());
}
Aggregations