google-cloud-spanner 2.21.0 → 2.23.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.
Files changed (34) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +23 -0
  3. data/lib/google/cloud/spanner/admin/database.rb +9 -11
  4. data/lib/google/cloud/spanner/admin/instance.rb +9 -11
  5. data/lib/google/cloud/spanner/backup/job/list.rb +1 -2
  6. data/lib/google/cloud/spanner/backup/job.rb +1 -2
  7. data/lib/google/cloud/spanner/backup/list.rb +1 -3
  8. data/lib/google/cloud/spanner/backup/restore/job.rb +1 -2
  9. data/lib/google/cloud/spanner/batch_client.rb +3 -2
  10. data/lib/google/cloud/spanner/batch_snapshot.rb +14 -9
  11. data/lib/google/cloud/spanner/batch_update.rb +3 -2
  12. data/lib/google/cloud/spanner/batch_write.rb +72 -0
  13. data/lib/google/cloud/spanner/batch_write_results.rb +142 -0
  14. data/lib/google/cloud/spanner/client.rb +245 -28
  15. data/lib/google/cloud/spanner/commit.rb +4 -0
  16. data/lib/google/cloud/spanner/convert.rb +2 -2
  17. data/lib/google/cloud/spanner/database/job/list.rb +1 -2
  18. data/lib/google/cloud/spanner/database/job.rb +2 -4
  19. data/lib/google/cloud/spanner/database/list.rb +2 -3
  20. data/lib/google/cloud/spanner/fields.rb +2 -1
  21. data/lib/google/cloud/spanner/instance/config/list.rb +2 -3
  22. data/lib/google/cloud/spanner/instance/job.rb +2 -3
  23. data/lib/google/cloud/spanner/instance/list.rb +2 -3
  24. data/lib/google/cloud/spanner/lar_headers.rb +4 -0
  25. data/lib/google/cloud/spanner/mutation_group.rb +288 -0
  26. data/lib/google/cloud/spanner/project.rb +9 -27
  27. data/lib/google/cloud/spanner/results.rb +2 -2
  28. data/lib/google/cloud/spanner/service.rb +32 -6
  29. data/lib/google/cloud/spanner/session.rb +167 -17
  30. data/lib/google/cloud/spanner/snapshot.rb +5 -2
  31. data/lib/google/cloud/spanner/transaction.rb +18 -3
  32. data/lib/google/cloud/spanner/version.rb +1 -1
  33. data/lib/google-cloud-spanner.rb +6 -3
  34. metadata +26 -191
@@ -25,6 +25,7 @@ require "google/cloud/spanner/column_value"
25
25
  require "google/cloud/spanner/convert"
26
26
  require "google/cloud/spanner/commit_response"
27
27
  require "google/cloud/spanner/lar_headers"
28
+ require "google/cloud/spanner/batch_write_results"
28
29
 
29
30
  module Google
30
31
  module Cloud
@@ -148,6 +149,7 @@ module Google
148
149
  # | `BOOL` | `true`/`false` | |
149
150
  # | `INT64` | `Integer` | |
150
151
  # | `FLOAT64` | `Float` | |
152
+ # | `FLOAT32` | `Float` | |
151
153
  # | `NUMERIC` | `BigDecimal` | |
152
154
  # | `STRING` | `String` | |
153
155
  # | `DATE` | `Date` | |
@@ -174,6 +176,7 @@ module Google
174
176
  # * `:BYTES`
175
177
  # * `:DATE`
176
178
  # * `:FLOAT64`
179
+ # * `:FLOAT32`
177
180
  # * `:NUMERIC`
178
181
  # * `:INT64`
179
182
  # * `:STRING`
@@ -473,7 +476,7 @@ module Google
473
476
  results = session.execute_query \
474
477
  sql, params: params, types: types, transaction: single_use_tx,
475
478
  query_options: query_options, request_options: request_options,
476
- call_options: call_options, directed_read_options: (directed_read_options || @directed_read_options),
479
+ call_options: call_options, directed_read_options: directed_read_options || @directed_read_options,
477
480
  route_to_leader: route_to_leader
478
481
  end
479
482
  results
@@ -584,6 +587,7 @@ module Google
584
587
  # | `BOOL` | `true`/`false` | |
585
588
  # | `INT64` | `Integer` | |
586
589
  # | `FLOAT64` | `Float` | |
590
+ # | `FLOAT32` | `Float` | |
587
591
  # | `NUMERIC` | `BigDecimal` | |
588
592
  # | `STRING` | `String` | |
589
593
  # | `DATE` | `Date` | |
@@ -611,6 +615,7 @@ module Google
611
615
  # * `:BYTES`
612
616
  # * `:DATE`
613
617
  # * `:FLOAT64`
618
+ # * `:FLOAT32`
614
619
  # * `:NUMERIC`
