google-cloud-bigquery
Google BigQuery (docs) enables super-fast, SQL-like queries against append-only tables, using the processing power of Google's infrastructure. Simply move your data into BigQuery and let it handle the hard work. You can control access to both the project and your data based on your business needs, such as giving others the ability to view or query your data.
- google-cloud-bigquery API documentation
- google-cloud-bigquery on RubyGems
- Google BigQuery documentation
Quick Start
$ gem install google-cloud-bigquery
Authentication
This library uses Service Account credentials to connect to Google Cloud services. When running on Compute Engine the credentials will be discovered automatically. When running on other environments the Service Account credentials can be specified by providing the path to the JSON file, or the JSON itself, in environment variables.
Instructions and configuration options are covered in the Authentication Guide.
Example
require "google/cloud/bigquery"
bigquery = Google::Cloud::Bigquery.new
dataset = bigquery.create_dataset "my_dataset"
table = dataset.create_table "my_table" do |t|
t.name = "My Table",
t.description = "A description of my table."
t.schema do |s|
s.string "first_name", mode: :required
s.string "last_name", mode: :required
s.integer "age", mode: :required
end
end
# Load data into the table from Google Cloud Storage
table.load "gs://my-bucket/file-name.csv"
# Run a query
data = dataset.query "SELECT first_name FROM my_table"
data.each do |row|
puts row[:first_name]
end
Enabling Logging
To enable logging for this library, set the logger for the underlying Google API Client library. The logger that you set may be a Ruby stdlib Logger
as shown below, or a Google::Cloud::Logging::Logger
that will write logs to Stackdriver Logging.
If you do not set the logger explicitly and your application is running in a Rails environment, it will default to Rails.logger
. Otherwise, if you do not set the logger and you are not using Rails, logging is disabled by default.
Configuring a Ruby stdlib logger:
require "logger"
my_logger = Logger.new $stderr
my_logger.level = Logger::WARN
# Set the Google API Client logger
Google::Apis.logger = my_logger
Supported Ruby Versions
This library is supported on Ruby 2.3+.
Google provides official support for Ruby versions that are actively supported by Ruby Core—that is, Ruby versions that are either in normal maintenance or in security maintenance, and not end of life. Currently, this means Ruby 2.3 and later. Older versions of Ruby may still work, but are unsupported and not recommended. See https://www.ruby-lang.org/en/downloads/branches/ for details about the Ruby support schedule.
Versioning
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.
Contributing
Contributions to this library are always welcome and highly encouraged.
See the Contributing Guide for more information on how to get started.
Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms. See Code of Conduct for more information.
License
This library is licensed under Apache 2.0. Full license text is available in LICENSE.
Support
Please report bugs at the project on Github. Don't hesitate to ask questions about the client or APIs on StackOverflow.