google-cloud-spanner 1.16.1 → 2.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (108) hide show
  1. checksums.yaml +4 -4
  2. data/AUTHENTICATION.md +1 -1
  3. data/CHANGELOG.md +58 -0
  4. data/CONTRIBUTING.md +6 -6
  5. data/TROUBLESHOOTING.md +0 -6
  6. data/lib/google-cloud-spanner.rb +11 -13
  7. data/lib/google/cloud/spanner.rb +13 -13
  8. data/lib/google/cloud/spanner/admin/database/credentials.rb +2 -2
  9. data/lib/google/cloud/spanner/admin/instance/credentials.rb +2 -2
  10. data/lib/google/cloud/spanner/backup.rb +1 -1
  11. data/lib/google/cloud/spanner/backup/job.rb +2 -2
  12. data/lib/google/cloud/spanner/backup/job/list.rb +2 -2
  13. data/lib/google/cloud/spanner/backup/list.rb +1 -2
  14. data/lib/google/cloud/spanner/backup/restore/job.rb +2 -2
  15. data/lib/google/cloud/spanner/batch_client.rb +2 -2
  16. data/lib/google/cloud/spanner/batch_snapshot.rb +120 -23
  17. data/lib/google/cloud/spanner/batch_update.rb +1 -1
  18. data/lib/google/cloud/spanner/client.rb +388 -47
  19. data/lib/google/cloud/spanner/commit.rb +14 -14
  20. data/lib/google/cloud/spanner/commit_response.rb +87 -0
  21. data/lib/google/cloud/spanner/commit_response/commit_stats.rb +51 -0
  22. data/lib/google/cloud/spanner/convert.rb +16 -7
  23. data/lib/google/cloud/spanner/credentials.rb +2 -2
  24. data/lib/google/cloud/spanner/data.rb +2 -2
  25. data/lib/google/cloud/spanner/database.rb +22 -22
  26. data/lib/google/cloud/spanner/database/backup_info.rb +1 -1
  27. data/lib/google/cloud/spanner/database/job.rb +3 -3
  28. data/lib/google/cloud/spanner/database/job/list.rb +2 -2
  29. data/lib/google/cloud/spanner/database/list.rb +1 -1
  30. data/lib/google/cloud/spanner/database/restore_info.rb +1 -1
  31. data/lib/google/cloud/spanner/fields.rb +8 -8
  32. data/lib/google/cloud/spanner/instance.rb +5 -12
  33. data/lib/google/cloud/spanner/instance/config.rb +1 -1
  34. data/lib/google/cloud/spanner/instance/config/list.rb +1 -1
  35. data/lib/google/cloud/spanner/instance/job.rb +2 -2
  36. data/lib/google/cloud/spanner/instance/list.rb +1 -1
  37. data/lib/google/cloud/spanner/partition.rb +4 -4
  38. data/lib/google/cloud/spanner/policy.rb +2 -2
  39. data/lib/google/cloud/spanner/results.rb +103 -24
  40. data/lib/google/cloud/spanner/service.rb +367 -349
  41. data/lib/google/cloud/spanner/session.rb +370 -39
  42. data/lib/google/cloud/spanner/snapshot.rb +60 -6
  43. data/lib/google/cloud/spanner/transaction.rb +116 -10
  44. data/lib/google/cloud/spanner/version.rb +1 -1
  45. metadata +20 -107
  46. data/lib/google/cloud/spanner/admin/database.rb +0 -149
  47. data/lib/google/cloud/spanner/admin/database/v1.rb +0 -147
  48. data/lib/google/cloud/spanner/admin/database/v1/credentials.rb +0 -46
  49. data/lib/google/cloud/spanner/admin/database/v1/database_admin_client.rb +0 -1513
  50. data/lib/google/cloud/spanner/admin/database/v1/database_admin_client_config.json +0 -111
  51. data/lib/google/cloud/spanner/admin/database/v1/doc/google/iam/v1/iam_policy.rb +0 -64
  52. data/lib/google/cloud/spanner/admin/database/v1/doc/google/iam/v1/options.rb +0 -33
  53. data/lib/google/cloud/spanner/admin/database/v1/doc/google/iam/v1/policy.rb +0 -151
  54. data/lib/google/cloud/spanner/admin/database/v1/doc/google/longrunning/operations.rb +0 -51
  55. data/lib/google/cloud/spanner/admin/database/v1/doc/google/protobuf/any.rb +0 -131
  56. data/lib/google/cloud/spanner/admin/database/v1/doc/google/protobuf/empty.rb +0 -29
  57. data/lib/google/cloud/spanner/admin/database/v1/doc/google/protobuf/field_mask.rb +0 -222
  58. data/lib/google/cloud/spanner/admin/database/v1/doc/google/protobuf/timestamp.rb +0 -113
  59. data/lib/google/cloud/spanner/admin/database/v1/doc/google/rpc/status.rb +0 -39
  60. data/lib/google/cloud/spanner/admin/database/v1/doc/google/spanner/admin/database/v1/backup.rb +0 -325
  61. data/lib/google/cloud/spanner/admin/database/v1/doc/google/spanner/admin/database/v1/spanner_database_admin.rb +0 -368
  62. data/lib/google/cloud/spanner/admin/database/v1/doc/google/type/expr.rb +0 -45
  63. data/lib/google/cloud/spanner/admin/instance.rb +0 -164
  64. data/lib/google/cloud/spanner/admin/instance/v1.rb +0 -162
  65. data/lib/google/cloud/spanner/admin/instance/v1/credentials.rb +0 -46
  66. data/lib/google/cloud/spanner/admin/instance/v1/doc/google/iam/v1/iam_policy.rb +0 -64
  67. data/lib/google/cloud/spanner/admin/instance/v1/doc/google/iam/v1/options.rb +0 -33
  68. data/lib/google/cloud/spanner/admin/instance/v1/doc/google/iam/v1/policy.rb +0 -151
  69. data/lib/google/cloud/spanner/admin/instance/v1/doc/google/longrunning/operations.rb +0 -51
  70. data/lib/google/cloud/spanner/admin/instance/v1/doc/google/protobuf/any.rb +0 -131
  71. data/lib/google/cloud/spanner/admin/instance/v1/doc/google/protobuf/empty.rb +0 -29
  72. data/lib/google/cloud/spanner/admin/instance/v1/doc/google/protobuf/field_mask.rb +0 -222
  73. data/lib/google/cloud/spanner/admin/instance/v1/doc/google/rpc/status.rb +0 -39
  74. data/lib/google/cloud/spanner/admin/instance/v1/doc/google/spanner/admin/instance/v1/spanner_instance_admin.rb +0 -334
  75. data/lib/google/cloud/spanner/admin/instance/v1/doc/google/type/expr.rb +0 -45
  76. data/lib/google/cloud/spanner/admin/instance/v1/instance_admin_client.rb +0 -975
  77. data/lib/google/cloud/spanner/admin/instance/v1/instance_admin_client_config.json +0 -76
  78. data/lib/google/cloud/spanner/v1.rb +0 -16
  79. data/lib/google/cloud/spanner/v1/credentials.rb +0 -42
  80. data/lib/google/cloud/spanner/v1/doc/google/protobuf/any.rb +0 -131
  81. data/lib/google/cloud/spanner/v1/doc/google/protobuf/duration.rb +0 -91
  82. data/lib/google/cloud/spanner/v1/doc/google/protobuf/empty.rb +0 -29
  83. data/lib/google/cloud/spanner/v1/doc/google/protobuf/struct.rb +0 -74
  84. data/lib/google/cloud/spanner/v1/doc/google/protobuf/timestamp.rb +0 -113
  85. data/lib/google/cloud/spanner/v1/doc/google/rpc/status.rb +0 -39
  86. data/lib/google/cloud/spanner/v1/doc/google/spanner/v1/keys.rb +0 -150
  87. data/lib/google/cloud/spanner/v1/doc/google/spanner/v1/mutation.rb +0 -95
  88. data/lib/google/cloud/spanner/v1/doc/google/spanner/v1/query_plan.rb +0 -121
  89. data/lib/google/cloud/spanner/v1/doc/google/spanner/v1/result_set.rb +0 -190
  90. data/lib/google/cloud/spanner/v1/doc/google/spanner/v1/spanner.rb +0 -570
  91. data/lib/google/cloud/spanner/v1/doc/google/spanner/v1/transaction.rb +0 -432
  92. data/lib/google/cloud/spanner/v1/doc/google/spanner/v1/type.rb +0 -112
  93. data/lib/google/cloud/spanner/v1/spanner_client.rb +0 -1485
  94. data/lib/google/cloud/spanner/v1/spanner_client_config.json +0 -121
  95. data/lib/google/spanner/admin/database/v1/backup_pb.rb +0 -98
  96. data/lib/google/spanner/admin/database/v1/common_pb.rb +0 -28
  97. data/lib/google/spanner/admin/database/v1/spanner_database_admin_pb.rb +0 -141
  98. data/lib/google/spanner/admin/database/v1/spanner_database_admin_services_pb.rb +0 -169
  99. data/lib/google/spanner/admin/instance/v1/spanner_instance_admin_pb.rb +0 -125
  100. data/lib/google/spanner/admin/instance/v1/spanner_instance_admin_services_pb.rb +0 -181
  101. data/lib/google/spanner/v1/keys_pb.rb +0 -34
  102. data/lib/google/spanner/v1/mutation_pb.rb +0 -39
  103. data/lib/google/spanner/v1/query_plan_pb.rb +0 -48
  104. data/lib/google/spanner/v1/result_set_pb.rb +0 -48
  105. data/lib/google/spanner/v1/spanner_pb.rb +0 -179
  106. data/lib/google/spanner/v1/spanner_services_pb.rb +0 -179
  107. data/lib/google/spanner/v1/transaction_pb.rb +0 -56
  108. data/lib/google/spanner/v1/type_pb.rb +0 -44
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0664e0297ebbb9ce2dbc21a30d211fe48ea2e33ceb5bb00caa2505d9ef3a372c
4
- data.tar.gz: 2a8848bf6be79485cc33ceaea1d374e5b3626ca52045c84666962ac002c0894c
3
+ metadata.gz: 62f5ce383d6aefe48214924e77b5a794bd0a0c03bb6acaedd383be12d47da9b9
4
+ data.tar.gz: ed1e49a6ef47946d557f8cb768d6da33923179fa05551ea7fadd55f3f5cfe341
5
5
  SHA512:
