Search in sources :

Example 6 with Column

use of com.google.bigtable.v2.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();
}
Also used : Column(com.google.bigtable.v2.Column) Family(com.google.bigtable.v2.Family)

Example 7 with Column

use of com.google.bigtable.v2.Column in project beam by apache.

the class BigtableWriteIT method testE2EBigtableWrite.

@Test
public void testE2EBigtableWrite() throws Exception {
    final String tableName = bigtableOptions.getInstanceName().toTableNameStr(tableId);
    final String instanceName = bigtableOptions.getInstanceName().toString();
    final int numRows = 1000;
    final List<KV<ByteString, ByteString>> testData = generateTableData(numRows);
    createEmptyTable(instanceName, tableId);
    Pipeline p = Pipeline.create(options);
    p.apply(GenerateSequence.from(0).to(numRows)).apply(ParDo.of(new DoFn<Long, KV<ByteString, Iterable<Mutation>>>() {

        @ProcessElement
        public void processElement(ProcessContext c) {
            int index = c.element().intValue();
            Iterable<Mutation> mutations = ImmutableList.of(Mutation.newBuilder().setSetCell(Mutation.SetCell.newBuilder().setValue(testData.get(index).getValue()).setFamilyName(COLUMN_FAMILY_NAME)).build());
            c.output(KV.of(testData.get(index).getKey(), mutations));
        }
    })).apply(BigtableIO.write().withBigtableOptions(bigtableOptions).withTableId(tableId));
    p.run();
    // Test number of column families and column family name equality
    Table table = getTable(tableName);
    assertThat(table.getColumnFamiliesMap().keySet(), Matchers.hasSize(1));
    assertThat(table.getColumnFamiliesMap(), Matchers.hasKey(COLUMN_FAMILY_NAME));
    // Test table data equality
    List<KV<ByteString, ByteString>> tableData = getTableData(tableName);
    assertThat(tableData, Matchers.containsInAnyOrder(testData.toArray()));
}
Also used : Table(com.google.bigtable.admin.v2.Table) ByteString(com.google.protobuf.ByteString) KV(org.apache.beam.sdk.values.KV) Mutation(com.google.bigtable.v2.Mutation) TestPipeline(org.apache.beam.sdk.testing.TestPipeline) Pipeline(org.apache.beam.sdk.Pipeline) Test(org.junit.Test)

Example 8 with Column

use of com.google.bigtable.v2.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;
    }
}
Also used : HashMap(java.util.HashMap) Builder(com.google.bigtable.v2.RowFilter.Chain.Builder) RowSet(com.google.bigtable.v2.RowSet) ReadRowsRequest(com.google.bigtable.v2.ReadRowsRequest) ByteString(com.google.protobuf.ByteString) ByteArrayByteIterator(site.ycsb.ByteArrayByteIterator) RowFilter(com.google.bigtable.v2.RowFilter) ByteIterator(site.ycsb.ByteIterator) ByteArrayByteIterator(site.ycsb.ByteArrayByteIterator) RowRange(com.google.bigtable.v2.RowRange) Column(com.google.bigtable.v2.Column) Family(com.google.bigtable.v2.Family) Row(com.google.bigtable.v2.Row) DeleteFromRow(com.google.bigtable.v2.Mutation.DeleteFromRow) ExecutionException(java.util.concurrent.ExecutionException)

Example 9 with Column

use of com.google.bigtable.v2.Column in project simple-bigtable by spotify.

the class CellsReadImplTest method testParentDataTypeToDataType.

@Test
public void testParentDataTypeToDataType() throws Exception {
    assertEquals(Lists.newArrayList(), cellsRead.parentTypeToCurrentType().apply(Optional.empty()));
    assertEquals(Lists.newArrayList(), cellsRead.parentTypeToCurrentType().apply(Optional.of(Column.getDefaultInstance())));
    final Cell cell = Cell.getDefaultInstance();
    final Column column = Column.newBuilder().addCells(cell).build();
    assertEquals(ImmutableList.of(cell), cellsRead.parentTypeToCurrentType().apply(Optional.of(column)));
}
Also used : Column(com.google.bigtable.v2.Column) Cell(com.google.bigtable.v2.Cell) Test(org.junit.Test)

Example 10 with Column

use of com.google.bigtable.v2.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);
}
Also used : Column(com.airbnb.jitney.event.spinaltap.v1.Column) ImmutableSet(com.google.common.collect.ImmutableSet) Getter(lombok.Getter) ImmutableMap(com.google.common.collect.ImmutableMap) Collection(java.util.Collection) Set(java.util.Set) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) Value(lombok.Value) List(java.util.List) Optional(com.google.common.base.Optional) Map(java.util.Map) Splitter(com.google.common.base.Splitter) Column(com.airbnb.jitney.event.spinaltap.v1.Column) Column(com.airbnb.jitney.event.spinaltap.v1.Column)

Aggregations

Column (com.google.bigtable.v2.Column)7 Family (com.google.bigtable.v2.Family)6 ExecutionException (java.util.concurrent.ExecutionException)4 Test (org.junit.Test)4 ByteString (com.google.protobuf.ByteString)3 ByteString (com.google.bigtable.repackaged.com.google.protobuf.ByteString)2 Column (com.google.bigtable.v1.Column)2 Family (com.google.bigtable.v1.Family)2 DeleteFromRow (com.google.bigtable.v1.Mutation.DeleteFromRow)2 ReadRowsRequest (com.google.bigtable.v1.ReadRowsRequest)2 Row (com.google.bigtable.v1.Row)2 RowFilter (com.google.bigtable.v1.RowFilter)2 Builder (com.google.bigtable.v1.RowFilter.Chain.Builder)2 Cell (com.google.bigtable.v2.Cell)2 DeleteFromRow (com.google.bigtable.v2.Mutation.DeleteFromRow)2 ReadRowsRequest (com.google.bigtable.v2.ReadRowsRequest)2 Row (com.google.bigtable.v2.Row)2 RowFilter (com.google.bigtable.v2.RowFilter)2 Builder (com.google.bigtable.v2.RowFilter.Chain.Builder)2 ByteArrayByteIterator (com.yahoo.ycsb.ByteArrayByteIterator)2