This directory contains samples for google-cloud-bigtable.
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.
Authentication is typically done through Application Default Credentials , which means you do not have to change the code to authenticate as long as your environment has credentials. You have a few options for setting up authentication:
-
When running locally, use the Google Cloud SDK
gcloud auth application-default login -
When running on App Engine or Compute Engine, credentials are already set-up. However, you may need to configure your Compute Engine instance with additional scopes.
-
You can create a Service Account key file . This file can be used to authenticate to Google Cloud Platform services from any environment. To use the file, set the
GOOGLE_APPLICATION_CREDENTIALSenvironment variable to the path to the key file, for example:export GOOGLE_APPLICATION_CREDENTIALS=/path/to/service_account.json
Next, set the GOOGLE_CLOUD_PROJECT environment variable to the project name set in the Google Cloud Platform Developer Console:
`export GOOGLE_CLOUD_PROJECT="YOUR-PROJECT-ID"`
-
Install the Bundler gem.
-
Install dependencies using:
bundle install
Run the tests for these samples by running bundle exec rake test.
The Quick start sample shows a basic usage of the Cloud Bigtable client library: reading rows from a table.
Follow the cbt tutorial to install the cbt command line tool. Here are the cbt commands to create a table, column family and add some data:
cbt createtable my-table
cbt createfamily my-table cf
cbt set my-table "row-1" cf:field1=test-value
Run the quick start to read the row you just wrote using cbt:
bundle exec ruby quickstart.rb
Expected output similar to:
#<Google::Cloud::Bigtable::Row:0x007fc2fbc8ba70
@cells=
{"cf"=>
[#<Google::Cloud::Bigtable::Row::Cell:0x007fc2fbc2f1f8
@family="cf",
@labels=[],
@qualifier="field1",
@timestamp=1527522606344000,
@value="test-value">
]}
@key="row-1">
View the Hello World sample to see a basic usage of the Cloud Bigtable client library.
View the source code.
![Open in Cloud Shell][shell_img]
Usage: bundle exec ruby instanceadmin.rb --help
bundle exec ruby instanceadmin.rb <command> <instance_id> <cluster_id>
COMMANDS:
run <instance_id> <cluster_id> Creates an Instance(type: PRODUCTION) and run basic instance-operations
add-cluster <instance_id> <cluster_id> Add Cluster
del-cluster <instance_id> <cluster_id> Delete the Cluster
del-instance <instance_id> Delete the Instance
dev-instance <instance_id> Create Development Instance
Examples:
bundle exec ruby instanceadmin.rb run <instance_id> <cluster_id> Run instance operations
bundle exec ruby instanceadmin.rb dev-instance <instance_id> <cluster_id> Create Development Instance
bundle exec ruby instanceadmin.rb del-instance <instance_id> <cluster_id> Delete the Instance.
bundle exec ruby instanceadmin.rb add-cluster <instance_id> <cluster_id> Add Cluster
bundle exec ruby instanceadmin.rb del-cluster <instance_id> <cluster_id> Delete the Cluster
For more information, see https://cloud.google.com/bigtable/docs
View the source code. This sample showcases the basic table / column family operations:
- Create a table (if does not exist)
- List tables in the current project
- Retrieve table metadata
- Create column families with supported garbage collection(GC) rules
- List table column families and GC rules
- Update a column family GC rule
- Delete a column family
- Delete a table
Usage: bundle exec ruby tableadmin.rb --help
Commands:
run <instance_id> <table_id> Create a table (if does not exist) and run basic table operations
delete <instance_id> <table_id> Delete table
Examples:
bundle exec ruby tableadmin.rb run <instance_id> <table_id> Create a table (if does not exist) and run basic table operations.
bundle exec ruby tableadmin.rb delete <instance_id> <table_id> Delete a table.
For more information, see https://cloud.google.com/bigtable/docs