615
620
  # * `:INT64`
616
621
  # * `:STRING`
@@ -620,6 +625,9 @@ module Google
620
625
  # `[:INT64]`.
621
626
  # * {Fields} - Nested Structs are specified by providing a Fields
622
627
  # object.
628
+ # @param [Boolean] exclude_txn_from_change_streams If set to true,
629
+ # mutations will not be recorded in change streams with DDL option
630
+ # `allow_txn_exclusion=true`.
623
631
  # @param [Hash] query_options A hash of values to specify the custom
624
632
  # query options for executing SQL query. Query options are optional.
625
633
  # The following settings can be provided:
@@ -731,6 +739,7 @@ module Google
731
739
  # request_options: request_options
732
740
  #
733
741
  def execute_partition_update sql, params: nil, types: nil,
742
+ exclude_txn_from_change_streams: false,
734
743
  query_options: nil, request_options: nil,
735
744
  call_options: nil
736
745
  ensure_service!
@@ -741,9 +750,10 @@ module Google
741
750
  route_to_leader = LARHeaders.partition_query
742
751
  results = nil
743
752
  @pool.with_session do |session|
753
+ transaction = pdml_transaction session, exclude_txn_from_change_streams: exclude_txn_from_change_streams
744
754
  results = session.execute_query \
745
755
  sql, params: params, types: types,
746
- transaction: pdml_transaction(session),
756
+ transaction: transaction,
747
757
  query_options: query_options, request_options: request_options,
748
758
  call_options: call_options, route_to_leader: route_to_leader
749
759
  end
@@ -970,7 +980,7 @@ module Google
970
980
  transaction: single_use_tx,
971
981
  request_options: request_options,
972
982
  call_options: call_options,
973
- directed_read_options: (directed_read_options || @directed_read_options),
983
+ directed_read_options: directed_read_options || @directed_read_options,
974
984
  route_to_leader: route_to_leader
975
985
  end
976
986
  results
@@ -1005,6 +1015,7 @@ module Google
1005
1015
  # | `BOOL` | `true`/`false` | |
1006
1016
  # | `INT64` | `Integer` | |
1007
1017
  # | `FLOAT64` | `Float` | |
1018
+ # | `FLOAT32` | `Float` | |
1008
1019
  # | `NUMERIC` | `BigDecimal` | |
1009
1020
  # | `STRING` | `String` | |
1010
1021
  # | `DATE` | `Date` | |
@@ -1015,6 +1026,9 @@ module Google
1015
1026
  # See [Data
1016
1027
  # types](https://cloud.google.com/spanner/docs/data-definition-language#data_types).
1017
1028
  #
1029
+ # @param [Boolean] exclude_txn_from_change_streams If set to true,
1030
+ # mutations will not be recorded in change streams with DDL option
1031
+ # `allow_txn_exclusion=true`.
1018
1032
  # @param [Hash] commit_options A hash of commit options.
1019
1033
  # e.g., return_commit_stats. Commit options are optional.
1020
1034
  # The following options can be provided:
@@ -1037,6 +1051,20 @@ module Google
1037
1051
  # * `:tag` (String) A tag used for statistics collection
1038
1052
  # about transaction. A tag must be a valid identifier of the format:
1039
1053
  # `[a-zA-Z][a-zA-Z0-9_\-]{0,49}`.
1054
+ # @param [Hash] call_options A hash of values to specify the custom
1055
+ # call options, e.g., timeout, retries, etc. Call options are
1056
+ # optional. The following settings can be provided:
1057
+ #
1058
+ # * `:timeout` (Numeric) A numeric value of custom timeout in seconds
1059
+ # that overrides the default setting.
1060
+ # * `:retry_policy` (Hash) A hash of values that overrides the default
1061
+ # setting of retry policy with the following keys:
1062
+ # * `:initial_delay` (`Numeric`) - The initial delay in seconds.
1063
+ # * `:max_delay` (`Numeric`) - The max delay in seconds.
1064
+ # * `:multiplier` (`Numeric`) - The incremental backoff multiplier.
1065
+ # * `:retry_codes` (`Array<String>`) - The error codes that should
1066
+ # trigger a retry.
1067
+ #
1040
1068
  #
1041
1069
  # @return [Time, CommitResponse] The timestamp at which the operation
1042
1070
  # committed. If commit options are set it returns {CommitResponse}.
@@ -1090,13 +1118,18 @@ module Google
1090
1118
  # { id: 2, name: "Harvey", active: true }],
1091
1119
  # request_options: request_options
1092
1120
  #
1093
- def upsert table, rows, commit_options: nil, request_options: nil
1121
+ def upsert table, rows,
1122
+ exclude_txn_from_change_streams: false,
1123
+ commit_options: nil, request_options: nil, call_options: nil
1094
1124
  request_options = Convert.to_request_options \
