google-cloud-bigquery 1.18.0 → 1.21.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a73d3045289c56feffa2def6b2f46764fa271e617629253b01e43bd689017f43
4
- data.tar.gz: ac4730e78ce2a9734bcfc9c8adc5bc87576e2cbd9171e59c970cf54972c7c93f
3
+ metadata.gz: 66fb05be59bdce437c28d89670548abba36c23a00df0bbe175983156f7ef4677
4
+ data.tar.gz: 73fdc5465df51fe3e3a2f554fa6540d5ffeb0890146eee2b97e60669abb2a020
5
5
  SHA512:
6
- metadata.gz: 3b792a52259418fd31e3507723702b3d5934289e34bdc326b844f85b5495b57d6af208ccf4043f70c3ec3e5492691e03aa7ffadc92c223035b2a82dc2730b5ae
7
- data.tar.gz: 83eaa86026274ea0d0da3ee86770e0f10883510520fc35f3058bb37b5df09eb4f31f13db4fd5908f2056999128204bc4ab75606d4e4bffc1acd30dff7e334506
6
+ metadata.gz: 3c0857826bc2c7394e9d9fa8ffe4eee947bbd5ed57f9ad636e34718e0b266c7091e4ddd2734619874b7624d1b939e62f7f43a74f6fe944d33b057966dafea188
7
+ data.tar.gz: 685a245183d53e26bfc133f6475b949b00ffc33e25eb00dfa1a52e557525bc9e6e61522d435c2398058c188005f535e5b49f79d28e29b8d8d47cb995c5561bea
@@ -1,5 +1,53 @@
1
1
  # Release History
2
2
 
3
+ ### 1.21.1 / 2020-05-28
4
+
5
+ #### Documentation
6
+
7
+ * Fix a few broken links
8
+
9
+ ### 1.21.0 / 2020-03-31
10
+
11
+ #### Features
12
+
13
+ * Add Job#parent_job_id and Job#script_statistics
14
+ * Add parent_job to Project#jobs
15
+ * Add Job#num_child_jobs
16
+ * Add Job#parent_job_id
17
+ * Add Job#script_statistics
18
+
19
+ ### 1.20.0 / 2020-03-11
20
+
21
+ #### Features
22
+
23
+ * Add Range Partitioning
24
+ * Add range partitioning methods to Table and Table::Updater
25
+ * Add range partitioning methods to LoadJob
26
+ * Add range partitioning methods to QueryJob
27
+
28
+ ### 1.19.0 / 2020-02-11
29
+
30
+ #### Features
31
+
32
+ * Add Routine
33
+ * Add Dataset#create_routine
34
+ * Add Argument
35
+ * Update StandardSql classes to expose public initializer
36
+ * Add Data#ddl_target_routine and QueryJob#ddl_target_routine
37
+ * Allow row inserts to skip insert_id generation
38
+ * Streaming inserts using an insert_id are not able to be inserted as fast as inserts without an insert_id
39
+ * Add the ability for users to skip insert_id generation in order to speed up the inserts
40
+ * The default behavior continues to generate insert_id values for each row inserted
41
+ * Add yield documentation for Dataset#insert
42
+
43
+ ### 1.18.1 / 2019-12-18
44
+
45
+ #### Bug Fixes
46
+
47
+ * Fix MonitorMixin usage on Ruby 2.7
48
+ * Ruby 2.7 will error if new_cond is called before super().
49
+ * Make the call to super() be the first call in initialize
50
+
3
51
  ### 1.18.0 / 2019-11-06
4
52
 
5
53
  #### Features
@@ -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+bigquery
32
28
 
33
- [gh-search-ruby]: https://github.com/googlecloudplatform/google-cloud-ruby/issues?q=label%3A%22api%3A+bigquery%22
34
-
35
- [gh-ruby]: https://github.com/googlecloudplatform/google-cloud-ruby/issues/new
29
+ [gh-search-ruby]: https://github.com/googleapis/google-cloud-ruby/issues?q=label%3A%22api%3A+bigquery%22
36
30
 
