use of com.airbnb.jitney.event.spinaltap.v1.Column in project beam by apache.
the class BigtableTableTestUtils method bigTableRow.
static com.google.bigtable.v2.Row bigTableRow() {
List<Column> columns = ImmutableList.of(column("boolColumn", booleanToByteArray(true)), column("doubleColumn", doubleToByteArray(5.5)), column("longColumn", Longs.toByteArray(10L)), column("stringColumn", "stringValue".getBytes(UTF_8)));
Family family = Family.newBuilder().setName("familyTest").addAllColumns(columns).build();
return com.google.bigtable.v2.Row.newBuilder().setKey(byteStringUtf8("key")).addFamilies(family).build();
}
use of com.airbnb.jitney.event.spinaltap.v1.Column in project YCSB by brianfrankcooper.
the class GoogleBigtableClient method scan.
@Override
public Status scan(String table, String startkey, int recordcount, Set<String> fields, Vector<HashMap<String, ByteIterator>> result) {
setTable(table);
RowFilter filter = RowFilter.newBuilder().setFamilyNameRegexFilterBytes(ByteStringer.wrap(columnFamilyBytes)).build();
if (fields != null && fields.size() > 0) {
Builder filterChain = RowFilter.Chain.newBuilder();
filterChain.addFilters(filter);
filterChain.addFilters(RowFilter.newBuilder().setCellsPerColumnLimitFilter(1).build());
int count = 0;
// usually "field#" so pre-alloc
final StringBuilder regex = new StringBuilder(fields.size() * 6);
for (final String field : fields) {
if (count++ > 0) {
regex.append("|");
}
regex.append(field);
}
filterChain.addFilters(RowFilter.newBuilder().setColumnQualifierRegexFilter(ByteStringer.wrap(regex.toString().getBytes()))).build();
filter = RowFilter.newBuilder().setChain(filterChain.build()).build();
}
final RowRange range = RowRange.newBuilder().setStartKeyClosed(ByteStringer.wrap(startkey.getBytes())).build();
final RowSet rowSet = RowSet.newBuilder().addRowRanges(range).build();
final ReadRowsRequest.Builder rrr = ReadRowsRequest.newBuilder().setTableNameBytes(ByteStringer.wrap(lastTableBytes)).setFilter(filter).setRows(rowSet);
List<Row> rows;
try {
rows = client.readRowsAsync(rrr.build()).get();
if (rows == null || rows.isEmpty()) {
return Status.NOT_FOUND;
}
int numResults = 0;
for (final Row row : rows) {
final HashMap<String, ByteIterator> rowResult = new HashMap<String, ByteIterator>(fields != null ? fields.size() : 10);
for (final Family family : row.getFamiliesList()) {
if (Arrays.equals(family.getNameBytes().toByteArray(), columnFamilyBytes)) {
for (final Column column : family.getColumnsList()) {
// we should only have a single cell per column
rowResult.put(column.getQualifier().toString(UTF8_CHARSET), new ByteArrayByteIterator(column.getCells(0).getValue().toByteArray()));
if (debug) {
System.out.println("Result for field: " + column.getQualifier().toString(UTF8_CHARSET) + " is: " + column.getCells(0).getValue().toString(UTF8_CHARSET));
}
}
}
}
result.add(rowResult);
numResults++;
if (numResults >= recordcount) {
// if hit recordcount, bail out
break;
}
}
return Status.OK;
} catch (InterruptedException e) {
System.err.println("Interrupted during scan: " + e);
Thread.currentThread().interrupt();
return Status.ERROR;
} catch (ExecutionException e) {
System.err.println("Exception during scan: " + e);
return Status.ERROR;
}
}
use of com.airbnb.jitney.event.spinaltap.v1.Column in project YCSB by brianfrankcooper.
the class GoogleBigtableClient method read.
@Override
public Status read(String table, String key, Set<String> fields, Map<String, ByteIterator> result) {
if (debug) {
System.out.println("Doing read from Bigtable columnfamily " + new String(columnFamilyBytes));
System.out.println("Doing read for key: " + key);
}
setTable(table);
RowFilter filter = RowFilter.newBuilder().setFamilyNameRegexFilterBytes(ByteStringer.wrap(columnFamilyBytes)).build();
if (fields != null && fields.size() > 0) {
Builder filterChain = RowFilter.Chain.newBuilder();
filterChain.addFilters(filter);
filterChain.addFilters(RowFilter.newBuilder().setCellsPerColumnLimitFilter(1).build());
int count = 0;
// usually "field#" so pre-alloc
final StringBuilder regex = new StringBuilder(fields.size() * 6);
for (final String field : fields) {
if (count++ > 0) {
regex.append("|");
}
regex.append(field);
}
filterChain.addFilters(RowFilter.newBuilder().setColumnQualifierRegexFilter(ByteStringer.wrap(regex.toString().getBytes()))).build();
filter = RowFilter.newBuilder().setChain(filterChain.build()).build();
}
final ReadRowsRequest.Builder rrr = ReadRowsRequest.newBuilder().setTableNameBytes(ByteStringer.wrap(lastTableBytes)).setFilter(filter).setRows(RowSet.newBuilder().addRowKeys(ByteStringer.wrap(key.getBytes())));
List<Row> rows;
try {
rows = client.readRowsAsync(rrr.build()).get();
if (rows == null || rows.isEmpty()) {
return Status.NOT_FOUND;
}
for (final Row row : rows) {
for (final Family family : row.getFamiliesList()) {
if (Arrays.equals(family.getNameBytes().toByteArray(), columnFamilyBytes)) {
for (final Column column : family.getColumnsList()) {
// we should only have a single cell per column
result.put(column.getQualifier().toString(UTF8_CHARSET), new ByteArrayByteIterator(column.getCells(0).getValue().toByteArray()));
if (debug) {
System.out.println("Result for field: " + column.getQualifier().toString(UTF8_CHARSET) + " is: " + column.getCells(0).getValue().toString(UTF8_CHARSET));
}
}
}
}
}
return Status.OK;
} catch (InterruptedException e) {
System.err.println("Interrupted during get: " + e);
Thread.currentThread().interrupt();
return Status.ERROR;
} catch (ExecutionException e) {
System.err.println("Exception during get: " + e);
return Status.ERROR;
}
}
use of com.airbnb.jitney.event.spinaltap.v1.Column in project SpinalTap by airbnb.
the class KafkaDestinationTest method createMutation.
private Mutation createMutation(MutationType type) {
Mapper<com.airbnb.spinaltap.Mutation<?>, ? extends TBase<?, ?>> thriftMutationMapper = ThriftMutationMapper.create("spinaltap");
Table table = new Table(0L, TABLE, DATABASE, ImmutableList.of(new ColumnMetadata("id", ColumnDataType.LONGLONG, true, 0)), ImmutableList.of("id"));
MysqlMutationMetadata metadata = new MysqlMutationMetadata(new DataSource(HOSTNAME, 0, "service"), new BinlogFilePos(), table, 0L, 0L, 0L, null, null, 0L, 0);
Row row = new Row(table, ImmutableMap.of("id", new Column(new ColumnMetadata("id", ColumnDataType.LONGLONG, true, 0), 1L)));
MysqlMutation mutation;
switch(type) {
case INSERT:
mutation = new MysqlInsertMutation(metadata, row);
break;
case UPDATE:
mutation = new MysqlUpdateMutation(metadata, row, row);
break;
case DELETE:
mutation = new MysqlDeleteMutation(metadata, row);
break;
default:
mutation = null;
}
return (Mutation) (thriftMutationMapper.map(mutation));
}
use of com.airbnb.jitney.event.spinaltap.v1.Column in project SpinalTap by airbnb.
the class Table method toThriftTable.
public static com.airbnb.jitney.event.spinaltap.v1.Table toThriftTable(Table table) {
Set<String> primaryKey = ImmutableSet.of();
if (table.getPrimaryKey().isPresent()) {
primaryKey = ImmutableSet.copyOf(table.getPrimaryKey().get().getColumns().values().stream().map(ColumnMetadata::getName).sorted().collect(Collectors.toList()));
}
Map<String, Column> columns = table.getColumns().values().stream().map(c -> {
com.airbnb.jitney.event.spinaltap.v1.Column column = new com.airbnb.jitney.event.spinaltap.v1.Column(c.getColType().getCode(), c.isPrimaryKey(), c.getName());
column.setPosition(c.getPosition());
return column;
}).collect(Collectors.toMap(c -> c.getName(), c -> c));
return new com.airbnb.jitney.event.spinaltap.v1.Table(table.getId(), table.getName(), table.getDatabase(), primaryKey, columns);
}
Aggregations