Java idiomatic client for Cloud Bigtable. Please note that this client is under heavy development and is not ready for production use. Please continue to use the HBase API client for production.
Note: This client is under heavy development and should not be used in production.
If you are using Maven, add this to your pom.xml file
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-bigtable</artifactId>
<version>0.60.0-alpha</version>
</dependency>
If you are using Gradle, add this to your dependencies
compile 'com.google.cloud:google-cloud-bigtable:0.60.0-alpha'
If you are using SBT, add this to your dependencies
libraryDependencies += "com.google.cloud" % "google-cloud-bigtable" % "0.60.0-alpha"
See the Authentication section in the base directory's README.
Cloud Bigtable is Google's NoSQL Big Data database service. It's the same database that powers many core Google services, including Search, Analytics, Maps, and Gmail.
Be sure to activate the Cloud Bigtable API and the Cloud Bigtable Admin API on the Developer's Console to use Cloud Bigtable from your project.
See the Bigtable client lib docs to learn how to interact with Cloud Bigtable using this Client Library.
For this tutorial, you will need a
Google Developers Console project with the Cloud Bigtable
API enabled. You will need to
enable billing to use Google Cloud Bigtable.
Follow these instructions to get your
project set up. You will also need to set up the local development environment by installing the
Google Cloud SDK and running the following commands in command line:
gcloud auth login
.
The Cloud Bigtable API is split into 3 parts: Data API, Instance Admin API and Table Admin API.
Here is a code snippet showing simple usage of the Data API. Add the following imports at the top of your file:
import com.google.cloud.bigtable.data.v2.BigtableDataClient;
import com.google.cloud.bigtable.data.v2.models.InstanceName;
import com.google.cloud.bigtable.data.v2.models.Query;
import com.google.cloud.bigtable.data.v2.models.Row;
Then, to make a query to Bigtable, use the following code:
// Instantiates a client
String projectId = "my-instance";
String instanceId = "my-database";
String tableId = "my-table";
// Create the client
BigtableDataClient dataClient = BigtableDataClient.create(
InstanceName.of(projectId, instanceId));
try {
// Query a table
Query query = Query.create(tableId)
.range("a", "z")
.limit(26);
for (Row row : dataClient.readRows(query)) {
System.out.println(row.getKey());
}
} finally {
dataClient.close();
}
The Admin APIs are similar. Here is a code snippet showing how to create a table. Add the following imports at the top of your file:
import com.google.bigtable.admin.v2.ColumnFamily;
import com.google.bigtable.admin.v2.InstanceName;
import com.google.bigtable.admin.v2.Table;
import com.google.cloud.bigtable.admin.v2.BigtableTableAdminClient;
Then, to create a table, use the following code:
String projectId = "my-instance";
String instanceId = "my-database";
BigtableTableAdminClient tableAdminClient = BigtableTableAdminClient.create();
try {
tableAdminClient.createTable(
InstanceName.of(projectId, instanceId),
"new-table-id",
Table.newBuilder()
.putColumnFamilies("my-family", ColumnFamily.getDefaultInstance())
.build()
);
} finally {
tableAdminClient.close();
}
To get help, follow the instructions in the shared Troubleshooting document.
Bigtable uses gRPC for the transport layer.
Java 7 or above is required for using this client.
This library follows Semantic Versioning.
It is currently in major version zero (0.y.z
), which means that anything may
change at any time and the public API should not be considered stable.
Contributions to this library are always welcome and highly encouraged.
See CONTRIBUTING for more information on how to get started and [DEVELOPING] for a layout of the codebase.
Apache 2.0 - See LICENSE for more information.