37
- [slack-ruby]: https://gcp-slack.appspot.com/
31
+ [gh-ruby]: https://github.com/googleapis/google-cloud-ruby/issues/new
@@ -0,0 +1,197 @@
1
+ # Copyright 2020 Google LLC
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
+ # https://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
+
16
+ require "google/cloud/bigquery/standard_sql"
17
+
18
+ module Google
19
+ module Cloud
20
+ module Bigquery
21
+ ##
22
+ # # Argument
23
+ #
24
+ # Input/output argument of a function or a stored procedure. See {Routine}.
25
+ #
26
+ # @example
27
+ # require "google/cloud/bigquery"
28
+ #
29
+ # bigquery = Google::Cloud::Bigquery.new
30
+ # dataset = bigquery.dataset "my_dataset"
31
+ # routine = dataset.create_routine "my_routine" do |r|
32
+ # r.routine_type = "SCALAR_FUNCTION"
33
+ # r.language = :SQL
34
+ # r.body = "(SELECT SUM(IF(elem.name = \"foo\",elem.val,null)) FROM UNNEST(arr) AS elem)"
35
+ # r.arguments = [
36
+ # Google::Cloud::Bigquery::Argument.new(
37
+ # name: "arr",
38
+ # argument_kind: "FIXED_TYPE",
39
+ # data_type: Google::Cloud::Bigquery::StandardSql::DataType.new(
40
+ # type_kind: "ARRAY",
41
+ # array_element_type: Google::Cloud::Bigquery::StandardSql::DataType.new(
42
+ # type_kind: "STRUCT",
43
+ # struct_type: Google::Cloud::Bigquery::StandardSql::StructType.new(
44
+ # fields: [
45
+ # Google::Cloud::Bigquery::StandardSql::Field.new(
46
+ # name: "name",
47
+ # type: Google::Cloud::Bigquery::StandardSql::DataType.new(type_kind: "STRING")
48
+ # ),
49
+ # Google::Cloud::Bigquery::StandardSql::Field.new(
50
+ # name: "val",
51
+ # type: Google::Cloud::Bigquery::StandardSql::DataType.new(type_kind: "INT64")
52
+ # )
53
+ # ]
54
+ # )
55
+ # )
56
+ # )
57
+ # )
58
+ # ]
59
+ # end
60
+ #
61
+ class Argument
62
+ ##
63
+ # Creates a new, immutable Argument object.
64
+ #
65
+ # @overload initialize(data_type, kind, mode, name)
66
+ # @param [StandardSql::DataType, String] data_type The data type of the argument. Required unless
67
+ # {#argument_kind} is `ANY_TYPE`.
68
+ # @param [String] argument_kind The kind of argument. Optional. Defaults to `FIXED_TYPE`.
69
+ #
70
+ # * `FIXED_TYPE` - The argument is a variable with fully specified type, which can be a struct or an array,
71
+ # but not a table.
72
+ # * `ANY_TYPE` - The argument is any type, including struct or array, but not a table.
73
+ #
74
+ # To be added: `FIXED_TABLE`, `ANY_TABLE`.
75
+ # @param [String] mode Specifies whether the argument is input or output. Optional. Can be set for procedures
76
+ # only.
77
+ #
78
+ # * IN - The argument is input-only.
79
+ # * OUT - The argument is output-only.
80
+ # * INOUT - The argument is both an input and an output.
81
+ # @param [String] name The name of the argument. Optional. Can be absent for a function return argument.
82
+ #
83
+ def initialize **kwargs
84
+ kwargs[:data_type] = StandardSql::DataType.gapi_from_string_or_data_type kwargs[:data_type]
85
+ @gapi = Google::Apis::BigqueryV2::Argument.new(**kwargs)
86
+ end
87
+
88
+ ##
89
+ # The data type of the argument. Required unless {#argument_kind} is `ANY_TYPE`.
90
+ #
91
+ # @return [StandardSql::DataType] The data type.
92
+ #
93
+ def data_type
94
+ StandardSql::DataType.from_gapi @gapi.data_type
95
+ end
96
+
97
+ ##
98
+ # The kind of argument. Optional. Defaults to `FIXED_TYPE`.
99
+ #
100
+ # * `FIXED_TYPE` - The argument is a variable with fully specified type, which can be a struct or an array, but
101
+ # not a table.
102
+ # * `ANY_TYPE` - The argument is any type, including struct or array, but not a table.
103
+ #
104
+ # To be added: `FIXED_TABLE`, `ANY_TABLE`.
105
+ #
106
+ # @return [String] The upper case kind of argument.
107
+ #
108
+ def argument_kind
109
+ @gapi.argument_kind
110
+ end
111
+
112
+ ##
113
+ # Checks if the value of {#argument_kind} is `FIXED_TYPE`. The default is `true`.
114
+ #
115
+ # @return [Boolean] `true` when `FIXED_TYPE`, `false` otherwise.
116
+ #
117
+ def fixed_type?
118
+ return true if @gapi.argument_kind.nil?
119
+ @gapi.argument_kind == "FIXED_TYPE"
120
+ end
121
+
122
+ ##
123
+ # Checks if the value of {#argument_kind} is `ANY_TYPE`. The default is `false`.
124
+ #
125
+ # @return [Boolean] `true` when `ANY_TYPE`, `false` otherwise.
126
+ #
127
+ def any_type?
128
+ @gapi.argument_kind == "ANY_TYPE"
129
+ end
130
+
131
+ ##
132
+ # Specifies whether the argument is input or output. Optional. Can be set for procedures only.
133
+ #
134
+ # * IN - The argument is input-only.
135
+ # * OUT - The argument is output-only.
136
+ # * INOUT - The argument is both an input and an output.
137
+ #
138
+ # @return [String] The upper case input/output mode of the argument.
139
+ #
140
+ def mode
141
+ @gapi.mode
142
+ end
143
+
144
+ ##
145
+ # Checks if the value of {#mode} is `IN`. Can be set for procedures only. The default is `false`.
146
+ #
147
+ # @return [Boolean] `true` when `IN`, `false` otherwise.
148
+ #
149
+ def in?
150
+ @gapi.mode == "IN"
151
+ end
152
+
153
+ ##
154
+ # Checks if the value of {#mode} is `OUT`. Can be set for procedures only. The default is `false`.
155
+ #
156
+ # @return [Boolean] `true` when `OUT`, `false` otherwise.
157
+ #
158
+ def out?
159
+ @gapi.mode == "OUT"
160
+ end
161
+
162
+ ##
163
+ # Checks if the value of {#mode} is `INOUT`. Can be set for procedures only. The default is `false`.
164
+ #
165
+ # @return [Boolean] `true` when `INOUT`, `false` otherwise.
166
+ #
167
+ def inout?
168
+ @gapi.mode == "INOUT"
169
+ end
170
+
171
+ ##
172
+ #
173
+ # The name of the argument. Optional. Can be absent for a function return argument.
174
+ #
175
+ # @return [String] The name of the argument.
176
+ #
177
+ def name
178
+ @gapi.name
179
+ end
180
+
181
+ ##
182
+ # @private
183
+ def to_gapi
184
+ @gapi
185
+ end
186
+
187
+ ##
188
+ # @private New Argument from a Google API Client object.
189
+ def self.from_gapi gapi
190
+ new.tap do |a|
191
+ a.instance_variable_set :@gapi, gapi
192
+ end
193
+ end
194
+ end
195
+ end
196
+ end
197
+ end
@@ -152,7 +152,7 @@ module Google
152
152
  #
