Skip to content

Commit 5ca03fb

Browse files
author
remi Taylor
authored
Merge pull request #53 from GoogleCloudPlatform/bigquery
Ruby Samples for Google Cloud BigQuery (updated to use google-cloud-bigquery)
2 parents dc77533 + a943d34 commit 5ca03fb

10 files changed

Lines changed: 851 additions & 121 deletions

File tree

bigquery/Gemfile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2015 Google, Inc
1+
# Copyright 2016 Google, Inc
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.
@@ -14,10 +14,11 @@
1414

1515
source "https://rubygems.org"
1616

17-
gem "gcloud"
17+
gem "google-cloud-bigquery"
1818

1919
group :test do
2020
gem "rake"
2121
gem "rubocop"
2222
gem "rspec"
23+
gem "google-cloud-storage"
2324
end

bigquery/Gemfile.lock

Lines changed: 59 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -1,111 +1,96 @@
11
GEM
22
remote: https://rubygems.org/
33
specs:
4-
activesupport (4.2.4)
5-
i18n (~> 0.7)
6-
json (~> 1.7, >= 1.7.7)
7-
minitest (~> 5.1)
8-
thread_safe (~> 0.3, >= 0.3.4)
9-
tzinfo (~> 1.1)
10-
addressable (2.3.8)
11-
ast (2.1.0)
12-
astrolabe (1.3.1)
13-
parser (~> 2.2)
14-
autoparse (0.3.3)
15-
addressable (>= 2.3.1)
16-
extlib (>= 0.9.15)
17-
multi_json (>= 1.0.0)
18-
beefcake (1.1.0)
4+
addressable (2.4.0)
5+
ast (2.3.0)
196
diff-lcs (1.2.5)
207
digest-crc (0.4.1)
21-
extlib (0.9.16)
228
faraday (0.9.2)
239
multipart-post (>= 1.2, < 3)
24-
gcloud (0.5.0)
25-
beefcake (~> 1.0)
26-
digest-crc (~> 0.4)
27-
google-api-client (~> 0.8.3)
28-
mime-types (~> 2.4)
29-
zonefile (~> 1.04)
30-
google-api-client (0.8.6)
31-
activesupport (>= 3.2)
10+
google-api-client (0.9.13)
3211
addressable (~> 2.3)
33-
autoparse (~> 0.3)
34-
extlib (~> 0.9)
35-
faraday (~> 0.9)
36-
googleauth (~> 0.3)
37-
launchy (~> 2.4)
38-
multi_json (~> 1.10)
39-
retriable (~> 1.4)
40-
signet (~> 0.6)
41-
googleauth (0.4.2)
12+
googleauth (~> 0.5)
13+
httpclient (~> 2.7)
14+
hurley (~> 0.1)
15+
memoist (~> 0.11)
16+
mime-types (>= 1.6)
17+
representable (~> 2.3.0)
18+
retriable (~> 2.0)
19+
google-cloud-bigquery (0.20.1)
20+
google-api-client (~> 0.9.11)
21+
google-cloud-core (~> 0.20.0)
22+
google-cloud-core (0.20.1)
23+
google-cloud-storage (0.20.0)
24+
digest-crc (~> 0.4)
25+
google-api-client (~> 0.9.11)
26+
google-cloud-core (~> 0.20.0)
27+
googleauth (0.5.1)
4228
faraday (~> 0.9)
4329
jwt (~> 1.4)
4430
logging (~> 2.0)
4531
memoist (~> 0.12)
4632
multi_json (~> 1.11)
47-
signet (~> 0.6)
48-
i18n (0.7.0)
49-
json (1.8.3)
50-
jwt (1.5.2)
51-
launchy (2.4.3)
52-
addressable (~> 2.3)
33+
os (~> 0.9)
34+
signet (~> 0.7)
35+
httpclient (2.8.2.3)
36+
hurley (0.2)
37+
jwt (1.5.4)
5338
little-plugger (1.1.4)
54-
logging (2.0.0)
39+
logging (2.1.0)
5540
little-plugger (~> 1.1)
5641
multi_json (~> 1.10)
57-
memoist (0.12.0)
58-
mime-types (2.6.2)
59-
minitest (5.8.2)
60-
multi_json (1.11.2)
42+
memoist (0.15.0)
43+
mime-types (3.1)
44+
mime-types-data (~> 3.2015)
45+
mime-types-data (3.2016.0521)
46+
multi_json (1.12.1)
6147
multipart-post (2.0.0)
62-
parser (2.2.3.0)
63-
ast (>= 1.1, < 3.0)
48+
os (0.9.6)
49+
parser (2.3.1.2)
50+
ast (~> 2.2)
6451
powerpack (0.1.1)
65-
rainbow (2.0.0)
66-
rake (10.4.2)
67-
retriable (1.4.1)
68-
rspec (3.3.0)
69-
rspec-core (~> 3.3.0)
70-
rspec-expectations (~> 3.3.0)
71-
rspec-mocks (~> 3.3.0)
72-
rspec-core (3.3.2)
73-
rspec-support (~> 3.3.0)
74-
rspec-expectations (3.3.1)
52+
rainbow (2.1.0)
53+
rake (11.1.2)
54+
representable (2.3.0)
55+
uber (~> 0.0.7)
56+
retriable (2.1.0)
57+
rspec (3.4.0)
58+
rspec-core (~> 3.4.0)
59+
rspec-expectations (~> 3.4.0)
60+
rspec-mocks (~> 3.4.0)
61+
rspec-core (3.4.4)
62+
rspec-support (~> 3.4.0)
63+
rspec-expectations (3.4.0)
7564
diff-lcs (>= 1.2.0, < 2.0)
76-
rspec-support (~> 3.3.0)
77-
rspec-mocks (3.3.2)
65+
rspec-support (~> 3.4.0)
66+
rspec-mocks (3.4.1)
7867
diff-lcs (>= 1.2.0, < 2.0)
79-
rspec-support (~> 3.3.0)
80-
rspec-support (3.3.0)
81-
rubocop (0.35.1)
82-
astrolabe (~> 1.3)
83-
parser (>= 2.2.3.0, < 3.0)
68+
rspec-support (~> 3.4.0)
69+
rspec-support (3.4.1)
70+
rubocop (0.42.0)
71+
parser (>= 2.3.1.1, < 3.0)
8472
powerpack (~> 0.1)
8573
rainbow (>= 1.99.1, < 3.0)
8674
ruby-progressbar (~> 1.7)
87-
tins (<= 1.6.0)
88-
ruby-progressbar (1.7.5)
89-
signet (0.6.1)
75+
unicode-display_width (~> 1.0, >= 1.0.1)
76+
ruby-progressbar (1.8.1)
77+
signet (0.7.3)
9078
addressable (~> 2.3)
91-
extlib (~> 0.9)
9279
faraday (~> 0.9)
9380
jwt (~> 1.5)
9481
multi_json (~> 1.10)
95-
thread_safe (0.3.5)
96-
tins (1.6.0)
97-
tzinfo (1.2.2)
98-
thread_safe (~> 0.1)
99-
zonefile (1.04)
82+
uber (0.0.15)
83+
unicode-display_width (1.1.0)
10084

