Search in sources :

Example 16 with Row

use of com.google.cloud.bigtable.data.v2.models.Row in project java-bigtable by googleapis.

the class MutateRowIT method test.

@Test
public void test() throws Exception {
    String rowKey = UUID.randomUUID().toString();
    String familyId = testEnvRule.env().getFamilyId();
    testEnvRule.env().getDataClient().mutateRowAsync(RowMutation.create(testEnvRule.env().getTableId(), rowKey).setCell(familyId, "q", "myVal").setCell(familyId, "q2", "myVal2").setCell(familyId, "q3", "myVal3").setCell(familyId, "q4", 0x12345678)).get(1, TimeUnit.MINUTES);
    testEnvRule.env().getDataClient().mutateRowAsync(RowMutation.create(testEnvRule.env().getTableId(), rowKey).deleteCells(familyId, "q2")).get(1, TimeUnit.MINUTES);
    Row row = testEnvRule.env().getDataClient().readRowsCallable().first().call(Query.create(testEnvRule.env().getTableId()).rowKey(rowKey));
    assertThat(row.getCells()).hasSize(3);
    assertThat(row.getCells().get(0).getValue()).isEqualTo(ByteString.copyFromUtf8("myVal"));
    assertThat(row.getCells().get(1).getValue()).isEqualTo(ByteString.copyFromUtf8("myVal3"));
    assertThat(row.getCells().get(2).getValue()).isEqualTo(ByteString.copyFrom(new byte[] { 0, 0, 0, 0, 0x12, 0x34, 0x56, 0x78 }));
}
Also used : ByteString(com.google.protobuf.ByteString) Row(com.google.cloud.bigtable.data.v2.models.Row) Test(org.junit.Test)

Example 17 with Row

use of com.google.cloud.bigtable.data.v2.models.Row in project java-bigtable by googleapis.

the class ReadRowsMergingAcceptanceTest method test.

@Test
public void test() throws Exception {
    List<ReadRowsResponse> responses = Lists.newArrayList();
    // Convert the chunks into a single ReadRowsResponse
    for (CellChunk chunk : testCase.getChunksList()) {
        ReadRowsResponse.Builder responseBuilder = ReadRowsResponse.newBuilder();
        responseBuilder.addChunks(chunk);
        responses.add(responseBuilder.build());
    }
    // Wrap the responses in a callable
    ServerStreamingCallable<ReadRowsRequest, ReadRowsResponse> source = new ServerStreamingStashCallable<>(responses);
    RowMergingCallable<Row> mergingCallable = new RowMergingCallable<>(source, new DefaultRowAdapter());
    // Invoke the callable to get the merged rows
    ServerStream<Row> stream = mergingCallable.call(ReadRowsRequest.getDefaultInstance());
    // Read all of the rows and transform them into logical cells
    List<ReadRowsTest.Result> actualResults = Lists.newArrayList();
    Exception error = null;
    try {
        for (Row row : stream) {
            for (RowCell cell : row.getCells()) {
                actualResults.add(ReadRowsTest.Result.newBuilder().setRowKeyBytes(row.getKey()).setFamilyName(cell.getFamily()).setQualifierBytes(cell.getQualifier()).setTimestampMicros(cell.getTimestamp()).setValueBytes(cell.getValue()).setLabel(cell.getLabels().isEmpty() ? "" : cell.getLabels().get(0)).build());
            }
        }
    } catch (Exception e) {
        error = e;
    }
    // Verify the results
    if (expectsError(testCase)) {
        assertThat(error).isNotNull();
    } else {
        if (error != null) {
            throw error;
        }
    }
    assertThat(getNonExceptionResults(testCase)).isEqualTo(actualResults);
}
Also used : CellChunk(com.google.bigtable.v2.ReadRowsResponse.CellChunk) ServerStreamingStashCallable(com.google.cloud.bigtable.gaxx.testing.FakeStreamingApi.ServerStreamingStashCallable) RowCell(com.google.cloud.bigtable.data.v2.models.RowCell) ReadRowsRequest(com.google.bigtable.v2.ReadRowsRequest) IOException(java.io.IOException) DefaultRowAdapter(com.google.cloud.bigtable.data.v2.models.DefaultRowAdapter) ReadRowsResponse(com.google.bigtable.v2.ReadRowsResponse) Row(com.google.cloud.bigtable.data.v2.models.Row) ReadRowsTest(com.google.cloud.conformance.bigtable.v2.TestDefinition.ReadRowsTest) Test(org.junit.Test)

Example 18 with Row

use of com.google.cloud.bigtable.data.v2.models.Row in project java-bigtable by googleapis.

the class ReadRowsRetryTest method getResults.

private List<String> getResults(Query query) {
    ServerStream<Row> actualRows = client.readRows(query);
    List<String> actualValues = Lists.newArrayList();
    for (Row row : actualRows) {
        actualValues.add(row.getKey().toStringUtf8());
    }
    return actualValues;
}
Also used : Row(com.google.cloud.bigtable.data.v2.models.Row) ByteString(com.google.protobuf.ByteString)

Example 19 with Row

use of com.google.cloud.bigtable.data.v2.models.Row in project java-bigtable by googleapis.

the class RowMergingCallableTest method scanMarker.

