google-cloud-bigquery 1.18.1 → 1.19.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1217,8 +1217,7 @@ module Google
1217
1217
  def data token: nil, max: nil, start: nil
1218
1218
  ensure_service!
1219
1219
  reload! unless resource_full?
1220
- options = { token: token, max: max, start: start }
1221
- data_json = service.list_tabledata dataset_id, table_id, options
1220
+ data_json = service.list_tabledata dataset_id, table_id, token: token, max: max, start: start
1222
1221
  Data.from_gapi_json data_json, gapi, nil, service
1223
1222
  end
1224
1223
 
@@ -1978,12 +1977,13 @@ module Google
1978
1977
  #
1979
1978
  # @param [Hash, Array<Hash>] rows A hash object or array of hash objects
1980
1979
  # containing the data. Required.
1981
- # @param [Array<String>] insert_ids A unique ID for each row. BigQuery
1982
- # uses this property to detect duplicate insertion requests on a
1983
- # best-effort basis. For more information, see [data
1984
- # consistency](https://cloud.google.com/bigquery/streaming-data-into-bigquery#dataconsistency).
1985
- # Optional. If not provided, the client library will assign a UUID to
1986
- # each row before the request is sent.
1980
+ # @param [Array<String|Symbol>, Symbol] insert_ids A unique ID for each row. BigQuery uses this property to
1981
+ # detect duplicate insertion requests on a best-effort basis. For more information, see [data
1982
+ # consistency](https://cloud.google.com/bigquery/streaming-data-into-bigquery#dataconsistency). Optional. If
1983
+ # not provided, the client library will assign a UUID to each row before the request is sent.
1984
+ #
1985
+ # The value `:skip` can be provided to skip the generation of IDs for all rows, or to skip the generation of an
1986
+ # ID for a specific row in the array.
1987
1987
  # @param [Boolean] skip_invalid Insert all valid rows of a request, even
1988
1988
  # if invalid rows exist. The default value is `false`, which causes
1989
1989
  # the entire request to fail if any invalid rows exist.
@@ -2023,12 +2023,14 @@ module Google
2023
2023
  #
2024
2024
  def insert rows, insert_ids: nil, skip_invalid: nil, ignore_unknown: nil
2025
2025
  rows = [rows] if rows.is_a? Hash
2026
+ raise ArgumentError, "No rows provided" if rows.empty?
2027
+
2028
+ insert_ids = Array.new(rows.count) { :skip } if insert_ids == :skip
2026
2029
  insert_ids = Array insert_ids
2027
2030
  if insert_ids.count.positive? && insert_ids.count != rows.count
2028
2031
  raise ArgumentError, "insert_ids must be the same size as rows"
2029
2032
  end
2030
- rows = [rows] if rows.is_a? Hash
2031
- raise ArgumentError, "No rows provided" if rows.empty?
2033
+
2032
2034
  ensure_service!
2033
2035
  options = { skip_invalid: skip_invalid, ignore_unknown: ignore_unknown, insert_ids: insert_ids }
2034
2036
  gapi = service.insert_tabledata dataset_id, table_id, rows, options
@@ -2162,7 +2164,7 @@ module Google
2162
2164
  # table = dataset.table "my_table", skip_lookup: true
2163
2165
  # table.exists? # true
2164
2166
  #
2165
- def exists? force: nil
2167
+ def exists? force: false
2166
2168
  return gapi_exists? if force
2167
2169
  # If we have a value, return it
2168
2170
  return @exists unless @exists.nil?
@@ -2276,7 +2278,7 @@ module Google
2276
2278
  end
2277
2279
 
2278
2280
  ##
2279
- # @private New lazy Table object without making an HTTP request.
2281
+ # @private New lazy Table object without making an HTTP request, for use with the skip_lookup option.
2280
2282
  def self.new_reference project_id, dataset_id, table_id, service
2281
2283
  raise ArgumentError, "dataset_id is required" unless dataset_id
2282
2284
  raise ArgumentError, "table_id is required" unless table_id
@@ -2505,14 +2507,14 @@ module Google
2505
2507
  end
2506
2508
 
2507
2509
  ##
2508
- # Yielded to a block to accumulate changes for a patch request.
2510
+ # Yielded to a block to accumulate changes for a create request. See {Dataset#create_table}.
2509
2511
  class Updater < Table