153
153
  # @return [Google::Cloud::Bigquery::CopyJob::Updater] A job
154
154
  # configuration object for setting copy options.
155
- def self.from_options service, source, target, options = {}
155
+ def self.from_options service, source, target, options
156
156
  job_ref = service.job_ref_from options[:job_id], options[:prefix]
157
157
  copy_cfg = Google::Apis::BigqueryV2::JobConfigurationTableCopy.new(
158
158
  source_table: source,
@@ -284,6 +284,23 @@ module Google
284
284
  @gapi.configuration.update! labels: value
285
285
  end
286
286
 
287
+ def cancel
288
+ raise "not implemented in #{self.class}"
289
+ end
290
+
291
+ def rerun!
292
+ raise "not implemented in #{self.class}"
293
+ end
294
+
295
+ def reload!
296
+ raise "not implemented in #{self.class}"
297
+ end
298
+ alias refresh! reload!
299
+
300
+ def wait_until_done!
301
+ raise "not implemented in #{self.class}"
302
+ end
303
+
287
304
  ##
288
305
  # @private Returns the Google API client library version of this job.
289
306
  #
@@ -316,6 +316,21 @@ module Google
316
316
  job_gapi&.statistics&.query&.ddl_operation_performed
317
317
  end
318
318
 
319
+ ##
320
+ # The DDL target routine, in reference state. (See {Routine#reference?}.)
321
+ # Present only for `CREATE/DROP FUNCTION/PROCEDURE` queries. (See
322
+ # {#statement_type}.)
323
+ #
324
+ # @return [Google::Cloud::Bigquery::Routine, nil] The DDL target routine, in
325
+ # reference state.
326
+ #
327
+ def ddl_target_routine
328
+ ensure_service!
329
+ routine = job_gapi&.statistics&.query&.ddl_target_routine
330
+ return nil if routine.nil?
331
+ Google::Cloud::Bigquery::Routine.new_reference_from_gapi routine, service
332
+ end
333
+
319
334
  ##
320
335
  # The DDL target table, in reference state. (See {Table#reference?}.)
321
336
  # Present only for `CREATE/DROP TABLE/VIEW` queries. (See
@@ -18,6 +18,7 @@ require "google/cloud/errors"
18
18
  require "google/cloud/bigquery/service"
19
19
  require "google/cloud/bigquery/table"
20
20
  require "google/cloud/bigquery/model"
21
+ require "google/cloud/bigquery/routine"
21
22
  require "google/cloud/bigquery/external"
22
23
  require "google/cloud/bigquery/dataset/list"
23
24
  require "google/cloud/bigquery/dataset/access"
@@ -554,6 +555,40 @@ module Google
554
555
  # end
555
556
  # end
556
557
  #
558
+ # @example With time partitioning and clustering.
559
+ # require "google/cloud/bigquery"
560
+ #
561
+ # bigquery = Google::Cloud::Bigquery.new
562
+ # dataset = bigquery.dataset "my_dataset"
563
+ #
564
+ # table = dataset.create_table "my_table" do |t|
565
+ # t.schema do |schema|
566
+ # schema.timestamp "dob", mode: :required
567
+ # schema.string "first_name", mode: :required
568
+ # schema.string "last_name", mode: :required
569
+ # end
570
+ # t.time_partitioning_type = "DAY"
571
+ # t.time_partitioning_field = "dob"
572
+ # t.clustering_fields = ["last_name", "first_name"]
573
+ # end
574
+ #
575
+ # @example With range partitioning.
576
+ # require "google/cloud/bigquery"
577
+ #
578
+ # bigquery = Google::Cloud::Bigquery.new
579
+ # dataset = bigquery.dataset "my_dataset"
580
+ #
581
+ # table = dataset.create_table "my_table" do |t|
582
+ # t.schema do |schema|
583
+ # schema.integer "my_table_id", mode: :required
584
+ # schema.string "my_table_data", mode: :required
585
+ # end
586
+ # t.range_partitioning_field = "my_table_id"
587
+ # t.range_partitioning_start = 0
588
+ # t.range_partitioning_interval = 10
589
+ # t.range_partitioning_end = 100
590
+ # end
591
+ #
557
592
  # @!group Table
558
593
  #
559
594
  def create_table table_id, name: nil, description: nil
@@ -601,12 +636,20 @@ module Google
601
636
  # SQL](https://cloud.google.com/bigquery/docs/reference/legacy-sql)
602
637
  # dialect. Optional. The default value is false.
603
638
  # @param [Array<String>, String] udfs User-defined function resources
604
- # used in the query. May be either a code resource to load from a
605
- # Google Cloud Storage URI (`gs://bucket/path`), or an inline resource
639
+ # used in a legacy SQL query. May be either a code resource to load from
640
+ # a Google Cloud Storage URI (`gs://bucket/path`), or an inline resource
606
641
  # that contains code for a user-defined function (UDF). Providing an
607
642
  # inline code resource is equivalent to providing a URI for a file
608
- # containing the same code. See [User-Defined
609
- # Functions](https://cloud.google.com/bigquery/docs/reference/standard-sql/user-defined-functions).
643
+ # containing the same code.
644
+ #
645
+ # This parameter is used for defining User Defined Function (UDF)
646
+ # resources only when using legacy SQL. Users of standard SQL should
647
+ # leverage either DDL (e.g. `CREATE [TEMPORARY] FUNCTION ...`) or the
648
+ # Routines API to define UDF resources.
649
+ #
650
+ # For additional information on migrating, see: [Migrating to
651
+ # standard SQL - Differences in user-defined JavaScript
652
+ # functions](https://cloud.google.com/bigquery/docs/reference/standard-sql/migrating-from-legacy-sql#differences_in_user-defined_javascript_functions)
610
653
  #
611
654
  # @return [Google::Cloud::Bigquery::Table] A new table object.
612
655
  #
@@ -731,8 +774,7 @@ module Google
731
774
  #
732
775
  def tables token: nil, max: nil
733
776
  ensure_service!
734
- options = { token: token, max: max }
735
- gapi = service.list_tables dataset_id, options
777
+ gapi = service.list_tables dataset_id, token: token, max: max
736
778
  Table::List.from_gapi gapi, service, dataset_id, max
737
779
  end
738
780
 
@@ -817,6 +859,174 @@ module Google
817
859
  Model::List.from_gapi gapi, service, dataset_id, max
818
860
  end
819
861
 
862
+ ##
863
+ # Creates a new routine. The following attributes may be set in the yielded block:
864
+ # {Routine::Updater#routine_type=}, {Routine::Updater#language=}, {Routine::Updater#arguments=},
865
+ # {Routine::Updater#return_type=}, {Routine::Updater#imported_libraries=}, {Routine::Updater#body=}, and
866
+ # {Routine::Updater#description=}.
867
+ #
868
+ # @param [String] routine_id The ID of the routine. The ID must contain only
869
+ # letters (a-z, A-Z), numbers (0-9), or underscores (_). The maximum length
870
+ # is 256 characters.
871
+ # @yield [routine] A block for setting properties on the routine.
872
+ # @yieldparam [Google::Cloud::Bigquery::Routine::Updater] routine An updater to set additional properties on the
873
+ # routine.
874
+ #
875
+ # @return [Google::Cloud::Bigquery::Routine] A new routine object.
876
+ #
877
+ # @example
878
+ # require "google/cloud/bigquery"
879
+ #
880
+ # bigquery = Google::Cloud::Bigquery.new
881
+ # dataset = bigquery.dataset "my_dataset"
882
+ #
883
+ # routine = dataset.create_routine "my_routine" do |r|
884
+ # r.routine_type = "SCALAR_FUNCTION"
885
+ # r.language = "SQL"
886
+ # r.arguments = [
887
+ # Google::Cloud::Bigquery::Argument.new(name: "x", data_type: "INT64")
888
+ # ]
889
+ # r.body = "x * 3"
890
+ # r.description = "My routine description"
891
+ # end
892
+ #
893
+ # puts routine.routine_id
894
+ #
895
+ # @example Extended example:
896
+ # require "google/cloud/bigquery"
897
+ #
898
+ # bigquery = Google::Cloud::Bigquery.new
899
+ # dataset = bigquery.dataset "my_dataset"
900
+ # routine = dataset.create_routine "my_routine" do |r|
901
+ # r.routine_type = "SCALAR_FUNCTION"
902
+ # r.language = :SQL
903
+ # r.body = "(SELECT SUM(IF(elem.name = \"foo\",elem.val,null)) FROM UNNEST(arr) AS elem)"
904
+ # r.arguments = [
905
+ # Google::Cloud::Bigquery::Argument.new(
906
+ # name: "arr",
907
+ # argument_kind: "FIXED_TYPE",
908
+ # data_type: Google::Cloud::Bigquery::StandardSql::DataType.new(
909
+ # type_kind: "ARRAY",
910
+ # array_element_type: Google::Cloud::Bigquery::StandardSql::DataType.new(
911
+ # type_kind: "STRUCT",
912
+ # struct_type: Google::Cloud::Bigquery::StandardSql::StructType.new(
913
+ # fields: [
914
+ # Google::Cloud::Bigquery::StandardSql::Field.new(
915
+ # name: "name",
916
+ # type: Google::Cloud::Bigquery::StandardSql::DataType.new(type_kind: "STRING")
917
+ # ),
918
+ # Google::Cloud::Bigquery::StandardSql::Field.new(
919
+ # name: "val",
920
+ # type: Google::Cloud::Bigquery::StandardSql::DataType.new(type_kind: "INT64")
921
+ # )
922
+ # ]
923
+ # )
924
+ # )
925
+ # )
926
+ # )
927
+ # ]
928
+ # end
929
+ #
930
+ # @!group Routine
931
+ #
932
+ def create_routine routine_id
933
+ ensure_service!
934
+ new_tb = Google::Apis::BigqueryV2::Routine.new(
935
+ routine_reference: Google::Apis::BigqueryV2::RoutineReference.new(
936
+ project_id: project_id, dataset_id: dataset_id, routine_id: routine_id
937
+ )
938
+ )
939
+ updater = Routine::Updater.new new_tb
940
+
941
+ yield updater if block_given?
942
+
943
+ gapi = service.insert_routine dataset_id, updater.to_gapi
944
+ Routine.from_gapi gapi, service
945
+ end
946
+
947
+ ##
948
+ # Retrieves an existing routine by ID.
949
+ #
950
+ # @param [String] routine_id The ID of a routine.
951
+ # @param [Boolean] skip_lookup Optionally create just a local reference
952
+ # object without verifying that the resource exists on the BigQuery
953
+ # service. Calls made on this object will raise errors if the resource
954
+ # does not exist. Default is `false`. Optional.
955
+ #
956
+ # @return [Google::Cloud::Bigquery::Routine, nil] Returns `nil` if the
957
+ # routine does not exist.
958
+ #
959
+ # @example
960
+ # require "google/cloud/bigquery"
961
+ #
962
+ # bigquery = Google::Cloud::Bigquery.new
963
+ # dataset = bigquery.dataset "my_dataset"
964
+ #
965
+ # routine = dataset.routine "my_routine"
966
+ # puts routine.routine_id
967
+ #
968
+ # @example Avoid retrieving the routine resource with `skip_lookup`:
969
+ # require "google/cloud/bigquery"
970
+ #
971
+ # bigquery = Google::Cloud::Bigquery.new
972
+ #
973
+ # dataset = bigquery.dataset "my_dataset"
974
+ #
975
+ # routine = dataset.routine "my_routine", skip_lookup: true
976
+ #
977
+ # @!group Routine
978
+ #
979
+ def routine routine_id, skip_lookup: nil
980
+ ensure_service!
981
+ return Routine.new_reference project_id, dataset_id, routine_id, service if skip_lookup
982
+ gapi = service.get_routine dataset_id, routine_id
983
+ Routine.from_gapi gapi, service
984
+ rescue Google::Cloud::NotFoundError
985
+ nil
986
+ end
987
+
988
+ ##
989
+ # Retrieves the list of routines belonging to the dataset.
990
+ #
991
+ # @param [String] token A previously-returned page token representing
992
+ # part of the larger set of results to view.
993
+ # @param [Integer] max Maximum number of routines to return.
994
+ # @param [String] filter If set, then only the routines matching this filter are returned. The current supported
995
+ # form is `routineType:`, with a {Routine#routine_type} enum value. Example: `routineType:SCALAR_FUNCTION`.
996
+ #
997
+ # @return [Array<Google::Cloud::Bigquery::Routine>] An array of routines
998
+ # (See {Google::Cloud::Bigquery::Routine::List})
999
+ #
1000
+ # @example
1001
+ # require "google/cloud/bigquery"
1002
+ #
1003
+ # bigquery = Google::Cloud::Bigquery.new
1004
+ # dataset = bigquery.dataset "my_dataset"
1005
+ #
1006
+ # routines = dataset.routines
1007
+ # routines.each do |routine|
1008
+ # puts routine.routine_id
1009
+ # end
1010
+ #
1011
+ # @example Retrieve all routines: (See {Routine::List#all})
1012
+ # require "google/cloud/bigquery"
1013
+ #
1014
+ # bigquery = Google::Cloud::Bigquery.new
1015
+ # dataset = bigquery.dataset "my_dataset"
1016
+ #
1017
+ # routines = dataset.routines
1018
+ # routines.all do |routine|
1019
+ # puts routine.routine_id
1020
+ # end
1021
+ #
1022
+ # @!group Routine
1023
+ #
1024
+ def routines token: nil, max: nil, filter: nil
1025
+ ensure_service!
1026
+ gapi = service.list_routines dataset_id, token: token, max: max, filter: filter
1027
+ Routine::List.from_gapi gapi, service, dataset_id, max, filter: filter
1028
+ end
1029
+
820
1030
  ##
821
1031
  # Queries data by creating a [query
822
1032
  # job](https://cloud.google.com/bigquery/docs/query-overview#query_jobs).
@@ -969,12 +1179,20 @@ module Google
969
1179
  # list must have a different key. See [Requirements for
970
1180
  # labels](https://cloud.google.com/bigquery/docs/creating-managing-labels#requirements).
971
1181
  # @param [Array<String>, String] udfs User-defined function resources
972
- # used in the query. May be either a code resource to load from a
973
- # Google Cloud Storage URI (`gs://bucket/path`), or an inline resource
1182
+ # used in a legacy SQL query. May be either a code resource to load from
1183
+ # a Google Cloud Storage URI (`gs://bucket/path`), or an inline resource
974
1184
  # that contains code for a user-defined function (UDF). Providing an
975
1185
  # inline code resource is equivalent to providing a URI for a file
976
- # containing the same code. See [User-Defined
977
- # Functions](https://cloud.google.com/bigquery/docs/reference/standard-sql/user-defined-functions).
1186
+ # containing the same code.
1187
+ #
1188
+ # This parameter is used for defining User Defined Function (UDF)
1189
+ # resources only when using legacy SQL. Users of standard SQL should
1190
+ # leverage either DDL (e.g. `CREATE [TEMPORARY] FUNCTION ...`) or the
1191
+ # Routines API to define UDF resources.
1192
+ #
1193
+ # For additional information on migrating, see: [Migrating to
1194
+ # standard SQL - Differences in user-defined JavaScript
1195
+ # functions](https://cloud.google.com/bigquery/docs/reference/standard-sql/migrating-from-legacy-sql#differences_in_user-defined_javascript_functions)
978
1196
  # @param [Integer] maximum_billing_tier Deprecated: Change the billing
979
1197
  # tier to allow high-compute queries.
980
1198
  # @yield [job] a job configuration object
@@ -1073,7 +1291,7 @@ module Google
1073
1291
  #
1074
1292
  # job.wait_until_done!
1075
1293
  # if !job.failed?
1076
- # table_ref = job.ddl_target_table
1294
+ # table_ref = job.ddl_target_table # Or ddl_target_routine for CREATE/DROP FUNCTION/PROCEDURE
1077
1295
  # end
1078
1296
  #
1079
1297
  # @example Execute a DML statement:
@@ -1321,7 +1539,7 @@ module Google
1321
1539
  #
1322
1540
  # data = bigquery.query "CREATE TABLE my_table (x INT64)"
1323
1541
  #
1324
- # table_ref = data.ddl_target_table
1542
+ # table_ref = data.ddl_target_table # Or ddl_target_routine for CREATE/DROP FUNCTION/PROCEDURE
1325
1543
  #
1326
1544
  # @example Execute a DML statement:
1327
1545
  # require "google/cloud/bigquery"
@@ -1942,7 +2160,7 @@ module Google
1942
2160
  # dataset = bigquery.dataset "my_dataset", skip_lookup: true
1943
2161
  # dataset.exists? # true
1944
2162
  #
1945
- def exists? force: nil
2163
+ def exists? force: false
1946
2164
  return gapi_exists? if force
1947
2165
  # If we have a memoized value, return it
1948
2166
  return @exists unless @exists.nil?
@@ -2052,7 +2270,7 @@ module Google
2052
2270
  end
2053
2271
 
2054
2272
  ##
2055
- # @private New lazy Dataset object without making an HTTP request.
2273
+ # @private New lazy Dataset object without making an HTTP request, for use with the skip_lookup option.
2056
2274
  def self.new_reference project_id, dataset_id, service
2057
2275
  raise ArgumentError, "dataset_id is required" unless dataset_id
2058
2276
  new.tap do |b|
@@ -2083,12 +2301,13 @@ module Google
2083
2301
  # @param [String] table_id The ID of the destination table.
2084
2302
  # @param [Hash, Array<Hash>] rows A hash object or array of hash objects
2085
2303
  # containing the data. Required.
2086
- # @param [Array<String>] insert_ids A unique ID for each row. BigQuery
2087
- # uses this property to detect duplicate insertion requests on a
2088
- # best-effort basis. For more information, see [data
2089
- # consistency](https://cloud.google.com/bigquery/streaming-data-into-bigquery#dataconsistency).
2090
- # Optional. If not provided, the client library will assign a UUID to
2091
- # each row before the request is sent.
2304
+ # @param [Array<String|Symbol>, Symbol] insert_ids A unique ID for each row. BigQuery uses this property to
2305
+ # detect duplicate insertion requests on a best-effort basis. For more information, see [data
2306
+ # consistency](https://cloud.google.com/bigquery/streaming-data-into-bigquery#dataconsistency). Optional. If
2307
+ # not provided, the client library will assign a UUID to each row before the request is sent.
2308
+ #
2309
+ # The value `:skip` can be provided to skip the generation of IDs for all rows, or to skip the generation of an
2310
+ # ID for a specific row in the array.
2092
2311
  # @param [Boolean] skip_invalid Insert all valid rows of a request, even
2093
2312
  # if invalid rows exist. The default value is `false`, which causes
2094
2313
  # the entire request to fail if any invalid rows exist.
@@ -2099,6 +2318,12 @@ module Google
2099
2318
  # a new table with the given `table_id`, if no table is found for
2100
2319
  # `table_id`. The default value is false.
2101
2320
  #
2321
+ # @yield [table] a block for setting the table
2322
+ # @yieldparam [Google::Cloud::Bigquery::Table::Updater] table An updater
2323
+ # to set additional properties on the table in the API request to
2324
+ # create it. Only used when `autocreate` is set and the table does not
2325
+ # already exist.
2326
+ #
2102
2327
  # @return [Google::Cloud::Bigquery::InsertResponse] An insert response
2103
2328
  # object.
2104
2329
  #
@@ -2144,32 +2369,19 @@ module Google
2144
2369
  #
2145
2370
  # @!group Data
2146
2371
  #
2147
- def insert table_id, rows, insert_ids: nil, skip_invalid: nil, ignore_unknown: nil, autocreate: nil
2372
+ def insert table_id, rows, insert_ids: nil, skip_invalid: nil, ignore_unknown: nil, autocreate: nil, &block
2148
2373
  rows = [rows] if rows.is_a? Hash
2374
+ raise ArgumentError, "No rows provided" if rows.empty?
2375
+
2376
+ insert_ids = Array.new(rows.count) { :skip } if insert_ids == :skip
2149
2377
  insert_ids = Array insert_ids
2150
2378
  if insert_ids.count.positive? && insert_ids.count != rows.count
2151
2379
  raise ArgumentError, "insert_ids must be the same size as rows"
2152
2380
  end
2153
2381
 
2154
2382
  if autocreate
2155
- begin
2156
- insert_data table_id, rows,
2157
- skip_invalid: skip_invalid, ignore_unknown: ignore_unknown, insert_ids: insert_ids
2158
- rescue Google::Cloud::NotFoundError
2159
- sleep rand(1..60)
2160
- begin
2161
- create_table table_id do |tbl_updater|
2162
- yield tbl_updater if block_given?
2163
- end
2164
- # rubocop:disable Lint/HandleExceptions
2165
- rescue Google::Cloud::AlreadyExistsError
2166
- end
2167
- # rubocop:enable Lint/HandleExceptions
2168
-
2169
- sleep 60
2170
- insert table_id, rows, skip_invalid: skip_invalid, ignore_unknown: ignore_unknown, autocreate: true,
2171
- insert_ids: insert_ids
2172
- end
2383
+ insert_data_with_autocreate table_id, rows, skip_invalid: skip_invalid, ignore_unknown: ignore_unknown,
2384
+ insert_ids: insert_ids, &block
2173
2385
  else
2174
2386
  insert_data table_id, rows, skip_invalid: skip_invalid, ignore_unknown: ignore_unknown,
2175
2387
  insert_ids: insert_ids
@@ -2239,15 +2451,30 @@ module Google
2239
2451
 
2240
2452
  protected
2241
2453
 
2242
- def insert_data table_id, rows, skip_invalid: nil, ignore_unknown: nil,
2243
- insert_ids: nil
2454
+ def insert_data_with_autocreate table_id, rows, skip_invalid: nil, ignore_unknown: nil, insert_ids: nil
2455
+ insert_data table_id, rows, skip_invalid: skip_invalid, ignore_unknown: ignore_unknown, insert_ids: insert_ids
2456
+ rescue Google::Cloud::NotFoundError
2457
+ sleep rand(1..60)
2458
+ begin
2459
+ create_table table_id do |tbl_updater|
2460
+ yield tbl_updater if block_given?
2461
+ end
2462
+ # rubocop:disable Lint/HandleExceptions
2463
+ rescue Google::Cloud::AlreadyExistsError
2464
+ end
2465
+ # rubocop:enable Lint/HandleExceptions
2466
+
2467
+ sleep 60
2468
+ retry
2469
+ end
2470
+
2471
+ def insert_data table_id, rows, skip_invalid: nil, ignore_unknown: nil, insert_ids: nil
2244
2472
  rows = [rows] if rows.is_a? Hash
2245
2473
  raise ArgumentError, "No rows provided" if rows.empty?
2246
2474
  ensure_service!
2247
- options = { skip_invalid: skip_invalid,
2248
- ignore_unknown: ignore_unknown,
2249
- insert_ids: insert_ids }
2250
- gapi = service.insert_tabledata dataset_id, table_id, rows, options
2475
+ gapi = service.insert_tabledata dataset_id, table_id, rows, skip_invalid: skip_invalid,
2476
+ ignore_unknown: ignore_unknown,
2477
+ insert_ids: insert_ids
2251
2478
  InsertResponse.from_gapi rows, gapi
2252
2479
  end
2253
2480
 
@@ -2444,14 +2671,14 @@ module Google
2444
2671
  end
2445
2672
 
2446
2673
  ##
2447
- # Yielded to a block to accumulate changes for a patch request.
2674
+ # Yielded to a block to accumulate changes for a create request. See {Project#create_dataset}.
2448
2675
  class Updater < Dataset
2449
2676
  ##
2450
- # A list of attributes that were updated.
2677
+ # @private A list of attributes that were updated.
2451
2678
  attr_reader :updates
2452
2679
 
2453
2680
  ##
2454
- # Create an Updater object.
2681
+ # @private Create an Updater object.
2455
2682
  def initialize gapi
2456
2683
  @updates = []
2457
2684
  @gapi = gapi
@@ -2468,8 +2695,109 @@ module Google
2468
2695
  @access
2469
2696
  end
2470
2697
 
2698
+ # rubocop:disable Style/MethodDefParentheses
2699
+
2700
+ ##
2701
+ # @raise [RuntimeError] not implemented
2702
+ def delete(*)
2703
+ raise "not implemented in #{self.class}"
2704
+ end
2705
+
2471
2706
  ##
2472
- # Make sure any access changes are saved
2707
+ # @raise [RuntimeError] not implemented
2708
+ def create_table(*)
2709
+ raise "not implemented in #{self.class}"
2710
+ end
2711
+
2712
+ ##
2713
+ # @raise [RuntimeError] not implemented
2714
+ def create_view(*)
2715
+ raise "not implemented in #{self.class}"
2716
+ end
2717
+
2718
+ ##
2719
+ # @raise [RuntimeError] not implemented
2720
+ def table(*)
2721
+ raise "not implemented in #{self.class}"
2722
+ end
2723
+
2724
+ ##
2725
+ # @raise [RuntimeError] not implemented
2726
+ def tables(*)
2727
+ raise "not implemented in #{self.class}"
2728
+ end
2729
+
2730
+ ##
2731
+ # @raise [RuntimeError] not implemented
2732
+ def model(*)
2733
+ raise "not implemented in #{self.class}"
2734
+ end
2735
+
2736
+ ##
2737
+ # @raise [RuntimeError] not implemented
2738
+ def models(*)
2739
+ raise "not implemented in #{self.class}"
2740
+ end
2741
+
2742
+ ##
2743
+ # @raise [RuntimeError] not implemented
2744
+ def create_routine(*)
2745
+ raise "not implemented in #{self.class}"
2746
+ end
2747
+
2748
+ ##
2749
+ # @raise [RuntimeError] not implemented
2750
+ def routine(*)
2751
+ raise "not implemented in #{self.class}"
2752
+ end
2753
+
2754
+ ##
2755
+ # @raise [RuntimeError] not implemented
2756
+ def routines(*)
2757
+ raise "not implemented in #{self.class}"
2758
+ end
2759
+
2760
+ ##
2761
+ # @raise [RuntimeError] not implemented
2762
+ def query_job(*)
2763
+ raise "not implemented in #{self.class}"
2764
+ end
2765
+
2766
+ ##
2767
+ # @raise [RuntimeError] not implemented
2768
+ def query(*)
2769
+ raise "not implemented in #{self.class}"
2770
+ end
2771
+
2772
+ ##
2773
+ # @raise [RuntimeError] not implemented
2774
+ def external(*)
2775
+ raise "not implemented in #{self.class}"
2776
+ end
2777
+
2778
+ ##
2779
+ # @raise [RuntimeError] not implemented
2780
+ def load_job(*)
2781
+ raise "not implemented in #{self.class}"
2782
+ end
2783
+
2784
+ ##
2785
+ # @raise [RuntimeError] not implemented
2786
+ def load(*)
2787
+ raise "not implemented in #{self.class}"
2788
+ end
2789
+
2790
+ ##
2791
+ # @raise [RuntimeError] not implemented
2792
+ def reload!
2793
+ raise "not implemented in #{self.class}"
2794
+ end
2795
+ alias refresh! reload!
2796
+
2797
+ # rubocop:enable Style/MethodDefParentheses
2798
+
2799
+ ##
2800
+ # @private Make sure any access changes are saved
2473
2801
  def check_for_mutated_access!
2474
2802
  return if @access.nil?
2475
2803
  return unless @access.changed?
@@ -2477,6 +2805,8 @@ module Google
2477
2805
  patch_gapi! :access
2478
2806
  end
2479
2807
 
2808
+ ##
2809
+ # @private
2480
2810
  def to_gapi
2481
2811
  check_for_mutated_access!
2482
2812
  @gapi