1095
1125
  request_options, tag_type: :transaction_tag
1096
1126
 
1097
1127
  @pool.with_session do |session|
1098
- session.upsert table, rows, commit_options: commit_options,
1099
- request_options: request_options
1128
+ session.upsert table, rows,
1129
+ exclude_txn_from_change_streams: exclude_txn_from_change_streams,
1130
+ commit_options: commit_options,
1131
+ request_options: request_options,
1132
+ call_options: call_options
1100
1133
  end
1101
1134
  end
1102
1135
  alias save upsert
@@ -1129,6 +1162,7 @@ module Google
1129
1162
  # | `BOOL` | `true`/`false` | |
1130
1163
  # | `INT64` | `Integer` | |
1131
1164
  # | `FLOAT64` | `Float` | |
1165
+ # | `FLOAT32` | `Float` | |
1132
1166
  # | `NUMERIC` | `BigDecimal` | |
1133
1167
  # | `STRING` | `String` | |
1134
1168
  # | `DATE` | `Date` | |
@@ -1138,6 +1172,9 @@ module Google
1138
1172
  #
1139
1173
  # See [Data
1140
1174
  # types](https://cloud.google.com/spanner/docs/data-definition-language#data_types).
1175
+ # @param [Boolean] exclude_txn_from_change_streams If set to true,
1176
+ # mutations will not be recorded in change streams with DDL option
1177
+ # `allow_txn_exclusion=true`.
1141
1178
  # @param [Hash] commit_options A hash of commit options.
1142
1179
  # e.g., return_commit_stats. Commit options are optional.
1143
1180
  # The following options can be provided:
@@ -1160,6 +1197,20 @@ module Google
1160
1197
  # * `:tag` (String) A tag used for statistics collection
1161
1198
  # about transaction. A tag must be a valid identifier of the
1162
1199
  # format: `[a-zA-Z][a-zA-Z0-9_\-]{0,49}`.
1200
+ # @param [Hash] call_options A hash of values to specify the custom
1201
+ # call options, e.g., timeout, retries, etc. Call options are
1202
+ # optional. The following settings can be provided:
1203
+ #
1204
+ # * `:timeout` (Numeric) A numeric value of custom timeout in seconds
1205
+ # that overrides the default setting.
1206
+ # * `:retry_policy` (Hash) A hash of values that overrides the default
1207
+ # setting of retry policy with the following keys:
1208
+ # * `:initial_delay` (`Numeric`) - The initial delay in seconds.
1209
+ # * `:max_delay` (`Numeric`) - The max delay in seconds.
1210
+ # * `:multiplier` (`Numeric`) - The incremental backoff multiplier.
1211
+ # * `:retry_codes` (`Array<String>`) - The error codes that should
1212
+ # trigger a retry.
1213
+ #
1163
1214
  #
1164
1215
  # @return [Time, CommitResponse] The timestamp at which the operation
1165
1216
  # committed. If commit options are set it returns {CommitResponse}.
@@ -1213,13 +1264,18 @@ module Google
1213
1264
  # { id: 2, name: "Harvey", active: true }],
1214
1265
  # request_options: request_options
1215
1266
  #
1216
- def insert table, rows, commit_options: nil, request_options: nil
1267
+ def insert table, rows,
1268
+ exclude_txn_from_change_streams: false,
1269
+ commit_options: nil, request_options: nil, call_options: nil
1217
1270
  request_options = Convert.to_request_options \
1218
1271
  request_options, tag_type: :transaction_tag
1219
1272
 
1220
1273
  @pool.with_session do |session|
1221
- session.insert table, rows, commit_options: commit_options,
1222
- request_options: request_options
1274
+ session.insert table, rows,
1275
+ exclude_txn_from_change_streams: exclude_txn_from_change_streams,
1276
+ commit_options: commit_options,
1277
+ request_options: request_options,
1278
+ call_options: call_options
1223
1279
  end
1224
1280
  end
1225
1281
 
@@ -1251,6 +1307,7 @@ module Google
1251
1307
  # | `BOOL` | `true`/`false` | |
1252
1308
  # | `INT64` | `Integer` | |
1253
1309
  # | `FLOAT64` | `Float` | |
1310
+ # | `FLOAT32` | `Float` | |
1254
1311
  # | `NUMERIC` | `BigDecimal` | |
1255
1312
  # | `STRING` | `String` | |
1256
1313
  # | `DATE` | `Date` | |
@@ -1260,6 +1317,9 @@ module Google
1260
1317
  #
1261
1318
  # See [Data
1262
1319
  # types](https://cloud.google.com/spanner/docs/data-definition-language#data_types).
