google-cloud-bigquery 1.35.1 → 1.38.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +42 -0
- data/CONTRIBUTING.md +328 -115
- data/lib/google/cloud/bigquery/data.rb +18 -3
- data/lib/google/cloud/bigquery/dataset.rb +115 -27
- data/lib/google/cloud/bigquery/external/avro_source.rb +107 -0
- data/lib/google/cloud/bigquery/external/data_source.rb +2 -2
- data/lib/google/cloud/bigquery/external.rb +16 -14
- data/lib/google/cloud/bigquery/job.rb +32 -0
- data/lib/google/cloud/bigquery/project.rb +100 -54
- data/lib/google/cloud/bigquery/query_job.rb +51 -3
- data/lib/google/cloud/bigquery/schema/field.rb +10 -1
- data/lib/google/cloud/bigquery/service.rb +8 -0
- data/lib/google/cloud/bigquery/version.rb +1 -1
- metadata +4 -3
@@ -402,6 +402,12 @@ module Google
|
|
402
402
|
# Flattens all nested and repeated fields in the query results. The
|
403
403
|
# default value is `true`. `large_results` parameter must be `true` if
|
404
404
|
# this is set to `false`.
|
405
|
+
# @param [Integer] maximum_billing_tier Limits the billing tier for this
|
406
|
+
# job. Queries that have resource usage beyond this tier will fail
|
407
|
+
# (without incurring a charge). WARNING: The billed byte amount can be
|
408
|
+
# multiplied by an amount up to this number! Most users should not need
|
409
|
+
# to alter this setting, and we recommend that you avoid introducing new
|
410
|
+
# uses of it. Deprecated.
|
405
411
|
# @param [Integer] maximum_bytes_billed Limits the bytes billed for this
|
406
412
|
# job. Queries that will have bytes billed beyond this limit will fail
|
407
413
|
# (without incurring a charge). Optional. If unspecified, this will be
|
@@ -455,8 +461,13 @@ module Google
|
|
455
461
|
# For additional information on migrating, see: [Migrating to
|
456
462
|
# standard SQL - Differences in user-defined JavaScript
|
457
463
|
# functions](https://cloud.google.com/bigquery/docs/reference/standard-sql/migrating-from-legacy-sql#differences_in_user-defined_javascript_functions)
|
458
|
-
# @param [
|
459
|
-
#
|
464
|
+
# @param [Boolean] create_session If true, creates a new session, where the
|
465
|
+
# session ID will be a server generated random id. If false, runs query
|
466
|
+
# with an existing session ID when one is provided in the `session_id`
|
467
|
+
# param, otherwise runs query in non-session mode. See {Job#session_id}.
|
468
|
+
# The default value is false.
|
469
|
+
# @param [String] session_id The ID of an existing session. See also the
|
470
|
+
# `create_session` param and {Job#session_id}.
|
460
471
|
# @yield [job] a job configuration object
|
461
472
|
# @yieldparam [Google::Cloud::Bigquery::QueryJob::Updater] job a job
|
462
473
|
# configuration object for setting query options.
|
@@ -468,8 +479,7 @@ module Google
|
|
468
479
|
#
|
469
480
|
# bigquery = Google::Cloud::Bigquery.new
|
470
481
|
#
|
471
|
-
# job = bigquery.query_job "SELECT name FROM "
|
472
|
-
# "`my_project.my_dataset.my_table`"
|
482
|
+
# job = bigquery.query_job "SELECT name FROM `my_project.my_dataset.my_table`"
|
473
483
|
#
|
474
484
|
# job.wait_until_done!
|
475
485
|
# if !job.failed?
|
@@ -483,8 +493,7 @@ module Google
|
|
483
493
|
#
|
484
494
|
# bigquery = Google::Cloud::Bigquery.new
|
485
495
|
#
|
486
|
-
# job = bigquery.query_job "SELECT name FROM "
|
487
|
-
# " [my_project:my_dataset.my_table]",
|
496
|
+
# job = bigquery.query_job "SELECT name FROM [my_project:my_dataset.my_table]",
|
488
497
|
# legacy_sql: true
|
489
498
|
#
|
490
499
|
# job.wait_until_done!
|
@@ -499,9 +508,7 @@ module Google
|
|
499
508
|
#
|
500
509
|
# bigquery = Google::Cloud::Bigquery.new
|
501
510
|
#
|
502
|
-
# job = bigquery.query_job "SELECT name FROM "
|
503
|
-
# "`my_dataset.my_table` " \
|
504
|
-
# "WHERE id = ?",
|
511
|
+
# job = bigquery.query_job "SELECT name FROM `my_dataset.my_table` WHERE id = ?",
|
505
512
|
# params: [1]
|
506
513
|
#
|
507
514
|
# job.wait_until_done!
|
@@ -516,9 +523,7 @@ module Google
|
|
516
523
|
#
|
517
524
|
# bigquery = Google::Cloud::Bigquery.new
|
518
525
|
#
|
519
|
-
# job = bigquery.query_job "SELECT name FROM "
|
520
|
-
# "`my_dataset.my_table` " \
|
521
|
-
# "WHERE id = @id",
|
526
|
+
# job = bigquery.query_job "SELECT name FROM `my_dataset.my_table` WHERE id = @id",
|
522
527
|
# params: { id: 1 }
|
523
528
|
#
|
524
529
|
# job.wait_until_done!
|
@@ -533,9 +538,7 @@ module Google
|
|
533
538
|
#
|
534
539
|
# bigquery = Google::Cloud::Bigquery.new
|
535
540
|
#
|
536
|
-
# job = bigquery.query_job "SELECT name FROM "
|
537
|
-
# "`my_dataset.my_table` " \
|
538
|
-
# "WHERE id IN UNNEST(@ids)",
|
541
|
+
# job = bigquery.query_job "SELECT name FROM `my_dataset.my_table` WHERE id IN UNNEST(@ids)",
|
539
542
|
# params: { ids: [] },
|
540
543
|
# types: { ids: [:INT64] }
|
541
544
|
#
|
@@ -551,9 +554,7 @@ module Google
|
|
551
554
|
#
|
552
555
|
# bigquery = Google::Cloud::Bigquery.new
|
553
556
|
#
|
554
|
-
# job = bigquery.query_job "CREATE TABLE "
|
555
|
-
# "`my_dataset.my_table` " \
|
556
|
-
# "(x INT64)"
|
557
|
+
# job = bigquery.query_job "CREATE TABLE`my_dataset.my_table` (x INT64)"
|
557
558
|
#
|
558
559
|
# job.wait_until_done!
|
559
560
|
# if !job.failed?
|
@@ -565,10 +566,7 @@ module Google
|
|
565
566
|
#
|
566
567
|
# bigquery = Google::Cloud::Bigquery.new
|
567
568
|
#
|
568
|
-
# job = bigquery.query_job "UPDATE "
|
569
|
-
# "`my_dataset.my_table` " \
|
570
|
-
# "SET x = x + 1 " \
|
571
|
-
# "WHERE x IS NOT NULL"
|
569
|
+
# job = bigquery.query_job "UPDATE `my_dataset.my_table` SET x = x + 1 WHERE x IS NOT NULL"
|
572
570
|
#
|
573
571
|
# job.wait_until_done!
|
574
572
|
# if !job.failed?
|
@@ -599,17 +597,56 @@ module Google
|
|
599
597
|
# end
|
600
598
|
# end
|
601
599
|
#
|
602
|
-
def query_job query,
|
603
|
-
|
604
|
-
|
605
|
-
|
600
|
+
def query_job query,
|
601
|
+
params: nil,
|
602
|
+
types: nil,
|
603
|
+
external: nil,
|
604
|
+
priority: "INTERACTIVE",
|
605
|
+
cache: true,
|
606
|
+
table: nil,
|
607
|
+
create: nil,
|
608
|
+
write: nil,
|
609
|
+
dryrun: nil,
|
610
|
+
dataset: nil,
|
611
|
+
project: nil,
|
612
|
+
standard_sql: nil,
|
613
|
+
legacy_sql: nil,
|
614
|
+
large_results: nil,
|
615
|
+
flatten: nil,
|
616
|
+
maximum_billing_tier: nil,
|
617
|
+
maximum_bytes_billed: nil,
|
618
|
+
job_id: nil,
|
619
|
+
prefix: nil,
|
620
|
+
labels: nil,
|
621
|
+
udfs: nil,
|
622
|
+
create_session: nil,
|
623
|
+
session_id: nil
|
606
624
|
ensure_service!
|
607
|
-
options = {
|
608
|
-
|
609
|
-
|
610
|
-
|
611
|
-
|
612
|
-
|
625
|
+
options = {
|
626
|
+
params: params,
|
627
|
+
types: types,
|
628
|
+
external: external,
|
629
|
+
priority: priority,
|
630
|
+
cache: cache,
|
631
|
+
table: table,
|
632
|
+
create: create,
|
633
|
+
write: write,
|
634
|
+
dryrun: dryrun,
|
635
|
+
dataset: dataset,
|
636
|
+
project: (project || self.project),
|
637
|
+
standard_sql: standard_sql,
|
638
|
+
legacy_sql: legacy_sql,
|
639
|
+
large_results: large_results,
|
640
|
+
flatten: flatten,
|
641
|
+
maximum_billing_tier: maximum_billing_tier,
|
642
|
+
maximum_bytes_billed: maximum_bytes_billed,
|
643
|
+
job_id: job_id,
|
644
|
+
prefix: prefix,
|
645
|
+
labels: labels,
|
646
|
+
udfs: udfs,
|
647
|
+
create_session: create_session,
|
648
|
+
session_id: session_id
|
649
|
+
}
|
613
650
|
|
614
651
|
updater = QueryJob::Updater.from_options service, query, options
|
615
652
|
|
@@ -730,6 +767,8 @@ module Google
|
|
730
767
|
# When set to false, the values of `large_results` and `flatten` are
|
731
768
|
# ignored; the query will be run as if `large_results` is true and
|
732
769
|
# `flatten` is false. Optional. The default value is false.
|
770
|
+
# @param [String] session_id The ID of an existing session. See the
|
771
|
+
# `create_session` param in {#query_job} and {Job#session_id}.
|
733
772
|
# @yield [job] a job configuration object
|
734
773
|
# @yieldparam [Google::Cloud::Bigquery::QueryJob::Updater] job a job
|
735
774
|
# configuration object for setting additional options for the query.
|
@@ -782,9 +821,7 @@ module Google
|
|
782
821
|
#
|
783
822
|
# bigquery = Google::Cloud::Bigquery.new
|
784
823
|
#
|
785
|
-
# data = bigquery.query "SELECT name "
|
786
|
-
# "FROM `my_dataset.my_table` " \
|
787
|
-
# "WHERE id = ?",
|
824
|
+
# data = bigquery.query "SELECT name FROM `my_dataset.my_table` WHERE id = ?",
|
788
825
|
# params: [1]
|
789
826
|
#
|
790
827
|
# # Iterate over the first page of results
|
@@ -799,9 +836,7 @@ module Google
|
|
799
836
|
#
|
800
837
|
# bigquery = Google::Cloud::Bigquery.new
|
801
838
|
#
|
802
|
-
# data = bigquery.query "SELECT name "
|
803
|
-
# "FROM `my_dataset.my_table` " \
|
804
|
-
# "WHERE id = @id",
|
839
|
+
# data = bigquery.query "SELECT name FROM `my_dataset.my_table` WHERE id = @id",
|
805
840
|
# params: { id: 1 }
|
806
841
|
#
|
807
842
|
# # Iterate over the first page of results
|
@@ -816,9 +851,7 @@ module Google
|
|
816
851
|
#
|
817
852
|
# bigquery = Google::Cloud::Bigquery.new
|
818
853
|
#
|
819
|
-
# data = bigquery.query "SELECT name FROM "
|
820
|
-
# "`my_dataset.my_table` " \
|
821
|
-
# "WHERE id IN UNNEST(@ids)",
|
854
|
+
# data = bigquery.query "SELECT name FROM `my_dataset.my_table` WHERE id IN UNNEST(@ids)",
|
822
855
|
# params: { ids: [] },
|
823
856
|
# types: { ids: [:INT64] }
|
824
857
|
#
|
@@ -843,9 +876,7 @@ module Google
|
|
843
876
|
#
|
844
877
|
# bigquery = Google::Cloud::Bigquery.new
|
845
878
|
#
|
846
|
-
# data = bigquery.query "UPDATE `my_dataset.my_table` "
|
847
|
-
# "SET x = x + 1 " \
|
848
|
-
# "WHERE x IS NOT NULL"
|
879
|
+
# data = bigquery.query "UPDATE `my_dataset.my_table` SET x = x + 1 WHERE x IS NOT NULL"
|
849
880
|
#
|
850
881
|
# puts data.num_dml_affected_rows
|
851
882
|
#
|
@@ -873,10 +904,29 @@ module Google
|
|
873
904
|
# # Retrieve the next page of results
|
874
905
|
# data = data.next if data.next?
|
875
906
|
#
|
876
|
-
def query query,
|
877
|
-
|
878
|
-
|
879
|
-
|
907
|
+
def query query,
|
908
|
+
params: nil,
|
909
|
+
types: nil,
|
910
|
+
external: nil,
|
911
|
+
max: nil,
|
912
|
+
cache: true,
|
913
|
+
dataset: nil,
|
914
|
+
project: nil,
|
915
|
+
standard_sql: nil,
|
916
|
+
legacy_sql: nil,
|
917
|
+
session_id: nil,
|
918
|
+
&block
|
919
|
+
job = query_job query,
|
920
|
+
params: params,
|
921
|
+
types: types,
|
922
|
+
external: external,
|
923
|
+
cache: cache,
|
924
|
+
dataset: dataset,
|
925
|
+
project: project,
|
926
|
+
standard_sql: standard_sql,
|
927
|
+
legacy_sql: legacy_sql,
|
928
|
+
session_id: session_id,
|
929
|
+
&block
|
880
930
|
job.wait_until_done!
|
881
931
|
|
882
932
|
if job.failed?
|
@@ -1326,9 +1376,7 @@ module Google
|
|
1326
1376
|
# bigquery = Google::Cloud::Bigquery.new
|
1327
1377
|
#
|
1328
1378
|
# fourpm = bigquery.time 16, 0, 0
|
1329
|
-
# data = bigquery.query "SELECT name "
|
1330
|
-
# "FROM `my_dataset.my_table`" \
|
1331
|
-
# "WHERE time_of_date = @time",
|
1379
|
+
# data = bigquery.query "SELECT name FROM `my_dataset.my_table` WHERE time_of_date = @time",
|
1332
1380
|
# params: { time: fourpm }
|
1333
1381
|
#
|
1334
1382
|
# # Iterate over the first page of results
|
@@ -1344,9 +1392,7 @@ module Google
|
|
1344
1392
|
# bigquery = Google::Cloud::Bigquery.new
|
1345
1393
|
#
|
1346
1394
|
# precise_time = bigquery.time 16, 35, 15.376541
|
1347
|
-
# data = bigquery.query "SELECT name "
|
1348
|
-
# "FROM `my_dataset.my_table`" \
|
1349
|
-
# "WHERE time_of_date >= @time",
|
1395
|
+
# data = bigquery.query "SELECT name FROM `my_dataset.my_table` WHERE time_of_date >= @time",
|
1350
1396
|
# params: { time: precise_time }
|
1351
1397
|
#
|
1352
1398
|
# # Iterate over the first page of results
|
@@ -250,6 +250,8 @@ module Google
|
|
250
250
|
# The type of query statement, if valid. Possible values (new values
|
251
251
|
# might be added in the future):
|
252
252
|
#
|
253
|
+
# * "ALTER_TABLE": DDL statement, see [Using Data Definition Language
|
254
|
+
# Statements](https://cloud.google.com/bigquery/docs/reference/standard-sql/data-definition-language)
|
253
255
|
# * "CREATE_MODEL": DDL statement, see [Using Data Definition Language
|
254
256
|
# Statements](https://cloud.google.com/bigquery/docs/reference/standard-sql/data-definition-language)
|
255
257
|
# * "CREATE_TABLE": DDL statement, see [Using Data Definition Language
|
@@ -295,8 +297,16 @@ module Google
|
|
295
297
|
# query_job.ddl? #=> true
|
296
298
|
#
|
297
299
|
def ddl?
|
298
|
-
[
|
299
|
-
|
300
|
+
[
|
301
|
+
"ALTER_TABLE",
|
302
|
+
"CREATE_MODEL",
|
303
|
+
"CREATE_TABLE",
|
304
|
+
"CREATE_TABLE_AS_SELECT",
|
305
|
+
"CREATE_VIEW",
|
306
|
+
"DROP_MODEL",
|
307
|
+
"DROP_TABLE",
|
308
|
+
"DROP_VIEW"
|
309
|
+
].include? statement_type
|
300
310
|
end
|
301
311
|
|
302
312
|
##
|
@@ -319,7 +329,12 @@ module Google
|
|
319
329
|
# query_job.dml? #=> true
|
320
330
|
#
|
321
331
|
def dml?
|
322
|
-
[
|
332
|
+
[
|
333
|
+
"INSERT",
|
334
|
+
"UPDATE",
|
335
|
+
"MERGE",
|
336
|
+
"DELETE"
|
337
|
+
].include? statement_type
|
323
338
|
end
|
324
339
|
|
325
340
|
##
|
@@ -775,6 +790,8 @@ module Google
|
|
775
790
|
updater = QueryJob::Updater.new service, req
|
776
791
|
updater.set_params_and_types options[:params], options[:types] if options[:params]
|
777
792
|
updater.create = options[:create]
|
793
|
+
updater.create_session = options[:create_session]
|
794
|
+
updater.session_id = options[:session_id] if options[:session_id]
|
778
795
|
updater.write = options[:write]
|
779
796
|
updater.table = options[:table]
|
780
797
|
updater.dryrun = options[:dryrun]
|
@@ -1018,6 +1035,37 @@ module Google
|
|
1018
1035
|
@gapi.configuration.query.create_disposition = Convert.create_disposition value
|
1019
1036
|
end
|
1020
1037
|
|
1038
|
+
##
|
1039
|
+
# Sets the create_session property. If true, creates a new session,
|
1040
|
+
# where session id will be a server generated random id. If false,
|
1041
|
+
# runs query with an existing {#session_id=}, otherwise runs query in
|
1042
|
+
# non-session mode. The default value is `false`.
|
1043
|
+
#
|
1044
|
+
# @param [Boolean] value The create_session property. The default
|
1045
|
+
# value is `false`.
|
1046
|
+
#
|
1047
|
+
# @!group Attributes
|
1048
|
+
def create_session= value
|
1049
|
+
@gapi.configuration.query.create_session = value
|
1050
|
+
end
|
1051
|
+
|
1052
|
+
##
|
1053
|
+
# Sets the session ID for a query run in session mode. See {#create_session=}.
|
1054
|
+
#
|
1055
|
+
# @param [String] value The session ID. The default value is `nil`.
|
1056
|
+
#
|
1057
|
+
# @!group Attributes
|
1058
|
+
def session_id= value
|
1059
|
+
@gapi.configuration.query.connection_properties ||= []
|
1060
|
+
prop = @gapi.configuration.query.connection_properties.find { |cp| cp.key == "session_id" }
|
1061
|
+
if prop
|
1062
|
+
prop.value = value
|
1063
|
+
else
|
1064
|
+
prop = Google::Apis::BigqueryV2::ConnectionProperty.new key: "session_id", value: value
|
1065
|
+
@gapi.configuration.query.connection_properties << prop
|
1066
|
+
end
|
1067
|
+
end
|
1068
|
+
|
1021
1069
|
##
|
1022
1070
|
# Sets the write disposition for when the query results table exists.
|
1023
1071
|
#
|
@@ -939,7 +939,14 @@ module Google
|
|
939
939
|
"Cannot add fields to a non-RECORD field (#{type})"
|
940
940
|
end
|
941
941
|
|
942
|
-
def add_field name,
|
942
|
+
def add_field name,
|
943
|
+
type,
|
944
|
+
description: nil,
|
945
|
+
mode: :nullable,
|
946
|
+
policy_tags: nil,
|
947
|
+
max_length: nil,
|
948
|
+
precision: nil,
|
949
|
+
scale: nil
|
943
950
|
frozen_check!
|
944
951
|
|
945
952
|
new_gapi = Google::Apis::BigqueryV2::TableFieldSchema.new(
|
@@ -954,6 +961,8 @@ module Google
|
|
954
961
|
new_gapi.policy_tags = Google::Apis::BigqueryV2::TableFieldSchema::PolicyTags.new names: policy_tags
|
955
962
|
end
|
956
963
|
new_gapi.max_length = max_length if max_length
|
964
|
+
new_gapi.precision = precision if precision
|
965
|
+
new_gapi.scale = scale if scale
|
957
966
|
# Remove any existing field of this name
|
958
967
|
@gapi.fields ||= []
|
959
968
|
@gapi.fields.reject! { |f| f.name == new_gapi.name }
|
@@ -418,6 +418,14 @@ module Google
|
|
418
418
|
end
|
419
419
|
end
|
420
420
|
|
421
|
+
##
|
422
|
+
# Deletes the job specified by jobId and location (required).
|
423
|
+
def delete_job job_id, location: nil
|
424
|
+
execute do
|
425
|
+
service.delete_job @project, job_id, location: location
|
426
|
+
end
|
427
|
+
end
|
428
|
+
|
421
429
|
##
|
422
430
|
# Returns the query data for the job
|
423
431
|
def job_query_results job_id, location: nil, max: nil, token: nil, start: nil, timeout: nil
|
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.
|
4
|
+
version: 1.38.1
|
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:
|
12
|
+
date: 2022-01-13 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: concurrent-ruby
|
@@ -270,6 +270,7 @@ files:
|
|
270
270
|
- lib/google/cloud/bigquery/dataset/list.rb
|
271
271
|
- lib/google/cloud/bigquery/encryption_configuration.rb
|
272
272
|
- lib/google/cloud/bigquery/external.rb
|
273
|
+
- lib/google/cloud/bigquery/external/avro_source.rb
|
273
274
|
- lib/google/cloud/bigquery/external/bigtable_source.rb
|
274
275
|
- lib/google/cloud/bigquery/external/bigtable_source/column.rb
|
275
276
|
- lib/google/cloud/bigquery/external/bigtable_source/column_family.rb
|
@@ -319,7 +320,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
319
320
|
- !ruby/object:Gem::Version
|
320
321
|
version: '0'
|
321
322
|
requirements: []
|
322
|
-
rubygems_version: 3.
|
323
|
+
rubygems_version: 3.3.5
|
323
324
|
signing_key:
|
324
325
|
specification_version: 4
|
325
326
|
summary: API Client library for Google BigQuery
|