2510
2512
  ##
2511
- # A list of attributes that were updated.
2513
+ # @private A list of attributes that were updated.
2512
2514
  attr_reader :updates
2513
2515
 
2514
2516
  ##
2515
- # Create an Updater object.
2517
+ # @private Create an Updater object.
2516
2518
  def initialize gapi
2517
2519
  @updates = []
2518
2520
  @gapi = gapi
@@ -2955,8 +2957,97 @@ module Google
2955
2957
  schema.record name, description: description, mode: mode, &block
2956
2958
  end
2957
2959
 
2960
+ # rubocop:disable Style/MethodDefParentheses
2961
+
2962
+ ##
2963
+ # @raise [RuntimeError] not implemented
2964
+ def data(*)
2965
+ raise "not implemented in #{self.class}"
2966
+ end
2967
+
2968
+ ##
2969
+ # @raise [RuntimeError] not implemented
2970
+ def copy_job(*)
2971
+ raise "not implemented in #{self.class}"
2972
+ end
2973
+
2958
2974
  ##
2959
- # Make sure any access changes are saved
2975
+ # @raise [RuntimeError] not implemented
2976
+ def copy(*)
2977
+ raise "not implemented in #{self.class}"
2978
+ end
2979
+
2980
+ ##
2981
+ # @raise [RuntimeError] not implemented
2982
+ def extract_job(*)
2983
+ raise "not implemented in #{self.class}"
2984
+ end
2985
+
2986
+ ##
2987
+ # @raise [RuntimeError] not implemented
2988
+ def extract(*)
2989
+ raise "not implemented in #{self.class}"
2990
+ end
2991
+
2992
+ ##
2993
+ # @raise [RuntimeError] not implemented
2994
+ def load_job(*)
2995
+ raise "not implemented in #{self.class}"
2996
+ end
2997
+
2998
+ ##
2999
+ # @raise [RuntimeError] not implemented
3000
+ def load(*)
3001
+ raise "not implemented in #{self.class}"
3002
+ end
3003
+
3004
+ ##
3005
+ # @raise [RuntimeError] not implemented
3006
+ def insert(*)
3007
+ raise "not implemented in #{self.class}"
3008
+ end
3009
+
3010
+ ##
3011
+ # @raise [RuntimeError] not implemented
3012
+ def insert_async(*)
3013
+ raise "not implemented in #{self.class}"
3014
+ end
3015
+
3016
+ ##
3017
+ # @raise [RuntimeError] not implemented
3018
+ def delete
3019
+ raise "not implemented in #{self.class}"
3020
+ end
3021
+
3022
+ ##
3023
+ # @raise [RuntimeError] not implemented
3024
+ def query_job(*)
3025
+ raise "not implemented in #{self.class}"
3026
+ end
3027
+
3028
+ ##
3029
+ # @raise [RuntimeError] not implemented
3030
+ def query(*)
3031
+ raise "not implemented in #{self.class}"
3032
+ end
3033
+
3034
+ ##
3035
+ # @raise [RuntimeError] not implemented
3036
+ def external(*)
3037
+ raise "not implemented in #{self.class}"
3038
+ end
3039
+
3040
+ ##
3041
+ # @raise [RuntimeError] not implemented
3042
+ def reload!
3043
+ raise "not implemented in #{self.class}"
3044
+ end
3045
+ alias refresh! reload!
3046
+
3047
+ # rubocop:enable Style/MethodDefParentheses
3048
+
3049
+ ##
3050
+ # @private Make sure any access changes are saved
2960
3051
  def check_for_mutated_schema!
2961
3052
  return if @schema.nil?
2962
3053
  return unless @schema.changed?
@@ -2964,6 +3055,8 @@ module Google
2964
3055
  patch_gapi! :schema
2965
3056
  end
2966
3057
 
3058
+ ##
3059
+ # @private
2967
3060
  def to_gapi
2968
3061
  check_for_mutated_schema!
2969
3062
  @gapi
@@ -113,12 +113,13 @@ module Google
113
113
  #
114
114
  # @param [Hash, Array<Hash>] rows A hash object or array of hash
115
115
  # objects containing the data.