1320
+ # @param [Boolean] exclude_txn_from_change_streams If set to true,
1321
+ # mutations will not be recorded in change streams with DDL option
1322
+ # `allow_txn_exclusion=true`.
1263
1323
  # @param [Hash] commit_options A hash of commit options.
1264
1324
  # e.g., return_commit_stats. Commit options are optional.
1265
1325
  # The following options can be provided:
@@ -1282,6 +1342,20 @@ module Google
1282
1342
  # * `:tag` (String) A tag used for statistics collection
1283
1343
  # about transaction. A tag must be a valid identifier of the
1284
1344
  # format: `[a-zA-Z][a-zA-Z0-9_\-]{0,49}`.
1345
+ # @param [Hash] call_options A hash of values to specify the custom
1346
+ # call options, e.g., timeout, retries, etc. Call options are
1347
+ # optional. The following settings can be provided:
1348
+ #
1349
+ # * `:timeout` (Numeric) A numeric value of custom timeout in seconds
1350
+ # that overrides the default setting.
1351
+ # * `:retry_policy` (Hash) A hash of values that overrides the default
1352
+ # setting of retry policy with the following keys:
1353
+ # * `:initial_delay` (`Numeric`) - The initial delay in seconds.
1354
+ # * `:max_delay` (`Numeric`) - The max delay in seconds.
1355
+ # * `:multiplier` (`Numeric`) - The incremental backoff multiplier.
1356
+ # * `:retry_codes` (`Array<String>`) - The error codes that should
1357
+ # trigger a retry.
1358
+ #
1285
1359
  #
1286
1360
  # @return [Time, CommitResponse] The timestamp at which the operation
1287
1361
  # committed. If commit options are set it returns {CommitResponse}.
@@ -1334,13 +1408,18 @@ module Google
1334
1408
  # { id: 2, name: "Harvey", active: true }],
1335
1409
  # request_options: request_options
1336
1410
  #
1337
- def update table, rows, commit_options: nil, request_options: nil
1411
+ def update table, rows,
1412
+ exclude_txn_from_change_streams: false,
1413
+ commit_options: nil, request_options: nil, call_options: nil
1338
1414
  request_options = Convert.to_request_options \
1339
1415
  request_options, tag_type: :transaction_tag
1340
1416
 
1341
1417
  @pool.with_session do |session|
1342
- session.update table, rows, commit_options: commit_options,
1343
- request_options: request_options
1418
+ session.update table, rows,
1419
+ exclude_txn_from_change_streams: exclude_txn_from_change_streams,
1420
+ commit_options: commit_options,
1421
+ request_options: request_options,
1422
+ call_options: call_options
1344
1423
  end
1345
1424
  end
1346
1425
 
@@ -1374,6 +1453,7 @@ module Google
1374
1453
  # | `BOOL` | `true`/`false` | |
1375
1454
  # | `INT64` | `Integer` | |
1376
1455
  # | `FLOAT64` | `Float` | |
1456
+ # | `FLOAT32` | `Float` | |
1377
1457
  # | `NUMERIC` | `BigDecimal` | |
1378
1458
  # | `STRING` | `String` | |
1379
1459
  # | `DATE` | `Date` | |
@@ -1383,6 +1463,9 @@ module Google
1383
1463
  #
1384
1464
  # See [Data
1385
1465
  # types](https://cloud.google.com/spanner/docs/data-definition-language#data_types).
1466
+ # @param [Boolean] exclude_txn_from_change_streams If set to true,
1467
+ # mutations will not be recorded in change streams with DDL option
1468
+ # `allow_txn_exclusion=true`.
1386
1469
  # @param [Hash] commit_options A hash of commit options.
1387
1470
  # e.g., return_commit_stats. Commit options are optional.
1388
1471
  # The following options can be provided:
@@ -1405,6 +1488,20 @@ module Google
1405
1488
  # * `:tag` (String) A tag used for statistics collection
1406
1489
  # about transaction. A tag must be a valid identifier of the
1407
1490
  # format: `[a-zA-Z][a-zA-Z0-9_\-]{0,49}`.
1491
+ # @param [Hash] call_options A hash of values to specify the custom
1492
+ # call options, e.g., timeout, retries, etc. Call options are
1493
+ # optional. The following settings can be provided:
1494
+ #
1495
+ # * `:timeout` (Numeric) A numeric value of custom timeout in seconds
1496
+ # that overrides the default setting.
1497
+ # * `:retry_policy` (Hash) A hash of values that overrides the default
1498
+ # setting of retry policy with the following keys:
1499
+ # * `:initial_delay` (`Numeric`) - The initial delay in seconds.
1500
+ # * `:max_delay` (`Numeric`) - The max delay in seconds.
1501
+ # * `:multiplier` (`Numeric`) - The incremental backoff multiplier.
1502
+ # * `:retry_codes` (`Array<String>`) - The error codes that should
1503
+ # trigger a retry.
1504
+ #
1408
1505
  #
