Giter VIP home page Giter VIP logo

bigquery-client's Introduction

BigQuery Client

Gem Version

A Ruby interface to the BigQuery API.

Installation

% gem install bigquery-client

Getting Started

require "bigquery-client"

client = BigQuery::Client.new(
  project:                "your-project-42",
  dataset:                "your_dataset",
  email:                  "[email protected]",
  private_key_path:       "/path/to/keyfile.p12",
  private_key_passphrase: "notasecret",
  auth_method:            "private_key"
)

client.sql "SELECT * FROM publicdata:samples.wikipedia LIMIT 10"

Available API methods

https://cloud.google.com/bigquery/docs/reference/v2/

Resource type Method Function Support
Tabledata insertAll insert, insert_all
Tabledata list list_tabledata
Tables list tables, list_tables
Tables get fetch_schema, fetch_table
Tables insert create_table
Tables patch patch_table
Tables update update_table
Tables delete delete_table
Jobs query sql, jobs_query
Jobs insert load
Jobs list jobs
Jobs get fetch_job
Jobs getQueryResults query_results
Datasets list datasets, list_datasets
Datasets get fetch_dataset ◻️
Datasets insert create_dataset
Datasets patch patch_dataset ◻️
Datasets update update_dataset ◻️
Datasets delete delete_dataset
Projects list projects, list_projects

Basic Usage

# insert
client.insert("your_table", nickname: "john", age: 42)

# insert multiple rows
rows = [
  { nickname: "foo", age: 43 },
  { nickname: "bar", age: 44 }
]
client.insert("your_table", rows)

# create table
schema = [
  { name: "foo", type: "timestamp" },
  { name: "bar", type: "string"    }
]
client.create_table("new_table", schema)

# sql
client.sql "SELECT * FROM your_dataset.your_table LIMIT 100"

# sql (public data)
client.sql "SELECT born_alive_alive,is_male,weight_pounds FROM publicdata:samples.natality LIMIT 3"
#=> [{"born_alive_alive"=>0, "is_male"=>true, "weight_pounds"=>8.437090766739999}, {"born_alive_alive"=>2, "is_male"=>true, "weight_pounds"=>6.8122838958}, {"born_alive_alive"=>4, "is_male"=>false, "weight_pounds"=>6.9996768185}]

# query
client.query "SELECT born_alive_alive,is_male,weight_pounds FROM publicdata:samples.natality LIMIT 3"
#=> #<struct BigQuery::ResultSet job_id="job_wNWRgrTUJKIi-IUFf9bIqe1mpU8", column_names=["born_alive_alive", "is_male", "weight_pounds"], column_types=["INTEGER", "BOOLEAN", "FLOAT"], records=[["0", "true", "8.437090766739999"], ["2", "true", "6.8122838958"], ["4", "false", "6.9996768185"]]>

# tables
client.tables
#=> ["your_table", "your_table2", "your_table3"]

# fetch schema
client.fetch_schema("your_table")
#=> [{"name"=>"nickname", "type"=>"STRING"}, {"name"=>"age", "type"=>"INTEGER"}]

# delete table
client.delete_table('your_table')

Datasets API

# No need to specify `:dataset`
client = BigQuery::Client.new(
  project:                "your-project-42",
  email:                  "[email protected]",
  private_key_path:       "/path/to/keyfile.p12",
  private_key_passphrase: "notasecret",
  auth_method:            "private_key"
)

client.datasets
#=> ["your_dataset", "your_dataset2"]

# create dataset
client.create_dataset('your_dataset')

# delete dataset
client.delete_dataset('your_dataset')

Projects API

# No need to specify `:project` and `:dataset`
client = BigQuery::Client.new(
  email:                  "[email protected]",
  private_key_path:       "/path/to/keyfile.p12",
  private_key_passphrase: "notasecret",
  auth_method:            "private_key"
)

client.projects
#=> ["your_project"]

TODO

How to run tests

Please create a file named .env on the root of this repository. You can use .env.example file as a template.

% cp .env.example .env

and edit .env file properly.

BIGQUERY_PROJECT=your-project-42
[email protected]
BIGQUERY_PRIVATE_KEY_PATH=/path/to/keyfile.p12

Then run tests.

% bundle install
% bundle exec rake

Contributing

  1. Fork it ( https://github.com/ttanimichi/bigquery-client/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am "Add some feature")
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

bigquery-client's People

Contributors

aim-hattori0407 avatar jpl avatar ttanimichi avatar yamotonalds avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

bigquery-client's Issues

query_result.rb

bigquery-clientの開発、ありがとうございます。
当方はRailsを入れていない者ですが、
以下のファイルにおいて、to_hがundefined methodでこけました。
/usr/local/share/gems/gems/bigquery-client-0.4.0/lib/bigquery-client/query_result.rb

そのため、以下のように修正したら動きましたので、ご報告いたします。

旧: [column_names, values].transpose.to_h
新: [column_names, values].transpose.inject({}){|h, x| h[x[0]] = x[1];h}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.