10185
PLATFORMS
10286
ruby
10387

10488
DEPENDENCIES
105-
gcloud
89+
google-cloud-bigquery
90+
google-cloud-storage
10691
rake
10792
rspec
10893
rubocop
10994

11095
BUNDLED WITH
111-
1.10.6
96+
1.12.5

bigquery/README.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<img src="https://avatars2.githubusercontent.com/u/2810941?v=3&s=96" alt="Google Cloud Platform logo" title="Google Cloud Platform" align="right" height="96" width="96"/>
2+
3+
# Google BigQuery API Ruby Samples
4+
5+
[BigQuery][bigquery_docs] is Google's fully managed, petabyte scale, low cost
6+
analytics data warehouse.
7+
8+
[bigquery_docs]: https://cloud.google.com/bigquery/docs/
9+
10+
## Samples
11+
12+
### Datasets
13+
14+
```
15+
Usage: ruby datasets.rb <command> [arguments]
16+
17+
Commands:
18+
create <dataset_id> Create a new dataset with the specified ID
19+
list List datasets in the specified project
20+
delete <dataset_id> Delete the dataset with the specified ID
21+
```
22+
23+
### Tables
24+
25+
```
26+
Usage: ruby tables.rb <command> [arguments]
27+
28+
Commands:
29+
create <dataset_id> <table_id> Create a new table with the specified ID
30+
list <dataset_id> List all tables in the specified dataset
31+
delete <dataset_id> <table_id> Delete table with the specified ID
32+
list_data <dataset_id> <table_id> List data in table with the specified ID
33+
import_file <dataset_id> <table_id> <file_path>
34+
import_gcs <dataset_id> <table_id> <cloud_storage_path>
35+
export <dataset_id> <table_id> <cloud_storage_path>
36+
query <query>
37+
query_job <query>
38+
```