6
- metadata.gz: eb4d0f943eb8277fb989cd6ec3bf4a64ce884d0305a4cb0aa0e56a748cef931784344dd36a35ab92f9bd412ad720016c895d1ba21a2646e5c92ccc65be2b4bf4
7
- data.tar.gz: 8129574c69d0fc3db9733f40dfb013461d72db64420afe6f6639a97993c5b87ed672457e73a9d7fe74b46fb9542f08a611836a6cec104425b95f29f23d5e8dc6
6
+ metadata.gz: 4b22e83c54208f8961e267a81ef681f98ef7e2ffe9a48274e566899adfed7c514c3a124b9f747667908db89067cbe0715f8c1363635d75cd4461f9072f703819
7
+ data.tar.gz: '085550ca4945d0436fd92f94adb16464d30224f5f466ca1f3becb24bdcf0b8bc4fa0416d2f26ecc375ca71eadface1856702dac02a7093bda001ce4e37be359d'
data/AUTHENTICATION.md CHANGED
@@ -76,7 +76,7 @@ The environment variables that google-cloud-spanner checks for project ID are:
76
76
  1. `SPANNER_PROJECT`
77
77
  2. `GOOGLE_CLOUD_PROJECT`
78
78
 
79
- The environment variables that google-cloud-spanner checks for credentials are configured on {Google::Cloud::Spanner::V1::Credentials}:
79
+ The environment variables that google-cloud-spanner checks for credentials are configured on `Google::Cloud::Spanner::V1::Spanner::Credentials`:
80
80
 