@Test
public void scanMarker() {
    FakeStreamingApi.ServerStreamingStashCallable<ReadRowsRequest, ReadRowsResponse> inner = new ServerStreamingStashCallable<>(Lists.newArrayList(// send a scan marker
    ReadRowsResponse.newBuilder().setLastScannedRowKey(ByteString.copyFromUtf8("key1")).build()));
    RowMergingCallable<Row> rowMergingCallable = new RowMergingCallable<>(inner, new DefaultRowAdapter());
    List<Row> results = rowMergingCallable.all().call(ReadRowsRequest.getDefaultInstance());
    Truth.assertThat(results).containsExactly(Row.create(ByteString.copyFromUtf8("key1"), Lists.<RowCell>newArrayList()));
}
Also used : FakeStreamingApi(com.google.cloud.bigtable.gaxx.testing.FakeStreamingApi) ReadRowsResponse(com.google.bigtable.v2.ReadRowsResponse) ServerStreamingStashCallable(com.google.cloud.bigtable.gaxx.testing.FakeStreamingApi.ServerStreamingStashCallable) RowCell(com.google.cloud.bigtable.data.v2.models.RowCell) ReadRowsRequest(com.google.bigtable.v2.ReadRowsRequest) Row(com.google.cloud.bigtable.data.v2.models.Row) DefaultRowAdapter(com.google.cloud.bigtable.data.v2.models.DefaultRowAdapter) Test(org.junit.Test)

Example 20 with Row

use of com.google.cloud.bigtable.data.v2.models.Row in project java-bigtable by googleapis.

the class RowMergingCallableTest method invalidMarkerInCell.

@Test
public void invalidMarkerInCell() {
    FakeStreamingApi.ServerStreamingStashCallable<ReadRowsRequest, ReadRowsResponse> inner = new ServerStreamingStashCallable<>(Lists.newArrayList(ReadRowsResponse.newBuilder().addChunks(CellChunk.newBuilder().setRowKey(ByteString.copyFromUtf8("key1")).setFamilyName(StringValue.newBuilder().setValue("family")).setQualifier(BytesValue.newBuilder().setValue(ByteString.EMPTY)).setTimestampMicros(1_000).setValue(ByteString.copyFromUtf8("a")).setValueSize(2)).build(), // send a scan marker
    ReadRowsResponse.newBuilder().setLastScannedRowKey(ByteString.copyFromUtf8("key1")).build(), // finish the cell & row
    ReadRowsResponse.newBuilder().addChunks(CellChunk.newBuilder().setValue(ByteString.copyFromUtf8("b")).setValueSize(0).setCommitRow(true)).build()));
    RowMergingCallable<Row> rowMergingCallable = new RowMergingCallable<>(inner, new DefaultRowAdapter());
    Throwable actualError = null;
    try {
        rowMergingCallable.all().call(ReadRowsRequest.getDefaultInstance());
    } catch (Throwable t) {
        actualError = t;
    }
    Truth.assertThat(actualError).isInstanceOf(IllegalStateException.class);
}
Also used : FakeStreamingApi(com.google.cloud.bigtable.gaxx.testing.FakeStreamingApi) ReadRowsResponse(com.google.bigtable.v2.ReadRowsResponse) ServerStreamingStashCallable(com.google.cloud.bigtable.gaxx.testing.FakeStreamingApi.ServerStreamingStashCallable) ReadRowsRequest(com.google.bigtable.v2.ReadRowsRequest) Row(com.google.cloud.bigtable.data.v2.models.Row) DefaultRowAdapter(com.google.cloud.bigtable.data.v2.models.DefaultRowAdapter) Test(org.junit.Test)

Aggregations

Row (com.google.cloud.bigtable.data.v2.models.Row)61 Test (org.junit.Test)51 Query (com.google.cloud.bigtable.data.v2.models.Query)29 ByteString (com.google.protobuf.ByteString)26 BigtableDataClient (com.google.cloud.bigtable.data.v2.BigtableDataClient)19 RowCell (com.google.cloud.bigtable.data.v2.models.RowCell)17 ReadModifyWriteRow (com.google.cloud.bigtable.data.v2.models.ReadModifyWriteRow)16 ReadRowsRequest (com.google.bigtable.v2.ReadRowsRequest)12 IOException (java.io.IOException)10 RowMutation (com.google.cloud.bigtable.data.v2.models.RowMutation)9 Filter (com.google.cloud.bigtable.data.v2.models.Filters.Filter)7 ServerStreamingStashCallable (com.google.cloud.bigtable.gaxx.testing.FakeStreamingApi.ServerStreamingStashCallable)7 Put (org.apache.hadoop.hbase.client.Put)7 DefaultRowAdapter (com.google.cloud.bigtable.data.v2.models.DefaultRowAdapter)6 MutateRowRequest (com.google.bigtable.v2.MutateRowRequest)5 Mutation (com.google.bigtable.v2.Mutation)5 SetCell (com.google.bigtable.v2.Mutation.SetCell)5 NotFoundException (com.google.api.gax.rpc.NotFoundException)4 ConditionalRowMutation (com.google.cloud.bigtable.data.v2.models.ConditionalRowMutation)4 RowMutationEntry (com.google.cloud.bigtable.data.v2.models.RowMutationEntry)4