1409
1506
  # @return [Time, CommitResponse] The timestamp at which the operation
1410
1507
  # committed. If commit options are set it returns {CommitResponse}.
@@ -1457,10 +1554,15 @@ module Google
1457
1554
  # { id: 2, name: "Harvey", active: true }],
1458
1555
  # request_options: request_options
1459
1556
  #
1460
- def replace table, rows, commit_options: nil, request_options: nil
1557
+ def replace table, rows,
1558
+ exclude_txn_from_change_streams: false,
1559
+ commit_options: nil, request_options: nil, call_options: nil
1461
1560
  @pool.with_session do |session|
1462
- session.replace table, rows, commit_options: commit_options,
1463
- request_options: request_options
1561
+ session.replace table, rows,
1562
+ exclude_txn_from_change_streams: exclude_txn_from_change_streams,
1563
+ commit_options: commit_options,
1564
+ request_options: request_options,
1565
+ call_options: call_options
1464
1566
  end
1465
1567
  end
1466
1568
 
@@ -1484,6 +1586,9 @@ module Google
1484
1586
  # @param [Object, Array<Object>] keys A single, or list of keys or key
1485
1587
  # ranges to match returned data to. Values should have exactly as many
1486
1588
  # elements as there are columns in the primary key.
1589
+ # @param [Boolean] exclude_txn_from_change_streams If set to true,
1590
+ # mutations will not be recorded in change streams with DDL option
1591
+ # `allow_txn_exclusion=true`.
1487
1592
  # @param [Hash] commit_options A hash of commit options.
1488
1593
  # e.g., return_commit_stats. Commit options are optional.
1489
1594
  # The following options can be provided:
@@ -1565,13 +1670,16 @@ module Google
1565
1670
  # request_options = { tag: "BulkDelete-Users" }
1566
1671
  # db.delete "users", [1, 2, 3], request_options: request_options
1567
1672
  #
1568
- def delete table, keys = [], commit_options: nil, request_options: nil,
1569
- call_options: nil
1673
+ def delete table, keys = [],
1674
+ exclude_txn_from_change_streams: false,
1675
+ commit_options: nil, request_options: nil, call_options: nil
1570
1676
  request_options = Convert.to_request_options \
1571
1677
  request_options, tag_type: :transaction_tag
1572
1678
 
1573
1679
  @pool.with_session do |session|
1574
- session.delete table, keys, commit_options: commit_options,
1680
+ session.delete table, keys,
1681
+ exclude_txn_from_change_streams: exclude_txn_from_change_streams,
1682
+ commit_options: commit_options,
1575
1683
  request_options: request_options,
1576
1684
  call_options: call_options
1577
1685
  end
@@ -1592,6 +1700,9 @@ module Google
1592
1700
  # this method may be appropriate for latency sensitive and/or high
1593
1701
  # throughput blind changes.
1594
1702
  #
1703
+ # @param [Boolean] exclude_txn_from_change_streams If set to true,
1704
+ # mutations will not be recorded in change streams with DDL option
1705
+ # `allow_txn_exclusion=true`.
1595
1706
  # @param [Hash] commit_options A hash of commit options.
1596
1707
  # e.g., return_commit_stats. Commit options are optional.
1597
1708
  # The following options can be provided:
@@ -1687,8 +1798,9 @@ module Google
1687
1798
  # c.insert "users", [{ id: 2, name: "Harvey", active: true }]
1688
1799
  # end
1689
1800
  #
1690
- def commit commit_options: nil, request_options: nil,
1691
- call_options: nil, &block
1801
+ def commit exclude_txn_from_change_streams: false,
1802
+ commit_options: nil, request_options: nil, call_options: nil,
1803
+ &block
1692
1804
  raise ArgumentError, "Must provide a block" unless block_given?
1693
1805
 
1694
1806
  request_options = Convert.to_request_options \
@@ -1696,12 +1808,111 @@ module Google
1696
1808
 
1697
1809
  @pool.with_session do |session|
1698
1810
  session.commit(
1811
+ exclude_txn_from_change_streams: exclude_txn_from_change_streams,
1699
1812
  commit_options: commit_options, request_options: request_options,
1700
1813
  call_options: call_options, &block
1701
1814
  )
1702
1815
  end
1703
1816
  end
1704
1817
 