bigquery/Rakefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2015 Google, Inc
1+
# Copyright 2016 Google, Inc
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.

bigquery/datasets.rb

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
# Copyright 2016 Google, Inc
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
def create_bigquery_client project_id:
16+
# [START create_bigquery_client]
17+
require "google/cloud"
18+
19+
gcloud = Google::Cloud.new project_id
20+
bigquery = gcloud.bigquery
21+
# [END create_bigquery_client]
22+
end
23+
24+
def create_dataset project_id:, dataset_id:
25+
# [START create_dataset]
26+
# project_id = "Your Google Cloud project ID"
27+
# dataset_id = "ID of the dataset to create"
28+
29+
require "google/cloud"
30+
31+
gcloud = Google::Cloud.new project_id
32+
bigquery = gcloud.bigquery
33+
34+
bigquery.create_dataset dataset_id
35+
36+
puts "Created dataset: #{dataset_id}"
37+
# [END create_dataset]
38+
end
39+
40+
def list_datasets project_id:
41+
# [START list_datasets]
42+
# project_id = "Your Google Cloud project ID"
43+
44+
require "google/cloud"
45+
46+
gcloud = Google::Cloud.new project_id
47+
bigquery = gcloud.bigquery
48+
49+
bigquery.datasets.each do |dataset|
50+
puts dataset.dataset_id
51+
end
52+
# [END list_datasets]
53+
end
54+
55+
def delete_dataset project_id:, dataset_id:
56+
# [START delete_dataset]
57+
# project_id = "Your Google Cloud project ID"
58+
# dataset_id = "ID of the dataset to delete"
59+
60+
require "google/cloud"
61+
62+
gcloud = Google::Cloud.new project_id
63+
bigquery = gcloud.bigquery
64+
dataset = bigquery.dataset dataset_id
65+
66+
dataset.delete
67+
68+
puts "Deleted dataset: #{dataset_id}"
69+
# [END delete_dataset]
70+
end
71+
72+
if __FILE__ == $PROGRAM_NAME
73+
project_id = ENV["GOOGLE_CLOUD_PROJECT"]
74+
command = ARGV.shift
75+
76+
case command
77+
when "create"
78+
create_dataset project_id: project_id, dataset_id: ARGV.shift
79+
when "list"
80+
list_datasets project_id: project_id
81+
when "delete"
82+
delete_dataset project_id: project_id, dataset_id: ARGV.shift
83+
else
84+
puts <<-usage
85+
Usage: ruby datasets.rb <command> [arguments]
86+
87+
Commands:
88+
create <dataset_id> Create a new dataset with the specified ID
89+
list List datasets in the specified project
90+
delete <dataset_id> Delete the dataset with the specified ID
91+
usage
92+
end
93+
end

bigquery/shakespeare.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
# See the License for the specific language governing permissions and
1515
# limitations under the License.
1616

17+
# NOTE: this file is here for historical reasons for cloud.google.com docs
18+
# TODO: deprecate documentation using this sample and remove file
19+
1720
module Samples
1821
# BigQuery Samples module
1922
module BigQuery

0 commit comments

Comments
 (0)