Search in sources :

Example 21 with BigtableDataSettings

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

the class Quickstart method quickstart.

public static void quickstart(String projectId, String instanceId, String tableId) {
    BigtableDataSettings settings = BigtableDataSettings.newBuilder().setProjectId(projectId).setInstanceId(instanceId).build();
    // the "close" method on the client to safely clean up any remaining background resources.
    try (BigtableDataClient dataClient = BigtableDataClient.create(settings)) {
        System.out.println("\nReading a single row by row key");
        Row row = dataClient.readRow(tableId, "r1");
        System.out.println("Row: " + row.getKey().toStringUtf8());
        for (RowCell cell : row.getCells()) {
            System.out.printf("Family: %s    Qualifier: %s    Value: %s%n", cell.getFamily(), cell.getQualifier().toStringUtf8(), cell.getValue().toStringUtf8());
        }
    } catch (NotFoundException e) {
        System.err.println("Failed to read from a non-existent table: " + e.getMessage());
    } catch (Exception e) {
        System.out.println("Error during quickstart: \n" + e.toString());
    }
}
Also used : RowCell(com.google.cloud.bigtable.data.v2.models.RowCell) NotFoundException(com.google.api.gax.rpc.NotFoundException) Row(com.google.cloud.bigtable.data.v2.models.Row) BigtableDataClient(com.google.cloud.bigtable.data.v2.BigtableDataClient) BigtableDataSettings(com.google.cloud.bigtable.data.v2.BigtableDataSettings) NotFoundException(com.google.api.gax.rpc.NotFoundException)

Example 22 with BigtableDataSettings

use of com.google.cloud.bigtable.data.v2.BigtableDataSettings in project native-image-support-java by GoogleCloudPlatform.

the class BigTableSampleApplication method main.

/**
 * Entrypoint to the BigTable sample application.
 */
public static void main(String[] args) throws IOException {
    String projectId = ServiceOptions.getDefaultProjectId();
    BigtableTableAdminSettings adminClientSettings = BigtableTableAdminSettings.newBuilder().setInstanceId(INSTANCE_NAME).setProjectId(projectId).build();
    BigtableDataSettings clientSettings = BigtableDataSettings.newBuilder().setInstanceId(INSTANCE_NAME).setProjectId(projectId).build();
    BigtableTableAdminClient adminClient = BigtableTableAdminClient.create(adminClientSettings);
    BigtableDataClient standardClient = BigtableDataClient.create(clientSettings);
    String tableName = TABLE_NAME + UUID.randomUUID().toString();
    createTable(adminClient, tableName);
    insertData(standardClient, tableName);
    readData(standardClient, tableName);
    // Clean up
    deleteTable(adminClient, tableName);
}
Also used : BigtableTableAdminSettings(com.google.cloud.bigtable.admin.v2.BigtableTableAdminSettings) ByteString(com.google.protobuf.ByteString) BigtableTableAdminClient(com.google.cloud.bigtable.admin.v2.BigtableTableAdminClient) BigtableDataClient(com.google.cloud.bigtable.data.v2.BigtableDataClient) BigtableDataSettings(com.google.cloud.bigtable.data.v2.BigtableDataSettings)

Aggregations

BigtableDataSettings (com.google.cloud.bigtable.data.v2.BigtableDataSettings)21 Test (org.junit.Test)12 BigtableTableAdminSettings (com.google.cloud.bigtable.admin.v2.BigtableTableAdminSettings)5 BigtableDataClient (com.google.cloud.bigtable.data.v2.BigtableDataClient)5 InstantiatingGrpcChannelProvider (com.google.api.gax.grpc.InstantiatingGrpcChannelProvider)3 EnhancedBigtableStubSettings (com.google.cloud.bigtable.data.v2.stub.EnhancedBigtableStubSettings)3 Before (org.junit.Before)3 NoCredentialsProvider (com.google.api.gax.core.NoCredentialsProvider)2 BigtableInstanceAdminClient (com.google.cloud.bigtable.admin.v2.BigtableInstanceAdminClient)2 BigtableInstanceAdminSettings (com.google.cloud.bigtable.admin.v2.BigtableInstanceAdminSettings)2 BigtableTableAdminClient (com.google.cloud.bigtable.admin.v2.BigtableTableAdminClient)2 Builder (com.google.cloud.bigtable.data.v2.BigtableDataSettings.Builder)2 Row (com.google.cloud.bigtable.data.v2.models.Row)2 ByteString (com.google.protobuf.ByteString)2 IOException (java.io.IOException)2 Ignore (org.junit.Ignore)2 ApiFunction (com.google.api.core.ApiFunction)1 BatcherImpl (com.google.api.gax.batching.BatcherImpl)1 BatchingSettings (com.google.api.gax.batching.BatchingSettings)1 FlowControlEventStats (com.google.api.gax.batching.FlowControlEventStats)1