1818
+ ##
1819
+ # Batches the supplied mutation groups in a collection of efficient
1820
+ # transactions.
1821
+ #
1822
+ # All mutations in a group are committed atomically. However, mutations
1823
+ # across groups can be committed non-atomically in an unspecified order
1824
+ # and thus they must be independent of each other. Partial failure is
1825
+ # possible, i.e., some groups may have been committed successfully,
1826
+ # while others may have failed. The results of individual batches are
1827
+ # streamed into the response as the batches are applied.
1828
+ #
1829
+ # BatchWrite requests are not replay protected, meaning that each mutation
1830
+ # group may be applied more than once. Replays of non-idempotent mutations
1831
+ # may have undesirable effects. For example, replays of an insert mutation
1832
+ # may produce an already exists error or if you use generated or commit
1833
+ # timestamp-based keys, it may result in additional rows being added to the
1834
+ # mutation's table. We recommend structuring your mutation groups to be
1835
+ # idempotent to avoid this issue.
1836
+ #
1837
+ # @param [Boolean] exclude_txn_from_change_streams If set to true,
1838
+ # mutations will not be recorded in change streams with DDL option
1839
+ # `allow_txn_exclusion=true`.
1840
+ # @param [Hash] request_options Common request options.
1841
+ #
1842
+ # * `:priority` (String) The relative priority for requests.
1843
+ # The priority acts as a hint to the Cloud Spanner scheduler
1844
+ # and does not guarantee priority or order of execution.
1845
+ # Valid values are `:PRIORITY_LOW`, `:PRIORITY_MEDIUM`,
1846
+ # `:PRIORITY_HIGH`. If priority not set then default is
1847
+ # `PRIORITY_UNSPECIFIED` is equivalent to `:PRIORITY_HIGH`.
1848
+ # * `:tag` (String) A per-request tag which can be applied to
1849
+ # queries or reads, used for statistics collection. Tag must be a
1850
+ # valid identifier of the form: `[a-zA-Z][a-zA-Z0-9_\-]` between 2
1851
+ # and 64 characters in length.
1852
+ #
1853
+ # @param [Hash] call_options A hash of values to specify the custom
1854
+ # call options, e.g., timeout, retries, etc. Call options are
1855
+ # optional. The following settings can be provided:
1856
+ #
1857
+ # * `:timeout` (Numeric) A numeric value of custom timeout in seconds
1858
+ # that overrides the default setting.
1859
+ # * `:retry_policy` (Hash) A hash of values that overrides the default
1860
+ # setting of retry policy with the following keys:
1861
+ # * `:initial_delay` (`Numeric`) - The initial delay in seconds.
1862
+ # * `:max_delay` (`Numeric`) - The max delay in seconds.
1863
+ # * `:multiplier` (`Numeric`) - The incremental backoff multiplier.
1864
+ # * `:retry_codes` (`Array<String>`) - The error codes that should
1865
+ # trigger a retry.
1866
+ #
1867
+ # @yield [batch_write] a batch write object
1868
+ # @yieldparam [Google::Cloud::Spanner::BatchWrite] batch_write a batch
1869
+ # write object used to add mutaion groups through {MutationGroup}.
1870
+ #
1871
+ # @return [Google::Cloud::Spanner::BatchWriteResults] The results of
1872
+ # the batch write operation. This is a stream of responses, each
1873
+ # covering a set of the mutation groups that were either applied or
1874
+ # failed together.
1875
+ #
1876
+ # @example
1877
+ # require "google/cloud/spanner"
1878
+ #
1879
+ # spanner = Google::Cloud::Spanner.new
1880
+ #
1881
+ # db = spanner.client "my-instance", "my-database"
1882
+ #
1883
+ # results = db.batch_write do |b|
1884
+ # # First mutation group
1885
+ # b.mutation_group do |mg|
1886
+ # mg.upsert "Singers", [{ SingerId: 16, FirstName: "Charlie", LastName: "Terry" }]
1887
+ # end
1888
+ #
1889
+ # # Second mutation group
1890
+ # b.mutation_group do |mg|
1891
+ # mg.upsert "Singers", [{ SingerId: 17, FirstName: "Catalina", LastName: "Smith" }]
1892
+ # mg.update "Albums", [{ SingerId: 17, AlbumId: 1, AlbumTitle: "Go Go Go" }]
1893
+ # end
1894
+ # end
1895
+ #
1896
+ # results.each do |response|
1897
+ # puts "groups applied: #{response.indexes}" if response.ok?
1898
+ # end
1899
+ #
1900
+ def batch_write exclude_txn_from_change_streams: false,
1901
+ request_options: nil,
1902
+ call_options: nil,
1903
+ &block
1904
+ raise ArgumentError, "Must provide a block" unless block_given?
1905
+
1906
+ @pool.with_session do |session|
1907
+ session.batch_write(
1908
+ exclude_txn_from_change_streams: exclude_txn_from_change_streams,
1909
+ request_options: request_options,
1910
+ call_options: call_options,
1911
+ &block
1912
+ )
1913
+ end
1914
+ end
1915
+
1705
1916
  # rubocop:disable Metrics/AbcSize
1706
1917
  # rubocop:disable Metrics/MethodLength
1707
1918
  # rubocop:disable Metrics/BlockLength
