Search in sources :

Example 46 with TableName

use of com.google.bigtable.admin.v2.TableName in project gapic-generator-java by googleapis.

the class BaseBigtableDataClientTest method checkAndMutateRowTest3.

@Test
public void checkAndMutateRowTest3() throws Exception {
    CheckAndMutateRowResponse expectedResponse = CheckAndMutateRowResponse.newBuilder().setPredicateMatched(true).build();
    mockBigtable.addResponse(expectedResponse);
    TableName tableName = TableName.of("[PROJECT]", "[INSTANCE]", "[TABLE]");
    ByteString rowKey = ByteString.EMPTY;
    RowFilter predicateFilter = RowFilter.newBuilder().build();
    List<Mutation> trueMutations = new ArrayList<>();
    List<Mutation> falseMutations = new ArrayList<>();
    String appProfileId = "appProfileId704923523";
    CheckAndMutateRowResponse actualResponse = client.checkAndMutateRow(tableName, rowKey, predicateFilter, trueMutations, falseMutations, appProfileId);
    Assert.assertEquals(expectedResponse, actualResponse);
    List<AbstractMessage> actualRequests = mockBigtable.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    CheckAndMutateRowRequest actualRequest = ((CheckAndMutateRowRequest) actualRequests.get(0));
    Assert.assertEquals(tableName.toString(), actualRequest.getTableName());
    Assert.assertEquals(rowKey, actualRequest.getRowKey());
    Assert.assertEquals(predicateFilter, actualRequest.getPredicateFilter());
    Assert.assertEquals(trueMutations, actualRequest.getTrueMutationsList());
    Assert.assertEquals(falseMutations, actualRequest.getFalseMutationsList());
    Assert.assertEquals(appProfileId, actualRequest.getAppProfileId());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : TableName(com.google.bigtable.v2.TableName) RowFilter(com.google.bigtable.v2.RowFilter) AbstractMessage(com.google.protobuf.AbstractMessage) ByteString(com.google.protobuf.ByteString) CheckAndMutateRowResponse(com.google.bigtable.v2.CheckAndMutateRowResponse) ArrayList(java.util.ArrayList) Mutation(com.google.bigtable.v2.Mutation) ByteString(com.google.protobuf.ByteString) CheckAndMutateRowRequest(com.google.bigtable.v2.CheckAndMutateRowRequest) Test(org.junit.Test)

Example 47 with TableName

use of com.google.bigtable.admin.v2.TableName in project gapic-generator-java by googleapis.

the class SyncCheckAndMutateRowTablenameBytestringRowfilterListmutationListmutation method syncCheckAndMutateRowTablenameBytestringRowfilterListmutationListmutation.

public static void syncCheckAndMutateRowTablenameBytestringRowfilterListmutationListmutation() throws Exception {
    // It may require modifications to work in your environment.
    try (BaseBigtableDataClient baseBigtableDataClient = BaseBigtableDataClient.create()) {
        TableName tableName = TableName.of("[PROJECT]", "[INSTANCE]", "[TABLE]");
        ByteString rowKey = ByteString.EMPTY;
        RowFilter predicateFilter = RowFilter.newBuilder().build();
        List<Mutation> trueMutations = new ArrayList<>();
        List<Mutation> falseMutations = new ArrayList<>();
        CheckAndMutateRowResponse response = baseBigtableDataClient.checkAndMutateRow(tableName, rowKey, predicateFilter, trueMutations, falseMutations);
    }
}
Also used : TableName(com.google.bigtable.v2.TableName) RowFilter(com.google.bigtable.v2.RowFilter) ByteString(com.google.protobuf.ByteString) ArrayList(java.util.ArrayList) CheckAndMutateRowResponse(com.google.bigtable.v2.CheckAndMutateRowResponse) Mutation(com.google.bigtable.v2.Mutation) BaseBigtableDataClient(com.google.cloud.bigtable.data.v2.BaseBigtableDataClient)

Example 48 with TableName

use of com.google.bigtable.admin.v2.TableName in project gapic-generator-java by googleapis.

the class SyncCheckAndMutateRowTablenameBytestringRowfilterListmutationListmutationString method syncCheckAndMutateRowTablenameBytestringRowfilterListmutationListmutationString.

public static void syncCheckAndMutateRowTablenameBytestringRowfilterListmutationListmutationString() throws Exception {
    // It may require modifications to work in your environment.
    try (BaseBigtableDataClient baseBigtableDataClient = BaseBigtableDataClient.create()) {
        TableName tableName = TableName.of("[PROJECT]", "[INSTANCE]", "[TABLE]");
        ByteString rowKey = ByteString.EMPTY;
        RowFilter predicateFilter = RowFilter.newBuilder().build();
        List<Mutation> trueMutations = new ArrayList<>();
        List<Mutation> falseMutations = new ArrayList<>();
        String appProfileId = "appProfileId704923523";
        CheckAndMutateRowResponse response = baseBigtableDataClient.checkAndMutateRow(tableName, rowKey, predicateFilter, trueMutations, falseMutations, appProfileId);
    }
}
Also used : TableName(com.google.bigtable.v2.TableName) RowFilter(com.google.bigtable.v2.RowFilter) ByteString(com.google.protobuf.ByteString) ArrayList(java.util.ArrayList) CheckAndMutateRowResponse(com.google.bigtable.v2.CheckAndMutateRowResponse) Mutation(com.google.bigtable.v2.Mutation) ByteString(com.google.protobuf.ByteString) BaseBigtableDataClient(com.google.cloud.bigtable.data.v2.BaseBigtableDataClient)

Example 49 with TableName

use of com.google.bigtable.admin.v2.TableName in project gapic-generator-java by googleapis.

the class SyncMutateRowTablenameBytestringListmutation method syncMutateRowTablenameBytestringListmutation.

public static void syncMutateRowTablenameBytestringListmutation() throws Exception {
    // It may require modifications to work in your environment.
    try (BaseBigtableDataClient baseBigtableDataClient = BaseBigtableDataClient.create()) {
        TableName tableName = TableName.of("[PROJECT]", "[INSTANCE]", "[TABLE]");
        ByteString rowKey = ByteString.EMPTY;
        List<Mutation> mutations = new ArrayList<>();
        MutateRowResponse response = baseBigtableDataClient.mutateRow(tableName, rowKey, mutations);
    }
}
Also used : TableName(com.google.bigtable.v2.TableName) MutateRowResponse(com.google.bigtable.v2.MutateRowResponse) ByteString(com.google.protobuf.ByteString) ArrayList(java.util.ArrayList) Mutation(com.google.bigtable.v2.Mutation) BaseBigtableDataClient(com.google.cloud.bigtable.data.v2.BaseBigtableDataClient)

Example 50 with TableName

use of com.google.bigtable.admin.v2.TableName in project java-bigquerystorage by googleapis.

the class WritePendingStream method writePendingStream.

public static void writePendingStream(String projectId, String datasetName, String tableName) throws DescriptorValidationException, InterruptedException, IOException {
    try (BigQueryWriteClient client = BigQueryWriteClient.create()) {
        // Initialize a write stream for the specified table.
        // For more information on WriteStream.Type, see:
        // https://googleapis.dev/java/google-cloud-bigquerystorage/latest/com/google/cloud/bigquery/storage/v1/WriteStream.Type.html
        WriteStream stream = WriteStream.newBuilder().setType(WriteStream.Type.PENDING).build();
        TableName parentTable = TableName.of(projectId, datasetName, tableName);
        CreateWriteStreamRequest createWriteStreamRequest = CreateWriteStreamRequest.newBuilder().setParent(parentTable.toString()).setWriteStream(stream).build();
        WriteStream writeStream = client.createWriteStream(createWriteStreamRequest);
        // https://googleapis.dev/java/google-cloud-bigquerystorage/latest/com/google/cloud/bigquery/storage/v1beta2/JsonStreamWriter.html
        try (JsonStreamWriter writer = JsonStreamWriter.newBuilder(writeStream.getName(), writeStream.getTableSchema()).build()) {
            // Write two batches to the stream, each with 10 JSON records.
            for (int i = 0; i < 2; i++) {
                // Create a JSON object that is compatible with the table schema.
                JSONArray jsonArr = new JSONArray();
                for (int j = 0; j < 10; j++) {
                    JSONObject record = new JSONObject();
                    record.put("col1", String.format("batch-record %03d-%03d", i, j));
                    jsonArr.put(record);
                }
                ApiFuture<AppendRowsResponse> future = writer.append(jsonArr);
                AppendRowsResponse response = future.get();
            }
            FinalizeWriteStreamResponse finalizeResponse = client.finalizeWriteStream(writeStream.getName());
            System.out.println("Rows written: " + finalizeResponse.getRowCount());
        }
        // Commit the streams.
        BatchCommitWriteStreamsRequest commitRequest = BatchCommitWriteStreamsRequest.newBuilder().setParent(parentTable.toString()).addWriteStreams(writeStream.getName()).build();
        BatchCommitWriteStreamsResponse commitResponse = client.batchCommitWriteStreams(commitRequest);
        // If the response does not have a commit time, it means the commit operation failed.
        if (commitResponse.hasCommitTime() == false) {
            for (StorageError err : commitResponse.getStreamErrorsList()) {
                System.out.println(err.getErrorMessage());
            }
            throw new RuntimeException("Error committing the streams");
        }
        System.out.println("Appended and committed records successfully.");
    } catch (ExecutionException e) {
        // If the wrapped exception is a StatusRuntimeException, check the state of the operation.
        // If the state is INTERNAL, CANCELLED, or ABORTED, you can retry. For more information, see:
        // https://grpc.github.io/grpc-java/javadoc/io/grpc/StatusRuntimeException.html
        System.out.println(e);
    }
}
Also used : FinalizeWriteStreamResponse(com.google.cloud.bigquery.storage.v1.FinalizeWriteStreamResponse) BatchCommitWriteStreamsRequest(com.google.cloud.bigquery.storage.v1.BatchCommitWriteStreamsRequest) JSONArray(org.json.JSONArray) AppendRowsResponse(com.google.cloud.bigquery.storage.v1.AppendRowsResponse) WriteStream(com.google.cloud.bigquery.storage.v1.WriteStream) BigQueryWriteClient(com.google.cloud.bigquery.storage.v1.BigQueryWriteClient) TableName(com.google.cloud.bigquery.storage.v1.TableName) CreateWriteStreamRequest(com.google.cloud.bigquery.storage.v1.CreateWriteStreamRequest) BatchCommitWriteStreamsResponse(com.google.cloud.bigquery.storage.v1.BatchCommitWriteStreamsResponse) JSONObject(org.json.JSONObject) StorageError(com.google.cloud.bigquery.storage.v1.StorageError) ExecutionException(java.util.concurrent.ExecutionException) JsonStreamWriter(com.google.cloud.bigquery.storage.v1.JsonStreamWriter)

Aggregations

Test (org.junit.Test)36 ByteString (com.google.protobuf.ByteString)31 ArrayList (java.util.ArrayList)20 TableName (com.google.bigtable.v2.TableName)18 TableName (com.google.bigtable.admin.v2.TableName)17 InvalidArgumentException (com.google.api.gax.rpc.InvalidArgumentException)13 Mutation (com.google.bigtable.v2.Mutation)13 AbstractMessage (com.google.protobuf.AbstractMessage)13 StatusRuntimeException (io.grpc.StatusRuntimeException)13 JSONArray (org.json.JSONArray)9 JSONObject (org.json.JSONObject)9 ExecutionException (java.util.concurrent.ExecutionException)8 TableName (com.google.cloud.bigquery.storage.v1.TableName)7 ReadModifyWriteRule (com.google.bigtable.v2.ReadModifyWriteRule)6 RowFilter (com.google.bigtable.v2.RowFilter)6 BaseBigtableDataClient (com.google.cloud.bigtable.data.v2.BaseBigtableDataClient)6 ColumnFamily (com.google.bigtable.admin.v2.ColumnFamily)5 Table (com.google.bigtable.admin.v2.Table)4 CheckAndMutateRowResponse (com.google.bigtable.v2.CheckAndMutateRowResponse)4 ReadModifyWriteRowResponse (com.google.bigtable.v2.ReadModifyWriteRowResponse)4