google-cloud-bigquery 1.37.0 → 1.38.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +13 -0
- data/lib/google/cloud/bigquery/dataset.rb +115 -27
- data/lib/google/cloud/bigquery/job.rb +10 -0
- data/lib/google/cloud/bigquery/project.rb +100 -54
- data/lib/google/cloud/bigquery/query_job.rb +33 -0
- data/lib/google/cloud/bigquery/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 134aa6aa80aff038d9ef64cb47875c8147051f47d7259dcc61199fb28f7d4e4e
|
|
4
|
+
data.tar.gz: '023664494e99ff2e580a10ebda7ef369b7fbe6290b9e448ee3eef697ecf94b8a'
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 7563dc9d4e0474c9b2c0bd3f06bef6c059568e24051221542c2536f4b8a0576310d8721eaa5338815ee6fbc5c71b1a782bde9b892c5eabbe532ec30309731e5f
|
|
7
|
+
data.tar.gz: fd6f178cd53ad95f8eb5310854909c726d796beb74232f7537212f949e1358423531f80f8bbfc3e7b8f1afa5b90b1ab5f83549dd1fa9d7a8fc1c9f5653a6712e
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# Release History
|
|
2
2
|
|
|
3
|
+
### 1.38.0 / 2021-11-16
|
|
4
|
+
|
|
5
|
+
#### Features
|
|
6
|
+
|
|
7
|
+
* Add session support
|
|
8
|
+
* Add create_session and session_id params to Project#query_job
|
|
9
|
+
* Add create_session and session_id params to Dataset#query_job
|
|
10
|
+
* Add session_id param to Project#query
|
|
11
|
+
* Add session_id param to Dataset#query
|
|
12
|
+
* Add Job#session_id
|
|
13
|
+
* Add QueryJob::Updater#create_session=
|
|
14
|
+
* Add QueryJob::Updater#session_id=
|
|
15
|
+
|
|
3
16
|
### 1.37.0 / 2021-10-21
|
|
4
17
|
|
|
5
18
|
#### Features
|
|
@@ -1244,6 +1244,12 @@ module Google
|
|
|
1244
1244
|
# Flattens all nested and repeated fields in the query results. The
|
|
1245
1245
|
# default value is `true`. `large_results` parameter must be `true` if
|
|
1246
1246
|
# this is set to `false`.
|
|
1247
|
+
# @param [Integer] maximum_billing_tier Limits the billing tier for this
|
|
1248
|
+
# job. Queries that have resource usage beyond this tier will fail
|
|
1249
|
+
# (without incurring a charge). WARNING: The billed byte amount can be
|
|
1250
|
+
# multiplied by an amount up to this number! Most users should not need
|
|
1251
|
+
# to alter this setting, and we recommend that you avoid introducing new
|
|
1252
|
+
# uses of it. Deprecated.
|
|
1247
1253
|
# @param [Integer] maximum_bytes_billed Limits the bytes billed for this
|
|
1248
1254
|
# job. Queries that will have bytes billed beyond this limit will fail
|
|
1249
1255
|
# (without incurring a charge). Optional. If unspecified, this will be
|
|
@@ -1294,8 +1300,13 @@ module Google
|
|
|
1294
1300
|
# For additional information on migrating, see: [Migrating to
|
|
1295
1301
|
# standard SQL - Differences in user-defined JavaScript
|
|
1296
1302
|
# functions](https://cloud.google.com/bigquery/docs/reference/standard-sql/migrating-from-legacy-sql#differences_in_user-defined_javascript_functions)
|
|
1297
|
-
# @param [
|
|
1298
|
-
#
|
|
1303
|
+
# @param [Boolean] create_session If true, creates a new session, where the
|
|
1304
|
+
# session ID will be a server generated random id. If false, runs query
|
|
1305
|
+
# with an existing session ID when one is provided in the `session_id`
|
|
1306
|
+
# param, otherwise runs query in non-session mode. See {Job#session_id}.
|
|
1307
|
+
# The default value is false.
|
|
1308
|
+
# @param [String] session_id The ID of an existing session. See also the
|
|
1309
|
+
# `create_session` param and {Job#session_id}.
|
|
1299
1310
|
# @yield [job] a job configuration object
|
|
1300
1311
|
# @yieldparam [Google::Cloud::Bigquery::QueryJob::Updater] job a job
|
|
1301
1312
|
# configuration object for setting additional options for the query.
|
|
@@ -1371,8 +1382,7 @@ module Google
|
|
|
1371
1382
|
# bigquery = Google::Cloud::Bigquery.new
|
|
1372
1383
|
# dataset = bigquery.dataset "my_dataset"
|
|
1373
1384
|
#
|
|
1374
|
-
# job = dataset.query_job "SELECT name FROM my_table "
|
|
1375
|
-
# "WHERE id IN UNNEST(@ids)",
|
|
1385
|
+
# job = dataset.query_job "SELECT name FROM my_table WHERE id IN UNNEST(@ids)",
|
|
1376
1386
|
# params: { ids: [] },
|
|
1377
1387
|
# types: { ids: [:INT64] }
|
|
1378
1388
|
#
|
|
@@ -1387,8 +1397,9 @@ module Google
|
|
|
1387
1397
|
# require "google/cloud/bigquery"
|
|
1388
1398
|
#
|
|
1389
1399
|
# bigquery = Google::Cloud::Bigquery.new
|
|
1400
|
+
# dataset = bigquery.dataset "my_dataset"
|
|
1390
1401
|
#
|
|
1391
|
-
# job =
|
|
1402
|
+
# job = dataset.query_job "CREATE TABLE my_table (x INT64)"
|
|
1392
1403
|
#
|
|
1393
1404
|
# job.wait_until_done!
|
|
1394
1405
|
# if !job.failed?
|
|
@@ -1399,16 +1410,28 @@ module Google
|
|
|
1399
1410
|
# require "google/cloud/bigquery"
|
|
1400
1411
|
#
|
|
1401
1412
|
# bigquery = Google::Cloud::Bigquery.new
|
|
1413
|
+
# dataset = bigquery.dataset "my_dataset"
|
|
1402
1414
|
#
|
|
1403
|
-
# job =
|
|
1404
|
-
# "SET x = x + 1 " \
|
|
1405
|
-
# "WHERE x IS NOT NULL"
|
|
1415
|
+
# job = dataset.query_job "UPDATE my_table SET x = x + 1 WHERE x IS NOT NULL"
|
|
1406
1416
|
#
|
|
1407
1417
|
# job.wait_until_done!
|
|
1408
1418
|
# if !job.failed?
|
|
1409
1419
|
# puts job.num_dml_affected_rows
|
|
1410
1420
|
# end
|
|
1411
1421
|
#
|
|
1422
|
+
# @example Run query in a session:
|
|
1423
|
+
# require "google/cloud/bigquery"
|
|
1424
|
+
#
|
|
1425
|
+
# bigquery = Google::Cloud::Bigquery.new
|
|
1426
|
+
# dataset = bigquery.dataset "my_dataset"
|
|
1427
|
+
#
|
|
1428
|
+
# job = dataset.query_job "CREATE TEMPORARY TABLE temptable AS SELECT 17 as foo", create_session: true
|
|
1429
|
+
#
|
|
1430
|
+
# job.wait_until_done!
|
|
1431
|
+
#
|
|
1432
|
+
# session_id = job.session_id
|
|
1433
|
+
# data = dataset.query "SELECT * FROM temptable", session_id: session_id
|
|
1434
|
+
#
|
|
1412
1435
|
# @example Query using external data source, set destination:
|
|
1413
1436
|
# require "google/cloud/bigquery"
|
|
1414
1437
|
#
|
|
@@ -1435,16 +1458,52 @@ module Google
|
|
|
1435
1458
|
#
|
|
1436
1459
|
# @!group Data
|
|
1437
1460
|
#
|
|
1438
|
-
def query_job query,
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1461
|
+
def query_job query,
|
|
1462
|
+
params: nil,
|
|
1463
|
+
types: nil,
|
|
1464
|
+
external: nil,
|
|
1465
|
+
priority: "INTERACTIVE",
|
|
1466
|
+
cache: true,
|
|
1467
|
+
table: nil,
|
|
1468
|
+
create: nil,
|
|
1469
|
+
write: nil,
|
|
1470
|
+
dryrun: nil,
|
|
1471
|
+
standard_sql: nil,
|
|
1472
|
+
legacy_sql: nil,
|
|
1473
|
+
large_results: nil,
|
|
1474
|
+
flatten: nil,
|
|
1475
|
+
maximum_billing_tier: nil,
|
|
1476
|
+
maximum_bytes_billed: nil,
|
|
1477
|
+
job_id: nil,
|
|
1478
|
+
prefix: nil,
|
|
1479
|
+
labels: nil,
|
|
1480
|
+
udfs: nil,
|
|
1481
|
+
create_session: nil,
|
|
1482
|
+
session_id: nil
|
|
1442
1483
|
ensure_service!
|
|
1443
|
-
options = {
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1484
|
+
options = {
|
|
1485
|
+
params: params,
|
|
1486
|
+
types: types,
|
|
1487
|
+
external: external,
|
|
1488
|
+
priority: priority,
|
|
1489
|
+
cache: cache,
|
|
1490
|
+
table: table,
|
|
1491
|
+
create: create,
|
|
1492
|
+
write: write,
|
|
1493
|
+
dryrun: dryrun,
|
|
1494
|
+
standard_sql: standard_sql,
|
|
1495
|
+
legacy_sql: legacy_sql,
|
|
1496
|
+
large_results: large_results,
|
|
1497
|
+
flatten: flatten,
|
|
1498
|
+
maximum_billing_tier: maximum_billing_tier,
|
|
1499
|
+
maximum_bytes_billed: maximum_bytes_billed,
|
|
1500
|
+
job_id: job_id,
|
|
1501
|
+
prefix: prefix,
|
|
1502
|
+
labels: labels,
|
|
1503
|
+
udfs: udfs,
|
|
1504
|
+
create_session: create_session,
|
|
1505
|
+
session_id: session_id
|
|
1506
|
+
}
|
|
1448
1507
|
|
|
1449
1508
|
updater = QueryJob::Updater.from_options service, query, options
|
|
1450
1509
|
updater.dataset = self
|
|
@@ -1566,6 +1625,8 @@ module Google
|
|
|
1566
1625
|
# When set to false, the values of `large_results` and `flatten` are
|
|
1567
1626
|
# ignored; the query will be run as if `large_results` is true and
|
|
1568
1627
|
# `flatten` is false. Optional. The default value is false.
|
|
1628
|
+
# @param [String] session_id The ID of an existing session. See the
|
|
1629
|
+
# `create_session` param in {#query_job} and {Job#session_id}.
|
|
1569
1630
|
# @yield [job] a job configuration object
|
|
1570
1631
|
# @yieldparam [Google::Cloud::Bigquery::QueryJob::Updater] job a job
|
|
1571
1632
|
# configuration object for setting additional options for the query.
|
|
@@ -1641,8 +1702,7 @@ module Google
|
|
|
1641
1702
|
# bigquery = Google::Cloud::Bigquery.new
|
|
1642
1703
|
# dataset = bigquery.dataset "my_dataset"
|
|
1643
1704
|
#
|
|
1644
|
-
# data = dataset.query "SELECT name FROM my_table "
|
|
1645
|
-
# "WHERE id IN UNNEST(@ids)",
|
|
1705
|
+
# data = dataset.query "SELECT name FROM my_table WHERE id IN UNNEST(@ids)",
|
|
1646
1706
|
# params: { ids: [] },
|
|
1647
1707
|
# types: { ids: [:INT64] }
|
|
1648
1708
|
#
|
|
@@ -1657,8 +1717,9 @@ module Google
|
|
|
1657
1717
|
# require "google/cloud/bigquery"
|
|
1658
1718
|
#
|
|
1659
1719
|
# bigquery = Google::Cloud::Bigquery.new
|
|
1720
|
+
# dataset = bigquery.dataset "my_dataset"
|
|
1660
1721
|
#
|
|
1661
|
-
# data =
|
|
1722
|
+
# data = dataset.query "CREATE TABLE my_table (x INT64)"
|
|
1662
1723
|
#
|
|
1663
1724
|
# table_ref = data.ddl_target_table # Or ddl_target_routine for CREATE/DROP FUNCTION/PROCEDURE
|
|
1664
1725
|
#
|
|
@@ -1666,13 +1727,25 @@ module Google
|
|
|
1666
1727
|
# require "google/cloud/bigquery"
|
|
1667
1728
|
#
|
|
1668
1729
|
# bigquery = Google::Cloud::Bigquery.new
|
|
1730
|
+
# dataset = bigquery.dataset "my_dataset"
|
|
1669
1731
|
#
|
|
1670
|
-
# data =
|
|
1671
|
-
# "SET x = x + 1 " \
|
|
1672
|
-
# "WHERE x IS NOT NULL"
|
|
1732
|
+
# data = dataset.query "UPDATE my_table SET x = x + 1 WHERE x IS NOT NULL"
|
|
1673
1733
|
#
|
|
1674
1734
|
# puts data.num_dml_affected_rows
|
|
1675
1735
|
#
|
|
1736
|
+
# @example Run query in a session:
|
|
1737
|
+
# require "google/cloud/bigquery"
|
|
1738
|
+
#
|
|
1739
|
+
# bigquery = Google::Cloud::Bigquery.new
|
|
1740
|
+
# dataset = bigquery.dataset "my_dataset"
|
|
1741
|
+
#
|
|
1742
|
+
# job = dataset.query_job "CREATE TEMPORARY TABLE temptable AS SELECT 17 as foo", create_session: true
|
|
1743
|
+
#
|
|
1744
|
+
# job.wait_until_done!
|
|
1745
|
+
#
|
|
1746
|
+
# session_id = job.session_id
|
|
1747
|
+
# data = dataset.query "SELECT * FROM temptable", session_id: session_id
|
|
1748
|
+
#
|
|
1676
1749
|
# @example Query using external data source, set destination:
|
|
1677
1750
|
# require "google/cloud/bigquery"
|
|
1678
1751
|
#
|
|
@@ -1699,10 +1772,25 @@ module Google
|
|
|
1699
1772
|
#
|
|
1700
1773
|
# @!group Data
|
|
1701
1774
|
#
|
|
1702
|
-
def query query,
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1775
|
+
def query query,
|
|
1776
|
+
params: nil,
|
|
1777
|
+
types: nil,
|
|
1778
|
+
external: nil,
|
|
1779
|
+
max: nil,
|
|
1780
|
+
cache: true,
|
|
1781
|
+
standard_sql: nil,
|
|
1782
|
+
legacy_sql: nil,
|
|
1783
|
+
session_id: nil,
|
|
1784
|
+
&block
|
|
1785
|
+
job = query_job query,
|
|
1786
|
+
params: params,
|
|
1787
|
+
types: types,
|
|
1788
|
+
external: external,
|
|
1789
|
+
cache: cache,
|
|
1790
|
+
standard_sql: standard_sql,
|
|
1791
|
+
legacy_sql: legacy_sql,
|
|
1792
|
+
session_id: session_id,
|
|
1793
|
+
&block
|
|
1706
1794
|
job.wait_until_done!
|
|
1707
1795
|
ensure_job_succeeded! job
|
|
1708
1796
|
|
|
@@ -226,6 +226,16 @@ module Google
|
|
|
226
226
|
Array(@gapi.statistics.reservation_usage).map { |g| ReservationUsage.from_gapi g }
|
|
227
227
|
end
|
|
228
228
|
|
|
229
|
+
##
|
|
230
|
+
# The ID of the session if this job is part of one. See the `create_session` param in {Project#query_job} and
|
|
231
|
+
# {Dataset#query_job}.
|
|
232
|
+
#
|
|
233
|
+
# @return [String, nil] The session ID, or `nil` if not associated with a session.
|
|
234
|
+
#
|
|
235
|
+
def session_id
|
|
236
|
+
@gapi.statistics.session_info&.session_id
|
|
237
|
+
end
|
|
238
|
+
|
|
229
239
|
##
|
|
230
240
|
# The ID of a multi-statement transaction.
|
|
231
241
|
#
|
|
@@ -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
|
|
@@ -775,6 +775,8 @@ module Google
|
|
|
775
775
|
updater = QueryJob::Updater.new service, req
|
|
776
776
|
updater.set_params_and_types options[:params], options[:types] if options[:params]
|
|
777
777
|
updater.create = options[:create]
|
|
778
|
+
updater.create_session = options[:create_session]
|
|
779
|
+
updater.session_id = options[:session_id] if options[:session_id]
|
|
778
780
|
updater.write = options[:write]
|
|
779
781
|
updater.table = options[:table]
|
|
780
782
|
updater.dryrun = options[:dryrun]
|
|
@@ -1018,6 +1020,37 @@ module Google
|
|
|
1018
1020
|
@gapi.configuration.query.create_disposition = Convert.create_disposition value
|
|
1019
1021
|
end
|
|
1020
1022
|
|
|
1023
|
+
##
|
|
1024
|
+
# Sets the create_session property. If true, creates a new session,
|
|
1025
|
+
# where session id will be a server generated random id. If false,
|
|
1026
|
+
# runs query with an existing {#session_id=}, otherwise runs query in
|
|
1027
|
+
# non-session mode. The default value is `false`.
|
|
1028
|
+
#
|
|
1029
|
+
# @param [Boolean] value The create_session property. The default
|
|
1030
|
+
# value is `false`.
|
|
1031
|
+
#
|
|
1032
|
+
# @!group Attributes
|
|
1033
|
+
def create_session= value
|
|
1034
|
+
@gapi.configuration.query.create_session = value
|
|
1035
|
+
end
|
|
1036
|
+
|
|
1037
|
+
##
|
|
1038
|
+
# Sets the session ID for a query run in session mode. See {#create_session=}.
|
|
1039
|
+
#
|
|
1040
|
+
# @param [String] value The session ID. The default value is `nil`.
|
|
1041
|
+
#
|
|
1042
|
+
# @!group Attributes
|
|
1043
|
+
def session_id= value
|
|
1044
|
+
@gapi.configuration.query.connection_properties ||= []
|
|
1045
|
+
prop = @gapi.configuration.query.connection_properties.find { |cp| cp.key == "session_id" }
|
|
1046
|
+
if prop
|
|
1047
|
+
prop.value = value
|
|
1048
|
+
else
|
|
1049
|
+
prop = Google::Apis::BigqueryV2::ConnectionProperty.new key: "session_id", value: value
|
|
1050
|
+
@gapi.configuration.query.connection_properties << prop
|
|
1051
|
+
end
|
|
1052
|
+
end
|
|
1053
|
+
|
|
1021
1054
|
##
|
|
1022
1055
|
# Sets the write disposition for when the query results table exists.
|
|
1023
1056
|
#
|
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.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: 2021-
|
|
12
|
+
date: 2021-11-17 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
|
15
15
|
name: concurrent-ruby
|