@@ -1723,6 +1934,9 @@ module Google
1723
1934
  #
1724
1935
  # @param [Numeric] deadline The total amount of time in seconds the
1725
1936
  # transaction has to succeed. The default is `120`.
1937
+ # @param [Boolean] exclude_txn_from_change_streams If set to true,
1938
+ # mutations will not be recorded in change streams with DDL option
1939
+ # `allow_txn_exclusion=true`.
1726
1940
  # @param [Hash] commit_options A hash of commit options.
1727
1941
  # e.g., return_commit_stats. Commit options are optional.
1728
1942
  # The following options can be provided:
@@ -1862,8 +2076,8 @@ module Google
1862
2076
  # tx.insert "users", [{ id: 2, name: "Harvey", active: true }]
1863
2077
  # end
1864
2078
  #
1865
- def transaction deadline: 120, commit_options: nil,
1866
- request_options: nil, call_options: nil
2079
+ def transaction deadline: 120, exclude_txn_from_change_streams: false,
2080
+ commit_options: nil, request_options: nil, call_options: nil
1867
2081
  ensure_service!
1868
2082
  unless Thread.current[IS_TRANSACTION_RUNNING_KEY].nil?
1869
2083
  raise "Nested transactions are not allowed"
@@ -1877,7 +2091,7 @@ module Google
1877
2091
  request_options, tag_type: :transaction_tag
1878
2092
 
1879
2093
  @pool.with_session do |session|
1880
- tx = session.create_empty_transaction
2094
+ tx = session.create_empty_transaction exclude_txn_from_change_streams: exclude_txn_from_change_streams
1881
2095
  if request_options
1882
2096
  tx.transaction_tag = request_options[:transaction_tag]
1883
2097
  end
@@ -1890,6 +2104,7 @@ module Google
1890
2104
  commit_resp = @project.service.commit \
1891
2105
  tx.session.path, tx.mutations,
1892
2106
  transaction_id: transaction_id,
2107
+ exclude_txn_from_change_streams: exclude_txn_from_change_streams,
1893
2108
  commit_options: commit_options,
1894
2109
  request_options: request_options,
1895
2110
  call_options: call_options
@@ -1903,7 +2118,7 @@ module Google
1903
2118
  # Sleep the amount from RetryDelay, or incremental backoff
1904
2119
  sleep(delay_from_aborted(e) || backoff *= 1.3)
1905
2120
  # Create new transaction on the session and retry the block
1906
- tx = session.create_transaction
2121
+ tx = session.create_transaction exclude_txn_from_change_streams: exclude_txn_from_change_streams
1907
2122
  retry
1908
2123
  rescue StandardError => e
1909
2124
  # Rollback transaction when handling unexpected error
@@ -2003,8 +2218,8 @@ module Google
2003
2218
  @pool.with_session do |session|
2004
2219
  snp_grpc = @project.service.create_snapshot \
2005
2220
  session.path, strong: strong,
2006
- timestamp: (timestamp || read_timestamp),
2007
- staleness: (staleness || exact_staleness),
2221
+ timestamp: timestamp || read_timestamp,
2222
+ staleness: staleness || exact_staleness,
2008
2223
  call_options: call_options
2009
2224
  Thread.current[IS_TRANSACTION_RUNNING_KEY] = true
2010
2225
  snp = Snapshot.from_grpc snp_grpc, session, @directed_read_options
@@ -2038,6 +2253,7 @@ module Google
2038
2253
  # * `:BYTES`
2039
2254
  # * `:DATE`
2040
2255
  # * `:FLOAT64`
2256
+ # * `:FLOAT32`
2041
2257
  # * `:NUMERIC`
2042
2258
  # * `:INT64`
2043
2259
  # * `:STRING`
@@ -2297,8 +2513,9 @@ module Google
2297
2513
  }.compact)))
2298
2514
  end
2299
2515
 
2300
- def pdml_transaction session
2301
- pdml_tx_grpc = @project.service.create_pdml session.path
2516
+ def pdml_transaction session, exclude_txn_from_change_streams: false
2517
+ pdml_tx_grpc = @project.service.create_pdml session.path,
2518
+ exclude_txn_from_change_streams: exclude_txn_from_change_streams
2302
2519
  V1::TransactionSelector.new id: pdml_tx_grpc.id
2303
2520
  end
2304
2521
 
@@ -69,6 +69,7 @@ module Google
69
69
  # | `BOOL` | `true`/`false` | |
70
70
  # | `INT64` | `Integer` | |
71
71
  # | `FLOAT64` | `Float` | |
72
+ # | `FLOAT32` | `Float` | |
72
73
  # | `NUMERIC` | `BigDecimal` | |
73
74
  # | `STRING` | `String` | |
74
75
  # | `DATE` | `Date` | |