81
81
  1. `SPANNER_CREDENTIALS` - Path to JSON file, or JSON contents
82
82
  2. `SPANNER_KEYFILE` - Path to JSON file, or JSON contents
data/CHANGELOG.md CHANGED
@@ -1,5 +1,63 @@
1
1
  # Release History
2
2
 
3
+ ### 2.3.0 / 2021-02-09
4
+
5
+ #### Features
6
+
7
+ * CommitStats in CommitResponse ([#8058](https://www.github.com/googleapis/google-cloud-ruby/issues/8058))
8
+ * optionalize `credentials` when using cloud spanner emulator host ([#8416](https://www.github.com/googleapis/google-cloud-ruby/issues/8416))
9
+ * Optionalize `credentials` when using Cloud Spanner Emulator
10
+ * Remove unnecessary credentials stub for emulator_host in Google::Cloud::Spanner.new
11
+ * Add test of explicit project_id in Google::Cloud::Spanner.new
12
+ * Update document for `emulator_host` without credentials
13
+ * Tidy code according to rubocop settings
14
+
15
+ ### 2.2.0 / 2020-09-15
16
+
17
+ #### Features
18
+
19
+ * quota_project can be set via library configuration
20
+ * Support numeric type.
21
+
22
+ #### Bug Fixes
23
+
24
+ * retry or resume eos and rst_stream errors
25
+
26
+ ### 2.1.0 / 2020-08-05
27
+
28
+ #### Features
29
+
30
+ * Support custom setting of timeout and retry
31
+
32
+ ### 2.0.0 / 2020-07-23
33
+
34
+ This is a major update that removes the "low-level" client interface code, and
35
+ instead adds `google-cloud-spanner-v1`, `google-cloud-spanner-admin-database-v1`,
36
+ and `google-cloud-spanner-admin-instance-v1` as dependencies.
37
+ The new dependencies are rewritten low-level clients, produced by a next-
38
+ generation client code generator, with improved performance and stability.
39
+
40
+ This change should have no effect on the high-level interface that most users
41
+ will use. The one exception is that the (mostly undocumented) `client_config`
42
+ argument, for adjusting low-level parameters such as RPC retry settings on
43
+ client objects, has been removed. If you need to adjust these parameters, use
44
+ the configuration interface in low-level clients.
45
+
46
+ Substantial changes have been made in the low-level interfaces, however. If you
47
+ are using the low-level classes under the old `Google::Spanner::V1` module,
48
+ please review the docs for the new `google-cloud-spanner-v1` gem. In particular:
49
+
50
+ * Some classes have been renamed, notably the client class itself.
51
+ * The client constructor takes a configuration block instead of configuration
52
+ keyword arguments.
53
+ * All RPC method arguments are now keyword arguments.
54
+
55
+ ### 1.16.2 / 2020-05-28
56
+
57
+ #### Documentation
58
+
59
+ * Fix a few broken links
60
+
3
61
  ### 1.16.1 / 2020-05-21
4
62
 
5
63
  #### Bug Fixes
data/CONTRIBUTING.md CHANGED
@@ -45,7 +45,7 @@ there is a small amount of setup:
45
45
 
46
46
  ```sh
47
47
  $ cd google-cloud-spanner/
48
- $ bundle exec rake bundleupdate
48
+ $ bundle install
49
49
  ```
50
50
 
51
51
  ## Console
@@ -53,7 +53,7 @@ there is a small amount of setup:
53
53
  In order to run code interactively, you can automatically load
54
54
  google-cloud-spanner and its dependencies in IRB. This requires that your
55
55
  developer environment has already been configured by following the steps
56
- described in the [Authentication Guide](AUTHENTICATION.md). An IRB console
56
+ described in the {file:AUTHENTICATION.md Authentication Guide}. An IRB console
57
57
  can be created with:
58
58
 
59
59
  ```sh
@@ -119,7 +119,7 @@ If you alter an example's title, you may encounter breaking tests.
119
119
  ### Spanner Acceptance Tests
120
120
 
121
121
  The Spanner acceptance tests interact with the live service API. Follow the
122
- instructions in the [Authentication Guide](AUTHENTICATION.md) for enabling
122
+ instructions in the {file:AUTHENTICATION.md Authentication Guide} for enabling
123
123
  the Spanner API. Occasionally, some API features may not yet be generally
124
124
  available, making it difficult for some contributors to successfully run the
125
125
  entire acceptance test suite. However, please ensure that you do successfully
@@ -127,7 +127,7 @@ run acceptance tests for any code areas covered by your pull request.
127
127
 
128
128
  To run the acceptance tests, first create and configure a project in the Google
129
129
  Developers Console, as described in the
130
- [Authentication Guide](AUTHENTICATION.md). Be sure to download the JSON KEY
130
+ {file:AUTHENTICATION.md Authentication Guide}. Be sure to download the JSON KEY
131
131
  file. Make note of the PROJECT_ID and the KEYFILE location on your system.
132
132
 
133
133
  Before you can run the Spanner acceptance tests, you must first create indexes
@@ -184,5 +184,5 @@ $ bundle exec rake rubocop
184
184
  ## Code of Conduct
185
185
 
186
186
  Please note that this project is released with a Contributor Code of Conduct. By
187
- participating in this project you agree to abide by its terms. See
188
- [Code of Conduct](CODE_OF_CONDUCT.md) for more information.
187
+ participating in this project you agree to abide by its terms. See the
188
+ {file:CODE_OF_CONDUCT.md Code of Conduct} for more information.
data/TROUBLESHOOTING.md CHANGED
@@ -24,14 +24,8 @@ improved, *please* create a new issue on GitHub so we can talk about it.
24
24
 
25
25
  - [New issue][gh-ruby]
26
26
 
27
- Or, you can ask questions on the [Google Cloud Platform Slack][slack-ruby]. You
28
- can use the "ruby" channel for general Ruby questions, or use the
29
- "google-cloud-ruby" channel if you have questions about this gem in particular.
30
-
31
27
  [so-ruby]: http://stackoverflow.com/questions/tagged/google-cloud-platform+ruby+spanner
32
28
 
33
29
  [gh-search-ruby]: https://github.com/googlecloudplatform/google-cloud-ruby/issues?q=label%3A%22api%3A+spanner%22
34
30
 
35
31
  [gh-ruby]: https://github.com/googlecloudplatform/google-cloud-ruby/issues/new
36
-
37
- [slack-ruby]: https://gcp-slack.appspot.com/
@@ -43,8 +43,6 @@ module Google
43
43
  # * `https://www.googleapis.com/auth/spanner`
44
44
  # * `https://www.googleapis.com/auth/spanner.data`
45
45
  # @param [Integer] timeout Default timeout to use in requests. Optional.
46
- # @param [Hash] client_config A hash of values to override the default
47
- # behavior of the API client. Optional.
48
46
  # @param [String] lib_name Library name. This will be added as a prefix
49
47
  # to the API call tracking header `x-goog-api-client` with provided
50
48
  # lib version for telemetry. Optional. For example prefix looks like
@@ -75,11 +73,9 @@ module Google
75
73
  # platform_scope = "https://www.googleapis.com/auth/cloud-platform"
76
74
  # spanner = gcloud.spanner scope: platform_scope
77
75
  #
78
- def spanner scope: nil, timeout: nil, client_config: nil, lib_name: nil,
79
- lib_version: nil
76
+ def spanner scope: nil, timeout: nil, lib_name: nil, lib_version: nil
80
77
  Google::Cloud.spanner @project, @keyfile, scope: scope,
81
78
  timeout: (timeout || @timeout),
82
- client_config: client_config,
83
79
  lib_name: lib_name,
84
80
  lib_version: lib_version
85
81
  end
@@ -107,8 +103,6 @@ module Google
107
103
  # * `https://www.googleapis.com/auth/spanner`
108
104
  # * `https://www.googleapis.com/auth/spanner.data`
109
105
  # @param [Integer] timeout Default timeout to use in requests. Optional.
110
- # @param [Hash] client_config A hash of values to override the default
111
- # behavior of the API client. Optional.
112
106
  # @param [String] lib_name Library name. This will be added as a prefix
113
107
  # to the API call tracking header `x-goog-api-client` with provided
114
108
  # lib version for telemetry. Optional. For example prefix looks like
@@ -132,13 +126,11 @@ module Google
132
126
  # spanner = Google::Cloud.spanner
133
127
  #
134
128
  def self.spanner project_id = nil, credentials = nil, scope: nil,
135
- timeout: nil, client_config: nil, lib_name: nil,
136
- lib_version: nil
129
+ timeout: nil, lib_name: nil, lib_version: nil
137
130
  require "google/cloud/spanner"
138
131
  Google::Cloud::Spanner.new project_id: project_id,
139
132
  credentials: credentials,
140
133
  scope: scope, timeout: timeout,
141
- client_config: client_config,
142
134
  lib_name: lib_name, lib_version: lib_version
143
135
  end
144
136
  end
@@ -169,16 +161,22 @@ Google::Cloud.configure.add_config! :spanner do |config|
169
161
  query_options
170
162
  end
171
163
 
164
+ default_scopes = [
165
+ "https://www.googleapis.com/auth/cloud-platform",
166
+ "https://www.googleapis.com/auth/spanner.admin",
167
+ "https://www.googleapis.com/auth/spanner.data"
168
+ ]
169
+
172
170
  config.add_field! :project_id, default_project, match: String, allow_nil: true
173
171
  config.add_alias! :project, :project_id
174
172
  config.add_field! :credentials, default_creds,
175
173
  match: [String, Hash, Google::Auth::Credentials],
176
174
  allow_nil: true
177
175
  config.add_alias! :keyfile, :credentials
178
- config.add_field! :scope, nil, match: [String, Array]
176
+ config.add_field! :scope, default_scopes, match: [String, Array]
177
+ config.add_field! :quota_project, nil, match: String
179
178
  config.add_field! :timeout, nil, match: Integer
180
- config.add_field! :client_config, nil, match: Hash
181
- config.add_field! :endpoint, nil, match: String
179
+ config.add_field! :endpoint, "spanner.googleapis.com", match: String
182
180
  config.add_field! :emulator_host, default_emulator, match: String, allow_nil: true
183
181
  config.add_field! :lib_name, nil, match: String, allow_nil: true
184
182
  config.add_field! :lib_version, nil, match: String, allow_nil: true
@@ -49,6 +49,8 @@ module Google
49
49
  # @param [String, Hash, Google::Auth::Credentials] credentials The path to
50
50
  # the keyfile as a String, the contents of the keyfile as a Hash, or a
51
51
  # Google::Auth::Credentials object. (See {Spanner::Credentials})
52
+ # If `emulator_host` is present, this becomes optional and the value is
53
+ # internally overriden with `:this_channel_is_insecure`.
52
54
  # @param [String, Array<String>] scope The OAuth 2.0 scopes controlling
53
55
  # the set of resources and operations that the connection can access.
54
56
  # See [Using OAuth 2.0 to Access Google
@@ -59,10 +61,8 @@ module Google
59
61
  # * `https://www.googleapis.com/auth/spanner`
60
62
  # * `https://www.googleapis.com/auth/spanner.data`
61
63
  # @param [Integer] timeout Default timeout to use in requests. Optional.
62
- # @param [Hash] client_config A hash of values to override the default
63
- # behavior of the API client. Optional.
64
64
  # @param [String] endpoint Override of the endpoint host name. Optional.
65
- # If the param is nil, uses the default endpoint.
65
+ # If the param is nil, uses `emulator_host` or the default endpoint.
66
66
  # @param [String] project Alias for the `project_id` argument. Deprecated.
67
67
  # @param [String] keyfile Alias for the `credentials` argument.
68
68
  # Deprecated.
@@ -91,22 +91,21 @@ module Google
91
91
  # spanner = Google::Cloud::Spanner.new
92
92
  #
93
93
  def self.new project_id: nil, credentials: nil, scope: nil, timeout: nil,
94
- client_config: nil, endpoint: nil, project: nil, keyfile: nil,
94
+ endpoint: nil, project: nil, keyfile: nil,
95
95
  emulator_host: nil, lib_name: nil, lib_version: nil
96
- project_id ||= (project || default_project_id)
96
+ project_id ||= project || default_project_id
97
97
  scope ||= configure.scope
98
98
  timeout ||= configure.timeout
99
- client_config ||= configure.client_config
100
- endpoint ||= configure.endpoint
101
- credentials ||= (keyfile || default_credentials(scope: scope))
102
99
  emulator_host ||= configure.emulator_host
100
+ endpoint ||= emulator_host || configure.endpoint
101
+ credentials ||= keyfile
103
102
  lib_name ||= configure.lib_name
104
103
  lib_version ||= configure.lib_version
105
104
 
106
105
  if emulator_host
107
106
  credentials = :this_channel_is_insecure
108
- endpoint = emulator_host
109
107
  else
108
+ credentials ||= default_credentials scope: scope
110
109
  unless credentials.is_a? Google::Auth::Credentials
111
110
  credentials = Spanner::Credentials.new credentials, scope: scope
112
111
  end
@@ -122,8 +121,8 @@ module Google
122
121
  Spanner::Project.new(
123
122
  Spanner::Service.new(
124
123
  project_id, credentials,
125
- host: endpoint, timeout: timeout, client_config: client_config,
126
- lib_name: lib_name, lib_version: lib_version
124
+ host: endpoint, timeout: timeout, lib_name: lib_name,
125
+ lib_version: lib_version
127
126
  ),
128
127
  query_options: configure.query_options
129
128
  )
@@ -145,8 +144,6 @@ module Google
145
144
  # * `scope` - (String, Array<String>) The OAuth 2.0 scopes controlling
146
145
  # the set of resources and operations that the connection can access.
147
146
  # * `timeout` - (Integer) Default timeout to use in requests.
148
- # * `client_config` - (Hash) A hash of values to override the default
149
- # behavior of the API client.
150
147
  # * `endpoint` - (String) Override of the endpoint host name, or `nil`
151
148
  # to use the default endpoint.
152
149
  # * `emulator_host` - (String) Host name of the emulator. Defaults to
@@ -184,4 +181,7 @@ module Google
184
181
  end
185
182
  end
186
183
  end
184
+
185
+ # @private
186
+ Spanner = Cloud::Spanner unless const_defined? :Spanner
187
187
  end
@@ -13,7 +13,7 @@
13
13
  # limitations under the License.
14
14
 
15
15
 
16
- require "googleauth"
16
+ require "google/cloud/spanner/admin/database/v1/database_admin/credentials"
17
17
 
18
18
  module Google
19
19
  module Cloud
@@ -23,7 +23,7 @@ module Google
23
23
  ##
24
24
  # @deprecated Use version-specific credentials classes
25
25
  #
26
- Credentials = Google::Cloud::Spanner::Admin::Database::V1::Credentials
26
+ Credentials = V1::DatabaseAdmin::Credentials
27
27
  end
28
28
  end
29
29
  end
@@ -13,7 +13,7 @@
13
13
  # limitations under the License.
14
14
 
15
15
 
16
- require "googleauth"
16
+ require "google/cloud/spanner/admin/instance/v1/instance_admin/credentials"
17
17
 
18
18
  module Google
19
19
  module Cloud
@@ -23,7 +23,7 @@ module Google
23
23
  ##
24
24
  # @deprecated Use version-specific credentials classes
25
25
  #
26
- Credentials = Google::Cloud::Spanner::Admin::Instance::V1::Credentials
26
+ Credentials = V1::InstanceAdmin::Credentials
27
27
  end
28
28
  end
29
29
  end
@@ -296,7 +296,7 @@ module Google
296
296
  ##
297
297
  # @private
298
298
  # Creates a new Backup instance from a
299
- # {Google::Spanner::Admin::Database::V1::Backup}.
299
+ # `Google::Cloud::Spanner::Admin::Database::V1::Backup`.
300
300
  def self.from_grpc grpc, service
301
301
  new grpc, service
302
302
  end
@@ -53,7 +53,7 @@ module Google
53
53
  #
54
54
  class Job
55
55
  ##
56
- # @private The Google::Gax::Operation gRPC object.
56
+ # @private The `Gapic::Operation` gRPC object.
57
57
  attr_accessor :grpc
58
58
 
59
59
  ##
@@ -260,7 +260,7 @@ module Google
260
260
  end
261
261
 
262
262
  ##
263
- # @private New Backup::Job from a Google::Gax::Operation object.
263
+ # @private New Backup::Job from a `Gapic::Operation` object.
264
264
  def self.from_grpc grpc, service
265
265
  new.tap do |job|
266
266
  job.instance_variable_set :@grpc, grpc
@@ -146,7 +146,7 @@ module Google
146
146
  # @private
147
147
  #
148
148
  # New Backup::Job::List from a
149
- # Google::Gax::PagedEnumerable<Google::Longrunning::Operation>
149
+ # `Gapic::PagedEnumerable<Google::Longrunning::Operation>`
150
150
  # object. Operation object is a backup operation.
151
151
  #
152
152
  def self.from_grpc grpc, service
@@ -154,7 +154,7 @@ module Google
154
154
  service.databases.instance_variable_get "@operations_client"
155
155
  jobs = new(Array(grpc.response.operations).map do |job_grpc|
156
156
  Job.from_grpc \
157
- Google::Gax::Operation.new(job_grpc, operations_client),
157
+ Gapic::Operation.new(job_grpc, operations_client),
158
158
  service
159
159
  end)
160
160
  jobs.grpc = grpc
@@ -143,8 +143,7 @@ module Google
143
143
  ##
144
144
  # @private
145
145
  # New Backup::List from a
146
- # Google::Gax::PagedEnumerable<Google::Spanner::Admin::Database::\
147
- # V1::Backup>
146
+ # `Gapic::PagedEnumerable<Google::Cloud::Spanner::Admin::Database::V1::Backup>`
148
147
  # object.
149
148
  def self.from_grpc grpc, service
150
149
  backups = List.new(Array(grpc.response.backups).map do |backup|
@@ -53,7 +53,7 @@ module Google
53
53
  #
54
54
  class Job
55
55
  ##
56
- # @private The Google::Gax::Operation gRPC object.
56
+ # @private The `Gapic::Operation` gRPC object.
57
57
  attr_accessor :grpc
58
58
 
59
59
  ##
@@ -231,7 +231,7 @@ module Google
231
231
  end
232
232
 
233
233
  ##
234
- # @private New Restore::Job from a Google::Gax::Operation object.
234
+ # @private New Restore::Job from a `Gapic::Operation` object.
235
235
  def self.from_grpc grpc, service
236
236
  new.tap do |job|
237
237
  job.instance_variable_set :@grpc, grpc
@@ -407,8 +407,8 @@ module Google
407
407
  def session
408
408
  ensure_service!
409
409
  grpc = @project.service.create_session \
410
- Admin::Database::V1::DatabaseAdminClient.database_path(
411
- project_id, instance_id, database_id
410
+ V1::Spanner::Paths.database_path(
411
+ project: project_id, instance: instance_id, database: database_id
412
412
  ),
413
413
  labels: @session_labels
414
414
  Session.from_grpc grpc, @project.service, query_options: @query_options
@@ -173,6 +173,19 @@ module Google
173
173
  # * `:optimizer_version` (String) The version of optimizer to use.
174
174
  # Empty to use database default. "latest" to use the latest
175
175
  # available optimizer version.
176
+ # @param [Hash] call_options A hash of values to specify the custom
177
+ # call options, e.g., timeout, retries, etc. Call options are
178
+ # optional. The following settings can be provided:
179
+ #
180
+ # * `:timeout` (Numeric) A numeric value of custom timeout in seconds
181
+ # that overrides the default setting.
182
+ # * `:retry_policy` (Hash) A hash of values that overrides the default
183
+ # setting of retry policy with the following keys:
184
+ # * `:initial_delay` (`Numeric`) - The initial delay in seconds.
185
+ # * `:max_delay` (`Numeric`) - The max delay in seconds.
186
+ # * `:multiplier` (`Numeric`) - The incremental backoff multiplier.
187
+ # * `:retry_codes` (`Array<String>`) - The error codes that should
188
+ # trigger a retry.
176
189
  #
177
190
  # @return [Array<Google::Cloud::Spanner::Partition>] The partitions
178
191
  # created by the query partition.
@@ -196,7 +209,7 @@ module Google
196
209
  #
197
210
  def partition_query sql, params: nil, types: nil,
198
211
  partition_size_bytes: nil, max_partitions: nil,
199
- query_options: nil
212
+ query_options: nil, call_options: nil
200
213
  ensure_session!
201
214
 
202
215
  params, types = Convert.to_input_params_and_types params, types
@@ -204,10 +217,11 @@ module Google
204
217
  results = session.partition_query \
205
218
  sql, tx_selector, params: params, types: types,
206
219
  partition_size_bytes: partition_size_bytes,
207
- max_partitions: max_partitions
220
+ max_partitions: max_partitions,
221
+ call_options: call_options
208
222
  results.partitions.map do |grpc|
209
223
  # Convert partition protos to execute sql request protos
210
- execute_sql_grpc = Google::Spanner::V1::ExecuteSqlRequest.new(
224
+ execute_sql_grpc = V1::ExecuteSqlRequest.new(
211
225
  {
212
226
  session: session.path,
213
227
  sql: sql,
@@ -248,6 +262,19 @@ module Google
248
262
  # partitions to return. For example, this may be set to the number of
249
263
  # workers available. This is only a hint and may provide different
250
264
  # results based on the request.
265
+ # @param [Hash] call_options A hash of values to specify the custom
266
+ # call options, e.g., timeout, retries, etc. Call options are
267
+ # optional. The following settings can be provided:
268
+ #
269
+ # * `:timeout` (Numeric) A numeric value of custom timeout in seconds
270
+ # that overrides the default setting.
271
+ # * `:retry_policy` (Hash) A hash of values that overrides the default
272
+ # setting of retry policy with the following keys:
273
+ # * `:initial_delay` (`Numeric`) - The initial delay in seconds.
274
+ # * `:max_delay` (`Numeric`) - The max delay in seconds.
275
+ # * `:multiplier` (`Numeric`) - The incremental backoff multiplier.
276
+ # * `:retry_codes` (`Array<String>`) - The error codes that should
277
+ # trigger a retry.
251
278
  #
252
279
  # @return [Array<Google::Cloud::Spanner::Partition>] The partitions
253
280
  # created by the read partition.
@@ -268,7 +295,8 @@ module Google
268
295
  # batch_snapshot.close
269
296
  #
270
297
  def partition_read table, columns, keys: nil, index: nil,
271
- partition_size_bytes: nil, max_partitions: nil
298
+ partition_size_bytes: nil, max_partitions: nil,
299
+ call_options: nil
272
300
  ensure_session!
273
301
 
274
302
  columns = Array(columns).map(&:to_s)
@@ -278,11 +306,12 @@ module Google
278
306
  table, columns, tx_selector,
279
307
  keys: keys, index: index,
280
308
  partition_size_bytes: partition_size_bytes,
281
- max_partitions: max_partitions
309
+ max_partitions: max_partitions,
310
+ call_options: call_options
282
311
 
283
312
  results.partitions.map do |grpc|
284
313
  # Convert partition protos to read request protos
285
- read_grpc = Google::Spanner::V1::ReadRequest.new(
314
+ read_grpc = V1::ReadRequest.new(
286
315
  {
287
316
  session: session.path,
288
317
  table: table,
@@ -304,6 +333,19 @@ module Google
304
333
  #
305
334
  # @param [Google::Cloud::Spanner::Partition] partition The partition to
306
335
  # be executed.
336
+ # @param [Hash] call_options A hash of values to specify the custom
337
+ # call options, e.g., timeout, retries, etc. Call options are
338
+ # optional. The following settings can be provided:
339
+ #
340
+ # * `:timeout` (Numeric) A numeric value of custom timeout in seconds
341
+ # that overrides the default setting.
342
+ # * `:retry_policy` (Hash) A hash of values that overrides the default
343
+ # setting of retry policy with the following keys:
344
+ # * `:initial_delay` (`Numeric`) - The initial delay in seconds.
345
+ # * `:max_delay` (`Numeric`) - The max delay in seconds.
346
+ # * `:multiplier` (`Numeric`) - The incremental backoff multiplier.
347
+ # * `:retry_codes` (`Array<String>`) - The error codes that should
348
+ # trigger a retry.
307
349
  #
308
350
  # @example
309
351
  # require "google/cloud/spanner"
@@ -320,7 +362,7 @@ module Google
320
362
  #
321
363
  # batch_snapshot.close
322
364
  #
323
- def execute_partition partition
365
+ def execute_partition partition, call_options: nil
324
366
  ensure_session!
325
367
 
326
368
  partition = Partition.load partition unless partition.is_a? Partition
@@ -329,10 +371,11 @@ module Google
329
371
  # TODO: raise if session.path != partition.session
330
372
  # TODO: raise if grpc.transaction != partition.transaction
331
373
 
374
+ opts = { call_options: call_options }
332
375
  if partition.execute?
333
- execute_partition_query partition
376
+ execute_partition_query partition, opts
334
377
  elsif partition.read?
335
- execute_partition_read partition
378
+ execute_partition_read partition, opts
336
379
  end
337
380
  end
338
381
 
@@ -430,6 +473,19 @@ module Google
430
473
  # * `:optimizer_version` (String) The version of optimizer to use.
431
474
  # Empty to use database default. "latest" to use the latest
432
475
  # available optimizer version.
476
+ # @param [Hash] call_options A hash of values to specify the custom
477
+ # call options, e.g., timeout, retries, etc. Call options are
478
+ # optional. The following settings can be provided:
479
+ #
480
+ # * `:timeout` (Numeric) A numeric value of custom timeout in seconds
481
+ # that overrides the default setting.
482
+ # * `:retry_policy` (Hash) A hash of values that overrides the default
483
+ # setting of retry policy with the following keys:
484
+ # * `:initial_delay` (`Numeric`) - The initial delay in seconds.
485
+ # * `:max_delay` (`Numeric`) - The max delay in seconds.
486
+ # * `:multiplier` (`Numeric`) - The incremental backoff multiplier.
487
+ # * `:retry_codes` (`Array<String>`) - The error codes that should
488
+ # trigger a retry.
433
489
  #
434
490
  # @return [Google::Cloud::Spanner::Results] The results of the query
435
491
  # execution.
@@ -549,14 +605,40 @@ module Google
549
605
  # puts "User #{row[:id]} is #{row[:name]}"
550
606
  # end
551
607
  #
552
- def execute_query sql, params: nil, types: nil, query_options: nil
608
+ # @example Query using custom timeout and retry policy:
609
+ # require "google/cloud/spanner"
610
+ #
611
+ # spanner = Google::Cloud::Spanner.new
612
+ # batch_client = spanner.batch_client "my-instance", "my-database"
613
+ # batch_snapshot = batch_client.batch_snapshot
614
+ #
615
+ # timeout = 30.0
616
+ # retry_policy = {
617
+ # initial_delay: 0.25,
618
+ # max_delay: 32.0,
619
+ # multiplier: 1.3,
620
+ # retry_codes: ["UNAVAILABLE"]
621
+ # }
622
+ # call_options = { timeout: timeout, retry_policy: retry_policy }
623
+ #
624
+ # results = batch_snapshot.execute_query \
625
+ # "SELECT * FROM users",
626
+ # call_options: call_options
627
+ #
628
+ # results.rows.each do |row|
629
+ # puts "User #{row[:id]} is #{row[:name]}"
630
+ # end
631
+ #
632
+ def execute_query sql, params: nil, types: nil, query_options: nil,
633
+ call_options: nil
553
634
  ensure_session!
554
635
 
555
636
  params, types = Convert.to_input_params_and_types params, types
556
637
 
557
638
  session.execute_query sql, params: params, types: types,
558
639
  transaction: tx_selector,
559
- query_options: query_options
640
+ query_options: query_options,
641
+ call_options: call_options
560
642
  end
561
643
  alias execute execute_query
562
644
  alias query execute_query
@@ -578,6 +660,19 @@ module Google
578
660
  # Optional.
579
661
  # @param [Integer] limit If greater than zero, no more than this number
580
662
  # of rows will be returned. The default is no limit.
663
+ # @param [Hash] call_options A hash of values to specify the custom
664
+ # call options, e.g., timeout, retries, etc. Call options are
665
+ # optional. The following settings can be provided:
666
+ #
667
+ # * `:timeout` (Numeric) A numeric value of custom timeout in seconds
668
+ # that overrides the default setting.
669
+ # * `:retry_policy` (Hash) A hash of values that overrides the default
670
+ # setting of retry policy with the following keys:
671
+ # * `:initial_delay` (`Numeric`) - The initial delay in seconds.
672
+ # * `:max_delay` (`Numeric`) - The max delay in seconds.
673
+ # * `:multiplier` (`Numeric`) - The incremental backoff multiplier.
674
+ # * `:retry_codes` (`Array<String>`) - The error codes that should
675
+ # trigger a retry.
581
676
  #
582
677
  # @return [Google::Cloud::Spanner::Results] The results of the read
583
678
  # operation.
@@ -595,14 +690,16 @@ module Google
595
690
  # puts "User #{row[:id]} is #{row[:name]}"
596
691
  # end
597
692
  #
598
- def read table, columns, keys: nil, index: nil, limit: nil
693
+ def read table, columns, keys: nil, index: nil, limit: nil,
694
+ call_options: nil
599
695
  ensure_session!
600
696
 
601
697
  columns = Array(columns).map(&:to_s)
602
698
  keys = Convert.to_key_set keys
603
699
 
604
700
  session.read table, columns, keys: keys, index: index, limit: limit,
605
- transaction: tx_selector
701
+ transaction: tx_selector,
702
+ call_options: call_options
606
703
  end
607
704
 
608
705
  ##
@@ -663,17 +760,15 @@ module Google
663
760
  def self.load data, service: nil, query_options: nil
664
761
  data = JSON.parse data, symbolize_names: true unless data.is_a? Hash
665
762
 
666
- session_grpc = Google::Spanner::V1::Session.decode \
667
- Base64.decode64(data[:session])
668
- transaction_grpc = Google::Spanner::V1::Transaction.decode \
669
- Base64.decode64(data[:transaction])
763
+ session_grpc = V1::Session.decode Base64.decode64(data[:session])
764
+ transaction_grpc = V1::Transaction.decode Base64.decode64(data[:transaction])
670
765
 
671
766
  from_grpc transaction_grpc, Session.from_grpc(session_grpc, service, query_options: query_options)
672
767
  end
673
768
 
674
769
  ##
675
770
  # @private Creates a new BatchSnapshot instance from a
676
- # Google::Spanner::V1::Transaction.
771
+ # `Google::Cloud::Spanner::V1::Transaction`.
677
772
  def self.from_grpc grpc, session
678
773
  new grpc, session
679
774
  end
@@ -682,7 +777,7 @@ module Google
682
777
 
683
778
  # The TransactionSelector to be used for queries
684
779
  def tx_selector
685
- Google::Spanner::V1::TransactionSelector.new id: transaction_id
780
+ V1::TransactionSelector.new id: transaction_id
686
781
  end
687
782
 
688
783
  ##
@@ -692,7 +787,7 @@ module Google
692
787
  raise "Must have active connection to service" unless session
693
788
  end
694
789
 
695
- def execute_partition_query partition
790
+ def execute_partition_query partition, call_options: nil
696
791
  query_options = partition.execute.query_options
697
792
  query_options = query_options.to_h unless query_options.nil?
698
793
  session.execute_query \
@@ -701,16 +796,18 @@ module Google
701
796
  types: partition.execute.param_types.to_h,
702
797
  transaction: partition.execute.transaction,
703
798
  partition_token: partition.execute.partition_token,
704
- query_options: query_options
799
+ query_options: query_options,
800
+ call_options: call_options
705
801
  end
706
802
 
707
- def execute_partition_read partition
803
+ def execute_partition_read partition, call_options: nil
708
804
  session.read partition.read.table,
709
805
  partition.read.columns.to_a,
710
806
  keys: partition.read.key_set,
711
807
  index: partition.read.index,
712
808
  transaction: partition.read.transaction,
713
- partition_token: partition.read.partition_token
809
+ partition_token: partition.read.partition_token,
810
+ call_options: call_options
714
811
  end
715
812
  end
716
813
  end