simple_bigtable_client 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 7cc5ced6876896f8ffe9df3d6a766147f5bfc940e1faadc817128055577ae5e8
4
+ data.tar.gz: e2f4b287e0eea4b676fbc1339bbe2cf431404d01d2f1705672727cfe96d66eb4
5
+ SHA512:
6
+ metadata.gz: 930890bef91af501b2a8b24943e473204696d5f3c641d3e966fac312235300923bdc36933a0586bcf87b77fceb67fd753862bceec5adf756b9894d63116323b2
7
+ data.tar.gz: dc866074f4279f9bd600be250b020603facafdda8a234949c42f39a2bcdf80c7cf163ac84ac0c7114b12c1235d4b53ebd86b64fb1eda6474826f664f69aae9b4
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.5.1
5
+ before_install: gem install bundler -v 1.16.2
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at fonsan@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in simple_bigtable_client.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,86 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ simple_bigtable_client (0.1.0)
5
+ google-cloud-bigtable (~> 0.1.0)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ addressable (2.5.2)
11
+ public_suffix (>= 2.0.2, < 4.0)
12
+ diff-lcs (1.3)
13
+ faraday (0.15.2)
14
+ multipart-post (>= 1.2, < 3)
15
+ google-cloud-bigtable (0.1.0)
16
+ google-cloud-core (~> 1.1)
17
+ google-gax (~> 1.0)
18
+ grpc-google-iam-v1 (~> 0.6.9)
19
+ google-cloud-core (1.2.2)
20
+ google-cloud-env (~> 1.0)
21
+ google-cloud-env (1.0.2)
22
+ faraday (~> 0.11)
23
+ google-gax (1.3.0)
24
+ google-protobuf (~> 3.2)
25
+ googleapis-common-protos (>= 1.3.5, < 2.0)
26
+ googleauth (~> 0.6.2)
27
+ grpc (>= 1.7.2, < 2.0)
28
+ rly (~> 0.2.3)
29
+ google-protobuf (3.6.1)
30
+ googleapis-common-protos (1.3.7)
31
+ google-protobuf (~> 3.0)
32
+ googleapis-common-protos-types (~> 1.0)
33
+ grpc (~> 1.0)
34
+ googleapis-common-protos-types (1.0.2)
35
+ google-protobuf (~> 3.0)
36
+ googleauth (0.6.4)
37
+ faraday (~> 0.12)
38
+ jwt (>= 1.4, < 3.0)
39
+ memoist (~> 0.12)
40
+ multi_json (~> 1.11)
41
+ os (>= 0.9, < 2.0)
42
+ signet (~> 0.7)
43
+ grpc (1.14.1)
44
+ google-protobuf (~> 3.1)
45
+ googleapis-common-protos-types (~> 1.0.0)
46
+ grpc-google-iam-v1 (0.6.9)
47
+ googleapis-common-protos (>= 1.3.1, < 2.0)
48
+ grpc (~> 1.0)
49
+ jwt (2.1.0)
50
+ memoist (0.16.0)
51
+ multi_json (1.13.1)
52
+ multipart-post (2.0.0)
53
+ os (1.0.0)
54
+ public_suffix (3.0.3)
55
+ rake (10.5.0)
56
+ rly (0.2.3)
57
+ rspec (3.8.0)
58
+ rspec-core (~> 3.8.0)
59
+ rspec-expectations (~> 3.8.0)
60
+ rspec-mocks (~> 3.8.0)
61
+ rspec-core (3.8.0)
62
+ rspec-support (~> 3.8.0)
63
+ rspec-expectations (3.8.1)
64
+ diff-lcs (>= 1.2.0, < 2.0)
65
+ rspec-support (~> 3.8.0)
66
+ rspec-mocks (3.8.0)
67
+ diff-lcs (>= 1.2.0, < 2.0)
68
+ rspec-support (~> 3.8.0)
69
+ rspec-support (3.8.0)
70
+ signet (0.8.1)
71
+ addressable (~> 2.3)
72
+ faraday (~> 0.9)
73
+ jwt (>= 1.5, < 3.0)
74
+ multi_json (~> 1.10)
75
+
76
+ PLATFORMS
77
+ ruby
78
+
79
+ DEPENDENCIES
80
+ bundler (~> 1.16)
81
+ rake (~> 10.0)
82
+ rspec (~> 3.0)
83
+ simple_bigtable_client!
84
+
85
+ BUNDLED WITH
86
+ 1.16.2
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Fonsan
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,131 @@
1
+ # SimpleBigtableClient
2
+
3
+ Simple abstraction on top of https://github.com/GoogleCloudPlatform/google-cloud-ruby/tree/master/google-cloud-bigtable
4
+
5
+ Which is at the time of writing currently under alpha
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'simple_bigtable_client'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install simple_bigtable_client
22
+
23
+ ## Usage
24
+
25
+ The main point of this gem is to simplify the interfaces when reading and writing to bigtable
26
+
27
+ ### Reading
28
+
29
+ Turns this
30
+ ```ruby
31
+ require 'google/cloud/bigtable/v2'
32
+ bigtable_client = Google::Cloud::Bigtable::V2.new
33
+ formatted_table_name = Google::Cloud::Bigtable::V2::BigtableClient.table_path("project", "instance", "table")
34
+ bigtable_client.read_rows(formatted_table_name).each do |cell_chunk|
35
+ cell_chunk # => <Google::Bigtable::V2::ReadRowsResponse: chunks: [<Google::Bigtable::V2::ReadRowsResponse::CellChunk: row_key:....
36
+ end
37
+ ```
38
+
39
+ Into
40
+ ```ruby
41
+ require 'simple_bigtable_client'
42
+ client = SimpleBigTableClient.new('instance') # Uses ENV['GOOGLE_CLOUD_PROJECT']
43
+ client.read_rows do |row|
44
+ row #=> {_row_key: 'a', b: 'c'}
45
+ end
46
+ ```
47
+
48
+ ### Writing
49
+
50
+ Turns
51
+
52
+ ```ruby
53
+ require 'google/cloud/bigtable/v2'
54
+ bigtable_client = Google::Cloud::Bigtable::V2.new
55
+ formatted_table_name = Google::Cloud::Bigtable::V2::BigtableClient.table_path("project", "instance", "table")
56
+ entries = [
57
+ {
58
+ row_key: 'test',
59
+ mutations: [
60
+ {
61
+ set_cell: {
62
+ column_qualifier: 'a',
63
+ family_name: 'cf_v1',
64
+ value: 'value'
65
+ }
66
+ },
67
+ {
68
+ set_cell: {
69
+ column_qualifier: 'b',
70
+ family_name: 'cf_v1',
71
+ value: 'value2'
72
+ }
73
+ }
74
+ ]
75
+ },
76
+ {
77
+ row_key: 'test2',
78
+ mutations: [
79
+ {
80
+ set_cell: {
81
+ column_qualifier: 'a',
82
+ family_name: 'cf_v1',
83
+ value: 'value'
84
+ }
85
+ },
86
+ {
87
+ set_cell: {
88
+ column_qualifier: 'b',
89
+ family_name: 'cf_v1',
90
+ value: 'value2'
91
+ }
92
+ }
93
+ ]
94
+ }
95
+ ]
96
+ bigtable_client.mutate_rows(formatted_table_name, entries).each do |result|
97
+ p result
98
+ end
99
+ ```
100
+
101
+ Into
102
+
103
+ ```ruby
104
+ require 'simple_bigtable_client'
105
+ client = SimpleBigTableClient.new('instance') # Uses ENV['GOOGLE_CLOUD_PROJECT']
106
+ entries = {
107
+ first: {a: 'b', c: 'd'},
108
+ second: {e: 'f'},
109
+ }
110
+ subject.mutate_rows('table', 'column_family', entries) do |result|
111
+ p result
112
+ end
113
+ ```
114
+
115
+ ## Development
116
+
117
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
118
+
119
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
120
+
121
+ ## Contributing
122
+
123
+ Bug reports and pull requests are welcome on GitHub at https://github.com/Fonsan/simple_bigtable_client. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
124
+
125
+ ## License
126
+
127
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
128
+
129
+ ## Code of Conduct
130
+
131
+ Everyone interacting in the SimpleBigtableClient project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/Fonsan/simple_bigtable_client/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "simple_bigtable_client"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,71 @@
1
+ require "simple_bigtable_client/version"
2
+ require 'google/cloud/bigtable/v2'
3
+
4
+ class SimpleBigtableClient
5
+ def initialize(instance, project_id: ENV['GOOGLE_CLOUD_PROJECT'], bigtable_client: Google::Cloud::Bigtable::V2.new)
6
+ @instance = instance
7
+ @bigtable_client = bigtable_client
8
+ @project_id = project_id
9
+ end
10
+
11
+ def read_rows(table, column_family, rows: nil, filter: nil, limit: nil, options: nil)
12
+ return to_enum(
13
+ __method__,
14
+ table,
15
+ column_family,
16
+ rows: rows,
17
+ filter: filter,
18
+ limit: limit,
19
+ options: options
20
+ ) unless block_given?
21
+ cell_chunk_enumerator = @bigtable_client.read_rows(
22
+ table_name(table),
23
+ rows: rows,
24
+ filter: filter,
25
+ rows_limit: limit,
26
+ options: options
27
+ )
28
+ prev_row_key = nil
29
+ row_enumerator = cell_chunk_enumerator.lazy.flat_map(&:chunks).chunk do |cell_chunk|
30
+ if cell_chunk.row_key == ""
31
+ prev_row_key
32
+ else
33
+ prev_row_key = cell_chunk.row_key
34
+ end
35
+ end
36
+ row_enumerator.each do |row_key, cell_chunks|
37
+ row = cell_chunks.each_with_object(_row_key: row_key) do |cell_chunk, acc|
38
+ acc[cell_chunk.qualifier.value.to_sym] = cell_chunk.value
39
+ end
40
+ yield(row)
41
+ end
42
+ end
43
+
44
+ def mutate_rows(table, column_family, enumerator, slice_size: 100_000)
45
+ enumerator.each_slice(slice_size) do |slice|
46
+ entries = slice.map do |row_key, cells|
47
+ {
48
+ row_key: row_key.to_s,
49
+ mutations: cells.map do |column_qualifier, value|
50
+ {
51
+ set_cell: {
52
+ column_qualifier: column_qualifier.to_s,
53
+ family_name: column_family,
54
+ value: value.to_s
55
+ }
56
+ }
57
+ end
58
+ }
59
+ end
60
+ @bigtable_client.mutate_rows(table_name(table), entries).each do |element|
61
+ yield element if block_given?
62
+ end
63
+ end
64
+ end
65
+
66
+ private
67
+
68
+ def table_name(table)
69
+ Google::Cloud::Bigtable::V2::BigtableClient.table_path(@project_id, @instance, table)
70
+ end
71
+ end
@@ -0,0 +1,3 @@
1
+ class SimpleBigtableClient
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,28 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "simple_bigtable_client/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "simple_bigtable_client"
8
+ spec.version = SimpleBigtableClient::VERSION
9
+ spec.authors = ["Fonsan"]
10
+ spec.email = ["fonsan@gmail.com"]
11
+
12
+ spec.summary = %q{A simple abstraction of reading and writing to bigtable}
13
+ spec.description = %q{A simple abstraction of reading and writing to bigtable}
14
+ spec.license = "MIT"
15
+
16
+ # Specify which files should be added to the gem when it is released.
17
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
18
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
19
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
20
+ end
21
+ spec.bindir = "exe"
22
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
+ spec.require_paths = ["lib"]
24
+ spec.add_dependency "google-cloud-bigtable", "~> 0.1.0"
25
+ spec.add_development_dependency "bundler", "~> 1.16"
26
+ spec.add_development_dependency "rake", "~> 10.0"
27
+ spec.add_development_dependency "rspec", "~> 3.0"
28
+ end
metadata ADDED
@@ -0,0 +1,114 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: simple_bigtable_client
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Fonsan
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-08-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: google-cloud-bigtable
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.1.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.1.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.16'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.16'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ description: A simple abstraction of reading and writing to bigtable
70
+ email:
71
+ - fonsan@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".rspec"
78
+ - ".travis.yml"
79
+ - CODE_OF_CONDUCT.md
80
+ - Gemfile
81
+ - Gemfile.lock
82
+ - LICENSE.txt
83
+ - README.md
84
+ - Rakefile
85
+ - bin/console
86
+ - bin/setup
87
+ - lib/simple_bigtable_client.rb
88
+ - lib/simple_bigtable_client/version.rb
89
+ - simple_bigtable_client.gemspec
90
+ homepage:
91
+ licenses:
92
+ - MIT
93
+ metadata: {}
94
+ post_install_message:
95
+ rdoc_options: []
96
+ require_paths:
97
+ - lib
98
+ required_ruby_version: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ required_rubygems_version: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ requirements: []
109
+ rubyforge_project:
110
+ rubygems_version: 2.7.7
111
+ signing_key:
112
+ specification_version: 4
113
+ summary: A simple abstraction of reading and writing to bigtable
114
+ test_files: []