@@ -128,6 +129,7 @@ module Google
128
129
  # | `BOOL` | `true`/`false` | |
129
130
  # | `INT64` | `Integer` | |
130
131
  # | `FLOAT64` | `Float` | |
132
+ # | `FLOAT32` | `Float` | |
131
133
  # | `NUMERIC` | `BigDecimal` | |
132
134
  # | `STRING` | `String` | |
133
135
  # | `DATE` | `Date` | |
@@ -186,6 +188,7 @@ module Google
186
188
  # | `BOOL` | `true`/`false` | |
187
189
  # | `INT64` | `Integer` | |
188
190
  # | `FLOAT64` | `Float` | |
191
+ # | `FLOAT32` | `Float` | |
189
192
  # | `NUMERIC` | `BigDecimal` | |
190
193
  # | `STRING` | `String` | |
191
194
  # | `DATE` | `Date` | |
@@ -246,6 +249,7 @@ module Google
246
249
  # | `BOOL` | `true`/`false` | |
247
250
  # | `INT64` | `Integer` | |
248
251
  # | `FLOAT64` | `Float` | |
252
+ # | `FLOAT32` | `Float` | |
249
253
  # | `NUMERIC` | `BigDecimal` | |
250
254
  # | `STRING` | `String` | |
251
255
  # | `DATE` | `Date` | |
@@ -183,7 +183,7 @@ module Google
183
183
  when :PG_NUMERIC
184
184
  V1::Type.new(code: :NUMERIC, type_annotation: :PG_NUMERIC)
185
185
  when :PG_JSONB
186
- V1::Type.new(code: :JSON, type_annotation: :PG_JSONB)
186
+ V1::Type.new(code: :JSON, type_annotation: :PG_JSONB)
187
187
  else
188
188
  V1::Type.new(code: field)
189
189
  end
@@ -197,7 +197,7 @@ module Google
197
197
  value.bool_value
198
198
  when :INT64
199
199
  Integer value.string_value
200
- when :FLOAT64
200
+ when :FLOAT32, :FLOAT64
201
201
  if value.kind == :string_value
202
202
  if value.string_value == "Infinity"
203
203
  Float::INFINITY
@@ -30,8 +30,7 @@ module Google
30
30
  # operations.
31
31
  #
32
32
  # @deprecated Use the result of
33
- # {Google::Cloud::Spanner::Admin::Database#database_admin Client#list_database_operations}
34
- # instead.
33
+ # {Google::Cloud::Spanner::Admin::Database.database_admin}.list_database_operations instead.
35
34
  #
36
35
  class List < DelegateClass(::Array)
37
36
  # @private
@@ -36,8 +36,7 @@ module Google
36
36
  # Long-running Operation
37
37
  #
38
38
  # @deprecated Use the long-running operation returned by
39
- # {Google::Cloud::Spanner::Admin::Database#database_admin Client#create_database}
40
- # instead.
39
+ # {Google::Cloud::Spanner::Admin::Database.database_admin}.create_database instead.
41
40
  #
42
41
  # @example
43
42
  # require "google/cloud/spanner"
@@ -95,8 +94,7 @@ module Google
95
94
  def database
96
95
  return nil unless done?
97
96
  return nil unless @grpc.grpc_op.result == :response
98
- return nil unless @grpc.results.instance_of? \
99
- Admin::Database::V1::Database
97
+ return nil unless @grpc.results.instance_of? Admin::Database::V1::Database
100
98
  Database.from_grpc @grpc.results, service
101
99
  end
102
100
 
@@ -26,9 +26,8 @@ module Google
26
26
  # Database::List is a special case Array with additional
27
27
  # values.
28
28
  #
29
- # @deprecated Use the result of
30
- # {Google::Cloud::Spanner::Admin::Database#database_admin Client#list_databases}
31
- # instead.
29
+ # @deprecated Use the result of {Google::Cloud::Spanner::Admin::Database.database_admin}.list_databases
30
+ # instead.
32
31
  class List < DelegateClass(::Array)
33
32
  ##
34
33
  # If not empty, indicates that there are more records that match
@@ -63,6 +63,7 @@ module Google
63
63
  # * `:BYTES`
64
64
  # * `:DATE`
65
65
  # * `:FLOAT64`
66
+ # * `:FLOAT32`
66
67
  # * `:NUMERIC`
67
68
  # * `:INT64`
68
69
  # * `:STRING`
@@ -173,7 +174,7 @@ module Google
173
174
  # @return [Boolean] Returns `true` if there are duplicate names.
174
175
  #
175
176
  def duplicate_names?
176
- keys.group_by { |e| e }.select { |_k, v| v.size > 1 }.any?
177
+ keys.group_by { |e| e }.any? { |_k, v| v.size > 1 }
177
178
  end
178
179
 
179
180
  ##