116
- # @param [Array<String>] insert_ids A unique ID for each row. BigQuery
117
- # uses this property to detect duplicate insertion requests on a
118
- # best-effort basis. For more information, see [data
119
- # consistency](https://cloud.google.com/bigquery/streaming-data-into-bigquery#dataconsistency).
120
- # Optional. If not provided, the client library will assign a UUID
121
- # to each row before the request is sent.
116
+ # @param [Array<String|Symbol>, Symbol] insert_ids A unique ID for each row. BigQuery uses this property to
117
+ # detect duplicate insertion requests on a best-effort basis. For more information, see [data
118
+ # consistency](https://cloud.google.com/bigquery/streaming-data-into-bigquery#dataconsistency). Optional. If
119
+ # not provided, the client library will assign a UUID to each row before the request is sent.
120
+ #
121
+ # The value `:skip` can be provided to skip the generation of IDs for all rows, or to skip the generation of
122
+ # an ID for a specific row in the array.
122
123
  #
123
124
  def insert rows, insert_ids: nil
124
125
  return nil if rows.nil?
@@ -224,10 +225,14 @@ module Google
224
225
 
225
226
  def validate_insert_args rows, insert_ids
226
227
  rows = [rows] if rows.is_a? Hash
228
+ raise ArgumentError, "No rows provided" if rows.empty?
229
+
230
+ insert_ids = Array.new(rows.count) { :skip } if insert_ids == :skip
227
231
  insert_ids = Array insert_ids
228
232
  if insert_ids.count.positive? && insert_ids.count != rows.count
229
233
  raise ArgumentError, "insert_ids must be the same size as rows"
230
234
  end
235
+
231
236
  [rows, insert_ids]
232
237
  end
233
238
 
@@ -332,8 +337,13 @@ module Google
332
337
  end
333
338
 
334
339
  def addl_bytes_for json_row, insert_id
335
- # "{\"insertId\":\"\",\"json\":},".bytesize #=> 24
336
- 24 + json_row.to_json.bytesize + insert_id.bytesize
340
+ if insert_id == :skip
341
+ # "{\"json\":},".bytesize #=> 10
342
+ 10 + json_row.to_json.bytesize
343
+ else
344
+ # "{\"insertId\":\"\",\"json\":},".bytesize #=> 24
345
+ 24 + json_row.to_json.bytesize + insert_id.bytesize
346
+ end
337
347
  end
338
348
  end
339
349
 
@@ -78,8 +78,7 @@ module Google
78
78
  def next
79
79
  return nil unless next?
80
80
  ensure_service!
81
- options = { token: token, max: @max }
82
- gapi = @service.list_tables @dataset_id, options
81
+ gapi = @service.list_tables @dataset_id, token: token, max: @max
83
82
  self.class.from_gapi gapi, @service, @dataset_id, @max
84
83
  end
85
84
 
@@ -16,7 +16,7 @@
16
16
  module Google
17
17
  module Cloud
18
18
  module Bigquery
19
- VERSION = "1.18.1".freeze
19
+ VERSION = "1.19.0".freeze
20
20
  end
21
21
  end
22
22
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: google-cloud-bigquery
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.18.1
4
+ version: 1.19.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Moore
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2019-12-20 00:00:00.000000000 Z
12
+ date: 2020-02-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: concurrent-ruby
@@ -240,6 +240,7 @@ files:
240
240
  - TROUBLESHOOTING.md
241
241
  - lib/google-cloud-bigquery.rb
242
242
  - lib/google/cloud/bigquery.rb
243
+ - lib/google/cloud/bigquery/argument.rb
243
244
  - lib/google/cloud/bigquery/convert.rb
244
245
  - lib/google/cloud/bigquery/copy_job.rb
245
246
  - lib/google/cloud/bigquery/credentials.rb
@@ -259,6 +260,8 @@ files:
259
260
  - lib/google/cloud/bigquery/project.rb
260
261
  - lib/google/cloud/bigquery/project/list.rb
261
262
  - lib/google/cloud/bigquery/query_job.rb
263
+ - lib/google/cloud/bigquery/routine.rb
264
+ - lib/google/cloud/bigquery/routine/list.rb
262
265
  - lib/google/cloud/bigquery/schema.rb
263
266
  - lib/google/cloud/bigquery/schema/field.rb
264
267
  - lib/google/cloud/bigquery/service.rb