Class: Google::Cloud::Spanner::V1::SpannerClient

Inherits:
Object
  • Object
show all
Defined in:
lib/google/cloud/spanner/v1/spanner_client.rb

Overview

Cloud Spanner API

The Cloud Spanner API can be used to manage sessions and execute transactions on data stored in Cloud Spanner databases.

Constant Summary collapse

SERVICE_ADDRESS =

The default address of the service.

"spanner.googleapis.com".freeze
DEFAULT_SERVICE_PORT =

The default port of the service.

443
GRPC_INTERCEPTORS =

The default set of gRPC interceptors.

[]
DEFAULT_TIMEOUT =
30
ALL_SCOPES =

The scopes needed to make gRPC calls to all of the methods defined in this service.

[
  "https://www.googleapis.com/auth/cloud-platform",
  "https://www.googleapis.com/auth/spanner.data"
].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(credentials: nil, scopes: ALL_SCOPES, client_config: {}, timeout: DEFAULT_TIMEOUT, metadata: nil, exception_transformer: nil, lib_name: nil, lib_version: "") ⇒ SpannerClient

Returns a new instance of SpannerClient

Parameters:

  • credentials (Google::Auth::Credentials, String, Hash, GRPC::Core::Channel, GRPC::Core::ChannelCredentials, Proc)

    Provides the means for authenticating requests made by the client. This parameter can be many types. A Google::Auth::Credentials uses a the properties of its represented keyfile for authenticating requests made by this client. A String will be treated as the path to the keyfile to be used for the construction of credentials for this client. A Hash will be treated as the contents of a keyfile to be used for the construction of credentials for this client. A GRPC::Core::Channel will be used to make calls through. A GRPC::Core::ChannelCredentials for the setting up the RPC client. The channel credentials should already be composed with a GRPC::Core::CallCredentials object. A Proc will be used as an updater_proc for the Grpc channel. The proc transforms the metadata for requests, generally, to give OAuth credentials.

  • scopes (Array<String>)

    The OAuth scopes for this service. This parameter is ignored if an updater_proc is supplied.

  • client_config (Hash)

    A Hash for call options for each method. See Google::Gax#construct_settings for the structure of this data. Falls back to the default config if not specified or the specified config is missing data points.

  • timeout (Numeric)

    The default timeout, in seconds, for calls made through this client.

  • metadata (Hash)

    Default metadata to be sent with each request. This can be overridden on a per call basis.

  • exception_transformer (Proc)

    An optional proc that intercepts any exceptions raised during an API call to inject custom error handling.



141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
# File 'lib/google/cloud/spanner/v1/spanner_client.rb', line 141

def initialize \
    credentials: nil,
    scopes: ALL_SCOPES,
    client_config: {},
    timeout: DEFAULT_TIMEOUT,
    metadata: nil,
    exception_transformer: nil,
    lib_name: nil,
    lib_version: ""
  # These require statements are intentionally placed here to initialize
  # the gRPC module only when it's required.
  # See https://github.com/googleapis/toolkit/issues/446
  require "google/gax/grpc"
  require "google/spanner/v1/spanner_services_pb"

  credentials ||= Google::Cloud::Spanner::V1::Credentials.default

  if credentials.is_a?(String) || credentials.is_a?(Hash)
    updater_proc = Google::Cloud::Spanner::V1::Credentials.new(credentials).updater_proc
  end
  if credentials.is_a?(GRPC::Core::Channel)
    channel = credentials
  end
  if credentials.is_a?(GRPC::Core::ChannelCredentials)
    chan_creds = credentials
  end
  if credentials.is_a?(Proc)
    updater_proc = credentials
  end
  if credentials.is_a?(Google::Auth::Credentials)
    updater_proc = credentials.updater_proc
  end

  package_version = Gem.loaded_specs['google-cloud-spanner'].version.version

  google_api_client = "gl-ruby/#{RUBY_VERSION}"
  google_api_client << " #{lib_name}/#{lib_version}" if lib_name
  google_api_client << " gapic/#{package_version} gax/#{Google::Gax::VERSION}"
  google_api_client << " grpc/#{GRPC::VERSION}"
  google_api_client.freeze

  headers = { :"x-goog-api-client" => google_api_client }
  headers.merge!() unless .nil?
  client_config_file = Pathname.new(__dir__).join(
    "spanner_client_config.json"
  )
  defaults = client_config_file.open do |f|
    Google::Gax.construct_settings(
      "google.spanner.v1.Spanner",
      JSON.parse(f.read),
      client_config,
      Google::Gax::Grpc::STATUS_CODE_NAMES,
      timeout,
      page_descriptors: PAGE_DESCRIPTORS,
      errors: Google::Gax::Grpc::API_ERRORS,
      metadata: headers
    )
  end

  # Allow overriding the service path/port in subclasses.
  service_path = self.class::SERVICE_ADDRESS
  port = self.class::DEFAULT_SERVICE_PORT
  interceptors = self.class::GRPC_INTERCEPTORS
  @spanner_stub = Google::Gax::Grpc.create_stub(
    service_path,
    port,
    chan_creds: chan_creds,
    channel: channel,
    updater_proc: updater_proc,
    scopes: scopes,
    interceptors: interceptors,
    &Google::Spanner::V1::Spanner::Stub.method(:new)
  )

  @create_session = Google::Gax.create_api_call(
    @spanner_stub.method(:create_session),
    defaults["create_session"],
    exception_transformer: exception_transformer
  )
  @get_session = Google::Gax.create_api_call(
    @spanner_stub.method(:get_session),
    defaults["get_session"],
    exception_transformer: exception_transformer
  )
  @list_sessions = Google::Gax.create_api_call(
    @spanner_stub.method(:list_sessions),
    defaults["list_sessions"],
    exception_transformer: exception_transformer
  )
  @delete_session = Google::Gax.create_api_call(
    @spanner_stub.method(:delete_session),
    defaults["delete_session"],
    exception_transformer: exception_transformer
  )
  @execute_sql = Google::Gax.create_api_call(
    @spanner_stub.method(:execute_sql),
    defaults["execute_sql"],
    exception_transformer: exception_transformer
  )
  @execute_streaming_sql = Google::Gax.create_api_call(
    @spanner_stub.method(:execute_streaming_sql),
    defaults["execute_streaming_sql"],
    exception_transformer: exception_transformer
  )
  @read = Google::Gax.create_api_call(
    @spanner_stub.method(:read),
    defaults["read"],
    exception_transformer: exception_transformer
  )
  @streaming_read = Google::Gax.create_api_call(
    @spanner_stub.method(:streaming_read),
    defaults["streaming_read"],
    exception_transformer: exception_transformer
  )
  @begin_transaction = Google::Gax.create_api_call(
    @spanner_stub.method(:begin_transaction),
    defaults["begin_transaction"],
    exception_transformer: exception_transformer
  )
  @commit = Google::Gax.create_api_call(
    @spanner_stub.method(:commit),
    defaults["commit"],
    exception_transformer: exception_transformer
  )
  @rollback = Google::Gax.create_api_call(
    @spanner_stub.method(:rollback),
    defaults["rollback"],
    exception_transformer: exception_transformer
  )
  @partition_query = Google::Gax.create_api_call(
    @spanner_stub.method(:partition_query),
    defaults["partition_query"],
    exception_transformer: exception_transformer
  )
  @partition_read = Google::Gax.create_api_call(
    @spanner_stub.method(:partition_read),
    defaults["partition_read"],
    exception_transformer: exception_transformer
  )
end

Instance Attribute Details

#spanner_stubGoogle::Spanner::V1::Spanner::Stub (readonly)

Returns:

  • (Google::Spanner::V1::Spanner::Stub)


41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
# File 'lib/google/cloud/spanner/v1/spanner_client.rb', line 41

class SpannerClient
  attr_reader :spanner_stub

  # The default address of the service.
  SERVICE_ADDRESS = "spanner.googleapis.com".freeze

  # The default port of the service.
  DEFAULT_SERVICE_PORT = 443

  # The default set of gRPC interceptors.
  GRPC_INTERCEPTORS = []

  DEFAULT_TIMEOUT = 30

  PAGE_DESCRIPTORS = {
    "list_sessions" => Google::Gax::PageDescriptor.new(
      "page_token",
      "next_page_token",
      "sessions")
  }.freeze

  private_constant :PAGE_DESCRIPTORS

  # The scopes needed to make gRPC calls to all of the methods defined in
  # this service.
  ALL_SCOPES = [
    "https://www.googleapis.com/auth/cloud-platform",
    "https://www.googleapis.com/auth/spanner.data"
  ].freeze


  DATABASE_PATH_TEMPLATE = Google::Gax::PathTemplate.new(
    "projects/{project}/instances/{instance}/databases/{database}"
  )

  private_constant :DATABASE_PATH_TEMPLATE

  SESSION_PATH_TEMPLATE = Google::Gax::PathTemplate.new(
    "projects/{project}/instances/{instance}/databases/{database}/sessions/{session}"
  )

  private_constant :SESSION_PATH_TEMPLATE

  # Returns a fully-qualified database resource name string.
  # @param project [String]
  # @param instance [String]
  # @param database [String]
  # @return [String]
  def self.database_path project, instance, database
    DATABASE_PATH_TEMPLATE.render(
      :"project" => project,
      :"instance" => instance,
      :"database" => database
    )
  end

  # Returns a fully-qualified session resource name string.
  # @param project [String]
  # @param instance [String]
  # @param database [String]
  # @param session [String]
  # @return [String]
  def self.session_path project, instance, database, session
    SESSION_PATH_TEMPLATE.render(
      :"project" => project,
      :"instance" => instance,
      :"database" => database,
      :"session" => session
    )
  end

  # @param credentials [Google::Auth::Credentials, String, Hash, GRPC::Core::Channel, GRPC::Core::ChannelCredentials, Proc]
  #   Provides the means for authenticating requests made by the client. This parameter can
  #   be many types.
  #   A `Google::Auth::Credentials` uses a the properties of its represented keyfile for
  #   authenticating requests made by this client.
  #   A `String` will be treated as the path to the keyfile to be used for the construction of
  #   credentials for this client.
  #   A `Hash` will be treated as the contents of a keyfile to be used for the construction of
  #   credentials for this client.
  #   A `GRPC::Core::Channel` will be used to make calls through.
  #   A `GRPC::Core::ChannelCredentials` for the setting up the RPC client. The channel credentials
  #   should already be composed with a `GRPC::Core::CallCredentials` object.
  #   A `Proc` will be used as an updater_proc for the Grpc channel. The proc transforms the
  #   metadata for requests, generally, to give OAuth credentials.
  # @param scopes [Array<String>]
  #   The OAuth scopes for this service. This parameter is ignored if
  #   an updater_proc is supplied.
  # @param client_config [Hash]
  #   A Hash for call options for each method. See
  #   Google::Gax#construct_settings for the structure of
  #   this data. Falls back to the default config if not specified
  #   or the specified config is missing data points.
  # @param timeout [Numeric]
  #   The default timeout, in seconds, for calls made through this client.
  # @param metadata [Hash]
  #   Default metadata to be sent with each request. This can be overridden on a per call basis.
  # @param exception_transformer [Proc]
  #   An optional proc that intercepts any exceptions raised during an API call to inject
  #   custom error handling.
  def initialize \
      credentials: nil,
      scopes: ALL_SCOPES,
      client_config: {},
      timeout: DEFAULT_TIMEOUT,
      metadata: nil,
      exception_transformer: nil,
      lib_name: nil,
      lib_version: ""
    # These require statements are intentionally placed here to initialize
    # the gRPC module only when it's required.
    # See https://github.com/googleapis/toolkit/issues/446
    require "google/gax/grpc"
    require "google/spanner/v1/spanner_services_pb"

    credentials ||= Google::Cloud::Spanner::V1::Credentials.default

    if credentials.is_a?(String) || credentials.is_a?(Hash)
      updater_proc = Google::Cloud::Spanner::V1::Credentials.new(credentials).updater_proc
    end
    if credentials.is_a?(GRPC::Core::Channel)
      channel = credentials
    end
    if credentials.is_a?(GRPC::Core::ChannelCredentials)
      chan_creds = credentials
    end
    if credentials.is_a?(Proc)
      updater_proc = credentials
    end
    if credentials.is_a?(Google::Auth::Credentials)
      updater_proc = credentials.updater_proc
    end

    package_version = Gem.loaded_specs['google-cloud-spanner'].version.version

    google_api_client = "gl-ruby/#{RUBY_VERSION}"
    google_api_client << " #{lib_name}/#{lib_version}" if lib_name
    google_api_client << " gapic/#{package_version} gax/#{Google::Gax::VERSION}"
    google_api_client << " grpc/#{GRPC::VERSION}"
    google_api_client.freeze

    headers = { :"x-goog-api-client" => google_api_client }
    headers.merge!() unless .nil?
    client_config_file = Pathname.new(__dir__).join(
      "spanner_client_config.json"
    )
    defaults = client_config_file.open do |f|
      Google::Gax.construct_settings(
        "google.spanner.v1.Spanner",
        JSON.parse(f.read),
        client_config,
        Google::Gax::Grpc::STATUS_CODE_NAMES,
        timeout,
        page_descriptors: PAGE_DESCRIPTORS,
        errors: Google::Gax::Grpc::API_ERRORS,
        metadata: headers
      )
    end

    # Allow overriding the service path/port in subclasses.
    service_path = self.class::SERVICE_ADDRESS
    port = self.class::DEFAULT_SERVICE_PORT
    interceptors = self.class::GRPC_INTERCEPTORS
    @spanner_stub = Google::Gax::Grpc.create_stub(
      service_path,
      port,
      chan_creds: chan_creds,
      channel: channel,
      updater_proc: updater_proc,
      scopes: scopes,
      interceptors: interceptors,
      &Google::Spanner::V1::Spanner::Stub.method(:new)
    )

    @create_session = Google::Gax.create_api_call(
      @spanner_stub.method(:create_session),
      defaults["create_session"],
      exception_transformer: exception_transformer
    )
    @get_session = Google::Gax.create_api_call(
      @spanner_stub.method(:get_session),
      defaults["get_session"],
      exception_transformer: exception_transformer
    )
    @list_sessions = Google::Gax.create_api_call(
      @spanner_stub.method(:list_sessions),
      defaults["list_sessions"],
      exception_transformer: exception_transformer
    )
    @delete_session = Google::Gax.create_api_call(
      @spanner_stub.method(:delete_session),
      defaults["delete_session"],
      exception_transformer: exception_transformer
    )
    @execute_sql = Google::Gax.create_api_call(
      @spanner_stub.method(:execute_sql),
      defaults["execute_sql"],
      exception_transformer: exception_transformer
    )
    @execute_streaming_sql = Google::Gax.create_api_call(
      @spanner_stub.method(:execute_streaming_sql),
      defaults["execute_streaming_sql"],
      exception_transformer: exception_transformer
    )
    @read = Google::Gax.create_api_call(
      @spanner_stub.method(:read),
      defaults["read"],
      exception_transformer: exception_transformer
    )
    @streaming_read = Google::Gax.create_api_call(
      @spanner_stub.method(:streaming_read),
      defaults["streaming_read"],
      exception_transformer: exception_transformer
    )
    @begin_transaction = Google::Gax.create_api_call(
      @spanner_stub.method(:begin_transaction),
      defaults["begin_transaction"],
      exception_transformer: exception_transformer
    )
    @commit = Google::Gax.create_api_call(
      @spanner_stub.method(:commit),
      defaults["commit"],
      exception_transformer: exception_transformer
    )
    @rollback = Google::Gax.create_api_call(
      @spanner_stub.method(:rollback),
      defaults["rollback"],
      exception_transformer: exception_transformer
    )
    @partition_query = Google::Gax.create_api_call(
      @spanner_stub.method(:partition_query),
      defaults["partition_query"],
      exception_transformer: exception_transformer
    )
    @partition_read = Google::Gax.create_api_call(
      @spanner_stub.method(:partition_read),
      defaults["partition_read"],
      exception_transformer: exception_transformer
    )
  end

  # Service calls

  # Creates a new session. A session can be used to perform
  # transactions that read and/or modify data in a Cloud Spanner database.
  # Sessions are meant to be reused for many consecutive
  # transactions.
  #
  # Sessions can only execute one transaction at a time. To execute
  # multiple concurrent read-write/write-only transactions, create
  # multiple sessions. Note that standalone reads and queries use a
  # transaction internally, and count toward the one transaction
  # limit.
  #
  # Cloud Spanner limits the number of sessions that can exist at any given
  # time; thus, it is a good idea to delete idle and/or unneeded sessions.
  # Aside from explicit deletes, Cloud Spanner can delete sessions for which no
  # operations are sent for more than an hour. If a session is deleted,
  # requests to it return +NOT_FOUND+.
  #
  # Idle sessions can be kept alive by sending a trivial SQL query
  # periodically, e.g., +"SELECT 1"+.
  #
  # @param database [String]
  #   Required. The database in which the new session is created.
  # @param session [Google::Spanner::V1::Session | Hash]
  #   The session to create.
  #   A hash of the same form as `Google::Spanner::V1::Session`
  #   can also be provided.
  # @param options [Google::Gax::CallOptions]
  #   Overrides the default settings for this call, e.g, timeout,
  #   retries, etc.
  # @yield [result, operation] Access the result along with the RPC operation
  # @yieldparam result [Google::Spanner::V1::Session]
  # @yieldparam operation [GRPC::ActiveCall::Operation]
  # @return [Google::Spanner::V1::Session]
  # @raise [Google::Gax::GaxError] if the RPC is aborted.
  # @example
  #   require "google/cloud/spanner"
  #
  #   spanner_client = Google::Cloud::Spanner.new(version: :v1)
  #   formatted_database = Google::Cloud::Spanner::V1::SpannerClient.database_path("[PROJECT]", "[INSTANCE]", "[DATABASE]")
  #   response = spanner_client.create_session(formatted_database)

  def create_session \
      database,
      session: nil,
      options: nil,
      &block
    req = {
      database: database,
      session: session
    }.delete_if { |_, v| v.nil? }
    req = Google::Gax::to_proto(req, Google::Spanner::V1::CreateSessionRequest)
    @create_session.call(req, options, &block)
  end

  # Gets a session. Returns +NOT_FOUND+ if the session does not exist.
  # This is mainly useful for determining whether a session is still
  # alive.
  #
  # @param name [String]
  #   Required. The name of the session to retrieve.
  # @param options [Google::Gax::CallOptions]
  #   Overrides the default settings for this call, e.g, timeout,
  #   retries, etc.
  # @yield [result, operation] Access the result along with the RPC operation
  # @yieldparam result [Google::Spanner::V1::Session]
  # @yieldparam operation [GRPC::ActiveCall::Operation]
  # @return [Google::Spanner::V1::Session]
  # @raise [Google::Gax::GaxError] if the RPC is aborted.
  # @example
  #   require "google/cloud/spanner"
  #
  #   spanner_client = Google::Cloud::Spanner.new(version: :v1)
  #   formatted_name = Google::Cloud::Spanner::V1::SpannerClient.session_path("[PROJECT]", "[INSTANCE]", "[DATABASE]", "[SESSION]")
  #   response = spanner_client.get_session(formatted_name)

  def get_session \
      name,
      options: nil,
      &block
    req = {
      name: name
    }.delete_if { |_, v| v.nil? }
    req = Google::Gax::to_proto(req, Google::Spanner::V1::GetSessionRequest)
    @get_session.call(req, options, &block)
  end

  # Lists all sessions in a given database.
  #
  # @param database [String]
  #   Required. The database in which to list sessions.
  # @param page_size [Integer]
  #   The maximum number of resources contained in the underlying API
  #   response. If page streaming is performed per-resource, this
  #   parameter does not affect the return value. If page streaming is
  #   performed per-page, this determines the maximum number of
  #   resources in a page.
  # @param filter [String]
  #   An expression for filtering the results of the request. Filter rules are
  #   case insensitive. The fields eligible for filtering are:
  #
  #   * +labels.key+ where key is the name of a label
  #
  #   Some examples of using filters are:
  #
  #   * +labels.env:*+ --> The session has the label "env".
  #     * +labels.env:dev+ --> The session has the label "env" and the value of
  #       the label contains the string "dev".
  # @param options [Google::Gax::CallOptions]
  #   Overrides the default settings for this call, e.g, timeout,
  #   retries, etc.
  # @yield [result, operation] Access the result along with the RPC operation
  # @yieldparam result [Google::Gax::PagedEnumerable<Google::Spanner::V1::Session>]
  # @yieldparam operation [GRPC::ActiveCall::Operation]
  # @return [Google::Gax::PagedEnumerable<Google::Spanner::V1::Session>]
  #   An enumerable of Google::Spanner::V1::Session instances.
  #   See Google::Gax::PagedEnumerable documentation for other
  #   operations such as per-page iteration or access to the response
  #   object.
  # @raise [Google::Gax::GaxError] if the RPC is aborted.
  # @example
  #   require "google/cloud/spanner"
  #
  #   spanner_client = Google::Cloud::Spanner.new(version: :v1)
  #   formatted_database = Google::Cloud::Spanner::V1::SpannerClient.database_path("[PROJECT]", "[INSTANCE]", "[DATABASE]")
  #
  #   # Iterate over all results.
  #   spanner_client.list_sessions(formatted_database).each do |element|
  #     # Process element.
  #   end
  #
  #   # Or iterate over results one page at a time.
  #   spanner_client.list_sessions(formatted_database).each_page do |page|
  #     # Process each page at a time.
  #     page.each do |element|
  #       # Process element.
  #     end
  #   end

  def list_sessions \
      database,
      page_size: nil,
      filter: nil,
      options: nil,
      &block
    req = {
      database: database,
      page_size: page_size,
      filter: filter
    }.delete_if { |_, v| v.nil? }
    req = Google::Gax::to_proto(req, Google::Spanner::V1::ListSessionsRequest)
    @list_sessions.call(req, options, &block)
  end

  # Ends a session, releasing server resources associated with it.
  #
  # @param name [String]
  #   Required. The name of the session to delete.
  # @param options [Google::Gax::CallOptions]
  #   Overrides the default settings for this call, e.g, timeout,
  #   retries, etc.
  # @yield [result, operation] Access the result along with the RPC operation
  # @yieldparam result []
  # @yieldparam operation [GRPC::ActiveCall::Operation]
  # @raise [Google::Gax::GaxError] if the RPC is aborted.
  # @example
  #   require "google/cloud/spanner"
  #
  #   spanner_client = Google::Cloud::Spanner.new(version: :v1)
  #   formatted_name = Google::Cloud::Spanner::V1::SpannerClient.session_path("[PROJECT]", "[INSTANCE]", "[DATABASE]", "[SESSION]")
  #   spanner_client.delete_session(formatted_name)

  def delete_session \
      name,
      options: nil,
      &block
    req = {
      name: name
    }.delete_if { |_, v| v.nil? }
    req = Google::Gax::to_proto(req, Google::Spanner::V1::DeleteSessionRequest)
    @delete_session.call(req, options, &block)
    nil
  end

  # Executes an SQL query, returning all rows in a single reply. This
  # method cannot be used to return a result set larger than 10 MiB;
  # if the query yields more data than that, the query fails with
  # a +FAILED_PRECONDITION+ error.
  #
  # Queries inside read-write transactions might return +ABORTED+. If
  # this occurs, the application should restart the transaction from
  # the beginning. See {Google::Spanner::V1::Transaction Transaction} for more details.
  #
  # Larger result sets can be fetched in streaming fashion by calling
  # {Google::Spanner::V1::Spanner::ExecuteStreamingSql ExecuteStreamingSql} instead.
  #
  # @param session [String]
  #   Required. The session in which the SQL query should be performed.
  # @param sql [String]
  #   Required. The SQL query string.
  # @param transaction [Google::Spanner::V1::TransactionSelector | Hash]
  #   The transaction to use. If none is provided, the default is a
  #   temporary read-only transaction with strong concurrency.
  #   A hash of the same form as `Google::Spanner::V1::TransactionSelector`
  #   can also be provided.
  # @param params [Google::Protobuf::Struct | Hash]
  #   The SQL query string can contain parameter placeholders. A parameter
  #   placeholder consists of +'@'+ followed by the parameter
  #   name. Parameter names consist of any combination of letters,
  #   numbers, and underscores.
  #
  #   Parameters can appear anywhere that a literal value is expected.  The same
  #   parameter name can be used more than once, for example:
  #     +"WHERE id > @msg_id AND id < @msg_id + 100"+
  #
  #   It is an error to execute an SQL query with unbound parameters.
  #
  #   Parameter values are specified using +params+, which is a JSON
  #   object whose keys are parameter names, and whose values are the
  #   corresponding parameter values.
  #   A hash of the same form as `Google::Protobuf::Struct`
  #   can also be provided.
  # @param param_types [Hash{String => Google::Spanner::V1::Type | Hash}]
  #   It is not always possible for Cloud Spanner to infer the right SQL type
  #   from a JSON value.  For example, values of type +BYTES+ and values
  #   of type +STRING+ both appear in {Google::Spanner::V1::ExecuteSqlRequest#params params} as JSON strings.
  #
  #   In these cases, +param_types+ can be used to specify the exact
  #   SQL type for some or all of the SQL query parameters. See the
  #   definition of {Google::Spanner::V1::Type Type} for more information
  #   about SQL types.
  #   A hash of the same form as `Google::Spanner::V1::Type`
  #   can also be provided.
  # @param resume_token [String]
  #   If this request is resuming a previously interrupted SQL query
  #   execution, +resume_token+ should be copied from the last
  #   {Google::Spanner::V1::PartialResultSet PartialResultSet} yielded before the interruption. Doing this
  #   enables the new SQL query execution to resume where the last one left
  #   off. The rest of the request parameters must exactly match the
  #   request that yielded this token.
  # @param query_mode [Google::Spanner::V1::ExecuteSqlRequest::QueryMode]
  #   Used to control the amount of debugging information returned in
  #   {Google::Spanner::V1::ResultSetStats ResultSetStats}. If {Google::Spanner::V1::ExecuteSqlRequest#partition_token partition_token} is set, {Google::Spanner::V1::ExecuteSqlRequest#query_mode query_mode} can only
  #   be set to {Google::Spanner::V1::ExecuteSqlRequest::QueryMode::NORMAL QueryMode::NORMAL}.
  # @param partition_token [String]
  #   If present, results will be restricted to the specified partition
  #   previously created using PartitionQuery().  There must be an exact
  #   match for the values of fields common to this message and the
  #   PartitionQueryRequest message used to create this partition_token.
  # @param options [Google::Gax::CallOptions]
  #   Overrides the default settings for this call, e.g, timeout,
  #   retries, etc.
  # @yield [result, operation] Access the result along with the RPC operation
  # @yieldparam result [Google::Spanner::V1::ResultSet]
  # @yieldparam operation [GRPC::ActiveCall::Operation]
  # @return [Google::Spanner::V1::ResultSet]
  # @raise [Google::Gax::GaxError] if the RPC is aborted.
  # @example
  #   require "google/cloud/spanner"
  #
  #   spanner_client = Google::Cloud::Spanner.new(version: :v1)
  #   formatted_session = Google::Cloud::Spanner::V1::SpannerClient.session_path("[PROJECT]", "[INSTANCE]", "[DATABASE]", "[SESSION]")
  #
  #   # TODO: Initialize +sql+:
  #   sql = ''
  #   response = spanner_client.execute_sql(formatted_session, sql)

  def execute_sql \
      session,
      sql,
      transaction: nil,
      params: nil,
      param_types: nil,
      resume_token: nil,
      query_mode: nil,
      partition_token: nil,
      options: nil,
      &block
    req = {
      session: session,
      sql: sql,
      transaction: transaction,
      params: params,
      param_types: param_types,
      resume_token: resume_token,
      query_mode: query_mode,
      partition_token: partition_token
    }.delete_if { |_, v| v.nil? }
    req = Google::Gax::to_proto(req, Google::Spanner::V1::ExecuteSqlRequest)
    @execute_sql.call(req, options, &block)
  end

  # Like {Google::Spanner::V1::Spanner::ExecuteSql ExecuteSql}, except returns the result
  # set as a stream. Unlike {Google::Spanner::V1::Spanner::ExecuteSql ExecuteSql}, there
  # is no limit on the size of the returned result set. However, no
  # individual row in the result set can exceed 100 MiB, and no
  # column value can exceed 10 MiB.
  #
  # @param session [String]
  #   Required. The session in which the SQL query should be performed.
  # @param sql [String]
  #   Required. The SQL query string.
  # @param transaction [Google::Spanner::V1::TransactionSelector | Hash]
  #   The transaction to use. If none is provided, the default is a
  #   temporary read-only transaction with strong concurrency.
  #   A hash of the same form as `Google::Spanner::V1::TransactionSelector`
  #   can also be provided.
  # @param params [Google::Protobuf::Struct | Hash]
  #   The SQL query string can contain parameter placeholders. A parameter
  #   placeholder consists of +'@'+ followed by the parameter
  #   name. Parameter names consist of any combination of letters,
  #   numbers, and underscores.
  #
  #   Parameters can appear anywhere that a literal value is expected.  The same
  #   parameter name can be used more than once, for example:
  #     +"WHERE id > @msg_id AND id < @msg_id + 100"+
  #
  #   It is an error to execute an SQL query with unbound parameters.
  #
  #   Parameter values are specified using +params+, which is a JSON
  #   object whose keys are parameter names, and whose values are the
  #   corresponding parameter values.
  #   A hash of the same form as `Google::Protobuf::Struct`
  #   can also be provided.
  # @param param_types [Hash{String => Google::Spanner::V1::Type | Hash}]
  #   It is not always possible for Cloud Spanner to infer the right SQL type
  #   from a JSON value.  For example, values of type +BYTES+ and values
  #   of type +STRING+ both appear in {Google::Spanner::V1::ExecuteSqlRequest#params params} as JSON strings.
  #
  #   In these cases, +param_types+ can be used to specify the exact
  #   SQL type for some or all of the SQL query parameters. See the
  #   definition of {Google::Spanner::V1::Type Type} for more information
  #   about SQL types.
  #   A hash of the same form as `Google::Spanner::V1::Type`
  #   can also be provided.
  # @param resume_token [String]
  #   If this request is resuming a previously interrupted SQL query
  #   execution, +resume_token+ should be copied from the last
  #   {Google::Spanner::V1::PartialResultSet PartialResultSet} yielded before the interruption. Doing this
  #   enables the new SQL query execution to resume where the last one left
  #   off. The rest of the request parameters must exactly match the
  #   request that yielded this token.
  # @param query_mode [Google::Spanner::V1::ExecuteSqlRequest::QueryMode]
  #   Used to control the amount of debugging information returned in
  #   {Google::Spanner::V1::ResultSetStats ResultSetStats}. If {Google::Spanner::V1::ExecuteSqlRequest#partition_token partition_token} is set, {Google::Spanner::V1::ExecuteSqlRequest#query_mode query_mode} can only
  #   be set to {Google::Spanner::V1::ExecuteSqlRequest::QueryMode::NORMAL QueryMode::NORMAL}.
  # @param partition_token [String]
  #   If present, results will be restricted to the specified partition
  #   previously created using PartitionQuery().  There must be an exact
  #   match for the values of fields common to this message and the
  #   PartitionQueryRequest message used to create this partition_token.
  # @param options [Google::Gax::CallOptions]
  #   Overrides the default settings for this call, e.g, timeout,
  #   retries, etc.
  # @return [Enumerable<Google::Spanner::V1::PartialResultSet>]
  #   An enumerable of Google::Spanner::V1::PartialResultSet instances.
  #
  # @raise [Google::Gax::GaxError] if the RPC is aborted.
  # @example
  #   require "google/cloud/spanner"
  #
  #   spanner_client = Google::Cloud::Spanner.new(version: :v1)
  #   formatted_session = Google::Cloud::Spanner::V1::SpannerClient.session_path("[PROJECT]", "[INSTANCE]", "[DATABASE]", "[SESSION]")
  #
  #   # TODO: Initialize +sql+:
  #   sql = ''
  #   spanner_client.execute_streaming_sql(formatted_session, sql).each do |element|
  #     # Process element.
  #   end

  def execute_streaming_sql \
      session,
      sql,
      transaction: nil,
      params: nil,
      param_types: nil,
      resume_token: nil,
      query_mode: nil,
      partition_token: nil,
      options: nil
    req = {
      session: session,
      sql: sql,
      transaction: transaction,
      params: params,
      param_types: param_types,
      resume_token: resume_token,
      query_mode: query_mode,
      partition_token: partition_token
    }.delete_if { |_, v| v.nil? }
    req = Google::Gax::to_proto(req, Google::Spanner::V1::ExecuteSqlRequest)
    @execute_streaming_sql.call(req, options)
  end

  # Reads rows from the database using key lookups and scans, as a
  # simple key/value style alternative to
  # {Google::Spanner::V1::Spanner::ExecuteSql ExecuteSql}.  This method cannot be used to
  # return a result set larger than 10 MiB; if the read matches more
  # data than that, the read fails with a +FAILED_PRECONDITION+
  # error.
  #
  # Reads inside read-write transactions might return +ABORTED+. If
  # this occurs, the application should restart the transaction from
  # the beginning. See {Google::Spanner::V1::Transaction Transaction} for more details.
  #
  # Larger result sets can be yielded in streaming fashion by calling
  # {Google::Spanner::V1::Spanner::StreamingRead StreamingRead} instead.
  #
  # @param session [String]
  #   Required. The session in which the read should be performed.
  # @param table [String]
  #   Required. The name of the table in the database to be read.
  # @param columns [Array<String>]
  #   The columns of {Google::Spanner::V1::ReadRequest#table table} to be returned for each row matching
  #   this request.
  # @param key_set [Google::Spanner::V1::KeySet | Hash]
  #   Required. +key_set+ identifies the rows to be yielded. +key_set+ names the
  #   primary keys of the rows in {Google::Spanner::V1::ReadRequest#table table} to be yielded, unless {Google::Spanner::V1::ReadRequest#index index}
  #   is present. If {Google::Spanner::V1::ReadRequest#index index} is present, then {Google::Spanner::V1::ReadRequest#key_set key_set} instead names
  #   index keys in {Google::Spanner::V1::ReadRequest#index index}.
  #
  #   If the {Google::Spanner::V1::ReadRequest#partition_token partition_token} field is empty, rows are yielded
  #   in table primary key order (if {Google::Spanner::V1::ReadRequest#index index} is empty) or index key order
  #   (if {Google::Spanner::V1::ReadRequest#index index} is non-empty).  If the {Google::Spanner::V1::ReadRequest#partition_token partition_token} field is not
  #   empty, rows will be yielded in an unspecified order.
  #
  #   It is not an error for the +key_set+ to name rows that do not
  #   exist in the database. Read yields nothing for nonexistent rows.
  #   A hash of the same form as `Google::Spanner::V1::KeySet`
  #   can also be provided.
  # @param transaction [Google::Spanner::V1::TransactionSelector | Hash]
  #   The transaction to use. If none is provided, the default is a
  #   temporary read-only transaction with strong concurrency.
  #   A hash of the same form as `Google::Spanner::V1::TransactionSelector`
  #   can also be provided.
  # @param index [String]
  #   If non-empty, the name of an index on {Google::Spanner::V1::ReadRequest#table table}. This index is
  #   used instead of the table primary key when interpreting {Google::Spanner::V1::ReadRequest#key_set key_set}
  #   and sorting result rows. See {Google::Spanner::V1::ReadRequest#key_set key_set} for further information.
  # @param limit [Integer]
  #   If greater than zero, only the first +limit+ rows are yielded. If +limit+
  #   is zero, the default is no limit. A limit cannot be specified if
  #   +partition_token+ is set.
  # @param resume_token [String]
  #   If this request is resuming a previously interrupted read,
  #   +resume_token+ should be copied from the last
  #   {Google::Spanner::V1::PartialResultSet PartialResultSet} yielded before the interruption. Doing this
  #   enables the new read to resume where the last read left off. The
  #   rest of the request parameters must exactly match the request
  #   that yielded this token.
  # @param partition_token [String]
  #   If present, results will be restricted to the specified partition
  #   previously created using PartitionRead().    There must be an exact
  #   match for the values of fields common to this message and the
  #   PartitionReadRequest message used to create this partition_token.
  # @param options [Google::Gax::CallOptions]
  #   Overrides the default settings for this call, e.g, timeout,
  #   retries, etc.
  # @yield [result, operation] Access the result along with the RPC operation
  # @yieldparam result [Google::Spanner::V1::ResultSet]
  # @yieldparam operation [GRPC::ActiveCall::Operation]
  # @return [Google::Spanner::V1::ResultSet]
  # @raise [Google::Gax::GaxError] if the RPC is aborted.
  # @example
  #   require "google/cloud/spanner"
  #
  #   spanner_client = Google::Cloud::Spanner.new(version: :v1)
  #   formatted_session = Google::Cloud::Spanner::V1::SpannerClient.session_path("[PROJECT]", "[INSTANCE]", "[DATABASE]", "[SESSION]")
  #
  #   # TODO: Initialize +table+:
  #   table = ''
  #
  #   # TODO: Initialize +columns+:
  #   columns = []
  #
  #   # TODO: Initialize +key_set+:
  #   key_set = {}
  #   response = spanner_client.read(formatted_session, table, columns, key_set)

  def read \
      session,
      table,
      columns,
      key_set,
      transaction: nil,
      index: nil,
      limit: nil,
      resume_token: nil,
      partition_token: nil,
      options: nil,
      &block
    req = {
      session: session,
      table: table,
      columns: columns,
      key_set: key_set,
      transaction: transaction,
      index: index,
      limit: limit,
      resume_token: resume_token,
      partition_token: partition_token
    }.delete_if { |_, v| v.nil? }
    req = Google::Gax::to_proto(req, Google::Spanner::V1::ReadRequest)
    @read.call(req, options, &block)
  end

  # Like {Google::Spanner::V1::Spanner::Read Read}, except returns the result set as a
  # stream. Unlike {Google::Spanner::V1::Spanner::Read Read}, there is no limit on the
  # size of the returned result set. However, no individual row in
  # the result set can exceed 100 MiB, and no column value can exceed
  # 10 MiB.
  #
  # @param session [String]
  #   Required. The session in which the read should be performed.
  # @param table [String]
  #   Required. The name of the table in the database to be read.
  # @param columns [Array<String>]
  #   The columns of {Google::Spanner::V1::ReadRequest#table table} to be returned for each row matching
  #   this request.
  # @param key_set [Google::Spanner::V1::KeySet | Hash]
  #   Required. +key_set+ identifies the rows to be yielded. +key_set+ names the
  #   primary keys of the rows in {Google::Spanner::V1::ReadRequest#table table} to be yielded, unless {Google::Spanner::V1::ReadRequest#index index}
  #   is present. If {Google::Spanner::V1::ReadRequest#index index} is present, then {Google::Spanner::V1::ReadRequest#key_set key_set} instead names
  #   index keys in {Google::Spanner::V1::ReadRequest#index index}.
  #
  #   If the {Google::Spanner::V1::ReadRequest#partition_token partition_token} field is empty, rows are yielded
  #   in table primary key order (if {Google::Spanner::V1::ReadRequest#index index} is empty) or index key order
  #   (if {Google::Spanner::V1::ReadRequest#index index} is non-empty).  If the {Google::Spanner::V1::ReadRequest#partition_token partition_token} field is not
  #   empty, rows will be yielded in an unspecified order.
  #
  #   It is not an error for the +key_set+ to name rows that do not
  #   exist in the database. Read yields nothing for nonexistent rows.
  #   A hash of the same form as `Google::Spanner::V1::KeySet`
  #   can also be provided.
  # @param transaction [Google::Spanner::V1::TransactionSelector | Hash]
  #   The transaction to use. If none is provided, the default is a
  #   temporary read-only transaction with strong concurrency.
  #   A hash of the same form as `Google::Spanner::V1::TransactionSelector`
  #   can also be provided.
  # @param index [String]
  #   If non-empty, the name of an index on {Google::Spanner::V1::ReadRequest#table table}. This index is
  #   used instead of the table primary key when interpreting {Google::Spanner::V1::ReadRequest#key_set key_set}
  #   and sorting result rows. See {Google::Spanner::V1::ReadRequest#key_set key_set} for further information.
  # @param limit [Integer]
  #   If greater than zero, only the first +limit+ rows are yielded. If +limit+
  #   is zero, the default is no limit. A limit cannot be specified if
  #   +partition_token+ is set.
  # @param resume_token [String]
  #   If this request is resuming a previously interrupted read,
  #   +resume_token+ should be copied from the last
  #   {Google::Spanner::V1::PartialResultSet PartialResultSet} yielded before the interruption. Doing this
  #   enables the new read to resume where the last read left off. The
  #   rest of the request parameters must exactly match the request
  #   that yielded this token.
  # @param partition_token [String]
  #   If present, results will be restricted to the specified partition
  #   previously created using PartitionRead().    There must be an exact
  #   match for the values of fields common to this message and the
  #   PartitionReadRequest message used to create this partition_token.
  # @param options [Google::Gax::CallOptions]
  #   Overrides the default settings for this call, e.g, timeout,
  #   retries, etc.
  # @return [Enumerable<Google::Spanner::V1::PartialResultSet>]
  #   An enumerable of Google::Spanner::V1::PartialResultSet instances.
  #
  # @raise [Google::Gax::GaxError] if the RPC is aborted.
  # @example
  #   require "google/cloud/spanner"
  #
  #   spanner_client = Google::Cloud::Spanner.new(version: :v1)
  #   formatted_session = Google::Cloud::Spanner::V1::SpannerClient.session_path("[PROJECT]", "[INSTANCE]", "[DATABASE]", "[SESSION]")
  #
  #   # TODO: Initialize +table+:
  #   table = ''
  #
  #   # TODO: Initialize +columns+:
  #   columns = []
  #
  #   # TODO: Initialize +key_set+:
  #   key_set = {}
  #   spanner_client.streaming_read(formatted_session, table, columns, key_set).each do |element|
  #     # Process element.
  #   end

  def streaming_read \
      session,
      table,
      columns,
      key_set,
      transaction: nil,
      index: nil,
      limit: nil,
      resume_token: nil,
      partition_token: nil,
      options: nil
    req = {
      session: session,
      table: table,
      columns: columns,
      key_set: key_set,
      transaction: transaction,
      index: index,
      limit: limit,
      resume_token: resume_token,
      partition_token: partition_token
    }.delete_if { |_, v| v.nil? }
    req = Google::Gax::to_proto(req, Google::Spanner::V1::ReadRequest)
    @streaming_read.call(req, options)
  end

  # Begins a new transaction. This step can often be skipped:
  # {Google::Spanner::V1::Spanner::Read Read}, {Google::Spanner::V1::Spanner::ExecuteSql ExecuteSql} and
  # {Google::Spanner::V1::Spanner::Commit Commit} can begin a new transaction as a
  # side-effect.
  #
  # @param session [String]
  #   Required. The session in which the transaction runs.
  # @param options_ [Google::Spanner::V1::TransactionOptions | Hash]
  #   Required. Options for the new transaction.
  #   A hash of the same form as `Google::Spanner::V1::TransactionOptions`
  #   can also be provided.
  # @param options [Google::Gax::CallOptions]
  #   Overrides the default settings for this call, e.g, timeout,
  #   retries, etc.
  # @yield [result, operation] Access the result along with the RPC operation
  # @yieldparam result [Google::Spanner::V1::Transaction]
  # @yieldparam operation [GRPC::ActiveCall::Operation]
  # @return [Google::Spanner::V1::Transaction]
  # @raise [Google::Gax::GaxError] if the RPC is aborted.
  # @example
  #   require "google/cloud/spanner"
  #
  #   spanner_client = Google::Cloud::Spanner.new(version: :v1)
  #   formatted_session = Google::Cloud::Spanner::V1::SpannerClient.session_path("[PROJECT]", "[INSTANCE]", "[DATABASE]", "[SESSION]")
  #
  #   # TODO: Initialize +options_+:
  #   options_ = {}
  #   response = spanner_client.begin_transaction(formatted_session, options_)

  def begin_transaction \
      session,
      options_,
      options: nil,
      &block
    req = {
      session: session,
      options: options_
    }.delete_if { |_, v| v.nil? }
    req = Google::Gax::to_proto(req, Google::Spanner::V1::BeginTransactionRequest)
    @begin_transaction.call(req, options, &block)
  end

  # Commits a transaction. The request includes the mutations to be
  # applied to rows in the database.
  #
  # +Commit+ might return an +ABORTED+ error. This can occur at any time;
  # commonly, the cause is conflicts with concurrent
  # transactions. However, it can also happen for a variety of other
  # reasons. If +Commit+ returns +ABORTED+, the caller should re-attempt
  # the transaction from the beginning, re-using the same session.
  #
  # @param session [String]
  #   Required. The session in which the transaction to be committed is running.
  # @param mutations [Array<Google::Spanner::V1::Mutation | Hash>]
  #   The mutations to be executed when this transaction commits. All
  #   mutations are applied atomically, in the order they appear in
  #   this list.
  #   A hash of the same form as `Google::Spanner::V1::Mutation`
  #   can also be provided.
  # @param transaction_id [String]
  #   Commit a previously-started transaction.
  # @param single_use_transaction [Google::Spanner::V1::TransactionOptions | Hash]
  #   Execute mutations in a temporary transaction. Note that unlike
  #   commit of a previously-started transaction, commit with a
  #   temporary transaction is non-idempotent. That is, if the
  #   +CommitRequest+ is sent to Cloud Spanner more than once (for
  #   instance, due to retries in the application, or in the
  #   transport library), it is possible that the mutations are
  #   executed more than once. If this is undesirable, use
  #   {Google::Spanner::V1::Spanner::BeginTransaction BeginTransaction} and
  #   {Google::Spanner::V1::Spanner::Commit Commit} instead.
  #   A hash of the same form as `Google::Spanner::V1::TransactionOptions`
  #   can also be provided.
  # @param options [Google::Gax::CallOptions]
  #   Overrides the default settings for this call, e.g, timeout,
  #   retries, etc.
  # @yield [result, operation] Access the result along with the RPC operation
  # @yieldparam result [Google::Spanner::V1::CommitResponse]
  # @yieldparam operation [GRPC::ActiveCall::Operation]
  # @return [Google::Spanner::V1::CommitResponse]
  # @raise [Google::Gax::GaxError] if the RPC is aborted.
  # @example
  #   require "google/cloud/spanner"
  #
  #   spanner_client = Google::Cloud::Spanner.new(version: :v1)
  #   formatted_session = Google::Cloud::Spanner::V1::SpannerClient.session_path("[PROJECT]", "[INSTANCE]", "[DATABASE]", "[SESSION]")
  #
  #   # TODO: Initialize +mutations+:
  #   mutations = []
  #   response = spanner_client.commit(formatted_session, mutations)

  def commit \
      session,
      mutations,
      transaction_id: nil,
      single_use_transaction: nil,
      options: nil,
      &block
    req = {
      session: session,
      mutations: mutations,
      transaction_id: transaction_id,
      single_use_transaction: single_use_transaction
    }.delete_if { |_, v| v.nil? }
    req = Google::Gax::to_proto(req, Google::Spanner::V1::CommitRequest)
    @commit.call(req, options, &block)
  end

  # Rolls back a transaction, releasing any locks it holds. It is a good
  # idea to call this for any transaction that includes one or more
  # {Google::Spanner::V1::Spanner::Read Read} or {Google::Spanner::V1::Spanner::ExecuteSql ExecuteSql} requests and
  # ultimately decides not to commit.
  #
  # +Rollback+ returns +OK+ if it successfully aborts the transaction, the
  # transaction was already aborted, or the transaction is not
  # found. +Rollback+ never returns +ABORTED+.
  #
  # @param session [String]
  #   Required. The session in which the transaction to roll back is running.
  # @param transaction_id [String]
  #   Required. The transaction to roll back.
  # @param options [Google::Gax::CallOptions]
  #   Overrides the default settings for this call, e.g, timeout,
  #   retries, etc.
  # @yield [result, operation] Access the result along with the RPC operation
  # @yieldparam result []
  # @yieldparam operation [GRPC::ActiveCall::Operation]
  # @raise [Google::Gax::GaxError] if the RPC is aborted.
  # @example
  #   require "google/cloud/spanner"
  #
  #   spanner_client = Google::Cloud::Spanner.new(version: :v1)
  #   formatted_session = Google::Cloud::Spanner::V1::SpannerClient.session_path("[PROJECT]", "[INSTANCE]", "[DATABASE]", "[SESSION]")
  #
  #   # TODO: Initialize +transaction_id+:
  #   transaction_id = ''
  #   spanner_client.rollback(formatted_session, transaction_id)

  def rollback \
      session,
      transaction_id,
      options: nil,
      &block
    req = {
      session: session,
      transaction_id: transaction_id
    }.delete_if { |_, v| v.nil? }
    req = Google::Gax::to_proto(req, Google::Spanner::V1::RollbackRequest)
    @rollback.call(req, options, &block)
    nil
  end

  # Creates a set of partition tokens that can be used to execute a query
  # operation in parallel.  Each of the returned partition tokens can be used
  # by {Google::Spanner::V1::Spanner::ExecuteStreamingSql ExecuteStreamingSql} to specify a subset
  # of the query result to read.  The same session and read-only transaction
  # must be used by the PartitionQueryRequest used to create the
  # partition tokens and the ExecuteSqlRequests that use the partition tokens.
  # Partition tokens become invalid when the session used to create them
  # is deleted or begins a new transaction.
  #
  # @param session [String]
  #   Required. The session used to create the partitions.
  # @param sql [String]
  #   The query request to generate partitions for. The request will fail if
  #   the query is not root partitionable. The query plan of a root
  #   partitionable query has a single distributed union operator. A distributed
  #   union operator conceptually divides one or more tables into multiple
  #   splits, remotely evaluates a subquery independently on each split, and
  #   then unions all results.
  # @param transaction [Google::Spanner::V1::TransactionSelector | Hash]
  #   Read only snapshot transactions are supported, read/write and single use
  #   transactions are not.
  #   A hash of the same form as `Google::Spanner::V1::TransactionSelector`
  #   can also be provided.
  # @param params [Google::Protobuf::Struct | Hash]
  #   The SQL query string can contain parameter placeholders. A parameter
  #   placeholder consists of +'@'+ followed by the parameter
  #   name. Parameter names consist of any combination of letters,
  #   numbers, and underscores.
  #
  #   Parameters can appear anywhere that a literal value is expected.  The same
  #   parameter name can be used more than once, for example:
  #     +"WHERE id > @msg_id AND id < @msg_id + 100"+
  #
  #   It is an error to execute an SQL query with unbound parameters.
  #
  #   Parameter values are specified using +params+, which is a JSON
  #   object whose keys are parameter names, and whose values are the
  #   corresponding parameter values.
  #   A hash of the same form as `Google::Protobuf::Struct`
  #   can also be provided.
  # @param param_types [Hash{String => Google::Spanner::V1::Type | Hash}]
  #   It is not always possible for Cloud Spanner to infer the right SQL type
  #   from a JSON value.  For example, values of type +BYTES+ and values
  #   of type +STRING+ both appear in {Google::Spanner::V1::PartitionQueryRequest#params params} as JSON strings.
  #
  #   In these cases, +param_types+ can be used to specify the exact
  #   SQL type for some or all of the SQL query parameters. See the
  #   definition of {Google::Spanner::V1::Type Type} for more information
  #   about SQL types.
  #   A hash of the same form as `Google::Spanner::V1::Type`
  #   can also be provided.
  # @param partition_options [Google::Spanner::V1::PartitionOptions | Hash]
  #   Additional options that affect how many partitions are created.
  #   A hash of the same form as `Google::Spanner::V1::PartitionOptions`
  #   can also be provided.
  # @param options [Google::Gax::CallOptions]
  #   Overrides the default settings for this call, e.g, timeout,
  #   retries, etc.
  # @yield [result, operation] Access the result along with the RPC operation
  # @yieldparam result [Google::Spanner::V1::PartitionResponse]
  # @yieldparam operation [GRPC::ActiveCall::Operation]
  # @return [Google::Spanner::V1::PartitionResponse]
  # @raise [Google::Gax::GaxError] if the RPC is aborted.
  # @example
  #   require "google/cloud/spanner"
  #
  #   spanner_client = Google::Cloud::Spanner.new(version: :v1)
  #   formatted_session = Google::Cloud::Spanner::V1::SpannerClient.session_path("[PROJECT]", "[INSTANCE]", "[DATABASE]", "[SESSION]")
  #
  #   # TODO: Initialize +sql+:
  #   sql = ''
  #   response = spanner_client.partition_query(formatted_session, sql)

  def partition_query \
      session,
      sql,
      transaction: nil,
      params: nil,
      param_types: nil,
      partition_options: nil,
      options: nil,
      &block
    req = {
      session: session,
      sql: sql,
      transaction: transaction,
      params: params,
      param_types: param_types,
      partition_options: partition_options
    }.delete_if { |_, v| v.nil? }
    req = Google::Gax::to_proto(req, Google::Spanner::V1::PartitionQueryRequest)
    @partition_query.call(req, options, &block)
  end

  # Creates a set of partition tokens that can be used to execute a read
  # operation in parallel.  Each of the returned partition tokens can be used
  # by {Google::Spanner::V1::Spanner::StreamingRead StreamingRead} to specify a subset of the read
  # result to read.  The same session and read-only transaction must be used by
  # the PartitionReadRequest used to create the partition tokens and the
  # ReadRequests that use the partition tokens.
  # Partition tokens become invalid when the session used to create them
  # is deleted or begins a new transaction.
  #
  # @param session [String]
  #   Required. The session used to create the partitions.
  # @param table [String]
  #   Required. The name of the table in the database to be read.
  # @param key_set [Google::Spanner::V1::KeySet | Hash]
  #   Required. +key_set+ identifies the rows to be yielded. +key_set+ names the
  #   primary keys of the rows in {Google::Spanner::V1::PartitionReadRequest#table table} to be yielded, unless {Google::Spanner::V1::PartitionReadRequest#index index}
  #   is present. If {Google::Spanner::V1::PartitionReadRequest#index index} is present, then {Google::Spanner::V1::PartitionReadRequest#key_set key_set} instead names
  #   index keys in {Google::Spanner::V1::PartitionReadRequest#index index}.
  #
  #   It is not an error for the +key_set+ to name rows that do not
  #   exist in the database. Read yields nothing for nonexistent rows.
  #   A hash of the same form as `Google::Spanner::V1::KeySet`
  #   can also be provided.
  # @param transaction [Google::Spanner::V1::TransactionSelector | Hash]
  #   Read only snapshot transactions are supported, read/write and single use
  #   transactions are not.
  #   A hash of the same form as `Google::Spanner::V1::TransactionSelector`
  #   can also be provided.
  # @param index [String]
  #   If non-empty, the name of an index on {Google::Spanner::V1::PartitionReadRequest#table table}. This index is
  #   used instead of the table primary key when interpreting {Google::Spanner::V1::PartitionReadRequest#key_set key_set}
  #   and sorting result rows. See {Google::Spanner::V1::PartitionReadRequest#key_set key_set} for further information.
  # @param columns [Array<String>]
  #   The columns of {Google::Spanner::V1::PartitionReadRequest#table table} to be returned for each row matching
  #   this request.
  # @param partition_options [Google::Spanner::V1::PartitionOptions | Hash]
  #   Additional options that affect how many partitions are created.
  #   A hash of the same form as `Google::Spanner::V1::PartitionOptions`
  #   can also be provided.
  # @param options [Google::Gax::CallOptions]
  #   Overrides the default settings for this call, e.g, timeout,
  #   retries, etc.
  # @yield [result, operation] Access the result along with the RPC operation
  # @yieldparam result [Google::Spanner::V1::PartitionResponse]
  # @yieldparam operation [GRPC::ActiveCall::Operation]
  # @return [Google::Spanner::V1::PartitionResponse]
  # @raise [Google::Gax::GaxError] if the RPC is aborted.
  # @example
  #   require "google/cloud/spanner"
  #
  #   spanner_client = Google::Cloud::Spanner.new(version: :v1)
  #   formatted_session = Google::Cloud::Spanner::V1::SpannerClient.session_path("[PROJECT]", "[INSTANCE]", "[DATABASE]", "[SESSION]")
  #
  #   # TODO: Initialize +table+:
  #   table = ''
  #
  #   # TODO: Initialize +key_set+:
  #   key_set = {}
  #   response = spanner_client.partition_read(formatted_session, table, key_set)

  def partition_read \
      session,
      table,
      key_set,
      transaction: nil,
      index: nil,
      columns: nil,
      partition_options: nil,
      options: nil,
      &block
    req = {
      session: session,
      table: table,
      key_set: key_set,
      transaction: transaction,
      index: index,
      columns: columns,
      partition_options: partition_options
    }.delete_if { |_, v| v.nil? }
    req = Google::Gax::to_proto(req, Google::Spanner::V1::PartitionReadRequest)
    @partition_read.call(req, options, &block)
  end
end

Class Method Details

.database_path(project, instance, database) ⇒ String

Returns a fully-qualified database resource name string.

Parameters:

  • project (String)
  • instance (String)
  • database (String)

Returns:

  • (String)


89
90
91
92
93
94
95
# File 'lib/google/cloud/spanner/v1/spanner_client.rb', line 89

def self.database_path project, instance, database
  DATABASE_PATH_TEMPLATE.render(
    :"project" => project,
    :"instance" => instance,
    :"database" => database
  )
end

.session_path(project, instance, database, session) ⇒ String

Returns a fully-qualified session resource name string.

Parameters:

  • project (String)
  • instance (String)
  • database (String)
  • session (String)

Returns:

  • (String)


103
104
105
106
107
108
109
110
# File 'lib/google/cloud/spanner/v1/spanner_client.rb', line 103

def self.session_path project, instance, database, session
  SESSION_PATH_TEMPLATE.render(
    :"project" => project,
    :"instance" => instance,
    :"database" => database,
    :"session" => session
  )
end

Instance Method Details

#begin_transaction(session, options_, options: nil) {|result, operation| ... } ⇒ Google::Spanner::V1::Transaction

Begins a new transaction. This step can often be skipped: Read, ExecuteSql and Commit can begin a new transaction as a side-effect.

Examples:

require "google/cloud/spanner"

spanner_client = Google::Cloud::Spanner.new(version: :v1)
formatted_session = Google::Cloud::Spanner::V1::SpannerClient.session_path("[PROJECT]", "[INSTANCE]", "[DATABASE]", "[SESSION]")

# TODO: Initialize +options_+:
options_ = {}
response = spanner_client.begin_transaction(formatted_session, options_)

Parameters:

  • session (String)

    Required. The session in which the transaction runs.

  • options_ (Google::Spanner::V1::TransactionOptions | Hash)

    Required. Options for the new transaction. A hash of the same form as Google::Spanner::V1::TransactionOptions can also be provided.

  • options (Google::Gax::CallOptions)

    Overrides the default settings for this call, e.g, timeout, retries, etc.

Yields:

  • (result, operation)

    Access the result along with the RPC operation

Yield Parameters:

Returns:

Raises:

  • (Google::Gax::GaxError)

    if the RPC is aborted.



922
923
924
925
926
927
928
929
930
931
932
933
# File 'lib/google/cloud/spanner/v1/spanner_client.rb', line 922

def begin_transaction \
    session,
    options_,
    options: nil,
    &block
  req = {
    session: session,
    options: options_
  }.delete_if { |_, v| v.nil? }
  req = Google::Gax::to_proto(req, Google::Spanner::V1::BeginTransactionRequest)
  @begin_transaction.call(req, options, &block)
end

#commit(session, mutations, transaction_id: nil, single_use_transaction: nil, options: nil) {|result, operation| ... } ⇒ Google::Spanner::V1::CommitResponse

Commits a transaction. The request includes the mutations to be applied to rows in the database.

+Commit+ might return an +ABORTED+ error. This can occur at any time; commonly, the cause is conflicts with concurrent transactions. However, it can also happen for a variety of other reasons. If +Commit+ returns +ABORTED+, the caller should re-attempt the transaction from the beginning, re-using the same session.

Examples:

require "google/cloud/spanner"

spanner_client = Google::Cloud::Spanner.new(version: :v1)
formatted_session = Google::Cloud::Spanner::V1::SpannerClient.session_path("[PROJECT]", "[INSTANCE]", "[DATABASE]", "[SESSION]")

# TODO: Initialize +mutations+:
mutations = []
response = spanner_client.commit(formatted_session, mutations)

Parameters:

  • session (String)

    Required. The session in which the transaction to be committed is running.

  • mutations (Array<Google::Spanner::V1::Mutation | Hash>)

    The mutations to be executed when this transaction commits. All mutations are applied atomically, in the order they appear in this list. A hash of the same form as Google::Spanner::V1::Mutation can also be provided.

  • transaction_id (String)

    Commit a previously-started transaction.

  • single_use_transaction (Google::Spanner::V1::TransactionOptions | Hash)

    Execute mutations in a temporary transaction. Note that unlike commit of a previously-started transaction, commit with a temporary transaction is non-idempotent. That is, if the +CommitRequest+ is sent to Cloud Spanner more than once (for instance, due to retries in the application, or in the transport library), it is possible that the mutations are executed more than once. If this is undesirable, use BeginTransaction and Commit instead. A hash of the same form as Google::Spanner::V1::TransactionOptions can also be provided.

  • options (Google::Gax::CallOptions)

    Overrides the default settings for this call, e.g, timeout, retries, etc.

Yields:

  • (result, operation)

    Access the result along with the RPC operation

Yield Parameters:

Returns:

Raises:

  • (Google::Gax::GaxError)

    if the RPC is aborted.



984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
# File 'lib/google/cloud/spanner/v1/spanner_client.rb', line 984

def commit \
    session,
    mutations,
    transaction_id: nil,
    single_use_transaction: nil,
    options: nil,
    &block
  req = {
    session: session,
    mutations: mutations,
    transaction_id: transaction_id,
    single_use_transaction: single_use_transaction
  }.delete_if { |_, v| v.nil? }
  req = Google::Gax::to_proto(req, Google::Spanner::V1::CommitRequest)
  @commit.call(req, options, &block)
end

#create_session(database, session: nil, options: nil) {|result, operation| ... } ⇒ Google::Spanner::V1::Session

Creates a new session. A session can be used to perform transactions that read and/or modify data in a Cloud Spanner database. Sessions are meant to be reused for many consecutive transactions.

Sessions can only execute one transaction at a time. To execute multiple concurrent read-write/write-only transactions, create multiple sessions. Note that standalone reads and queries use a transaction internally, and count toward the one transaction limit.

Cloud Spanner limits the number of sessions that can exist at any given time; thus, it is a good idea to delete idle and/or unneeded sessions. Aside from explicit deletes, Cloud Spanner can delete sessions for which no operations are sent for more than an hour. If a session is deleted, requests to it return +NOT_FOUND+.

Idle sessions can be kept alive by sending a trivial SQL query periodically, e.g., +"SELECT 1"+.

Examples:

require "google/cloud/spanner"

spanner_client = Google::Cloud::Spanner.new(version: :v1)
formatted_database = Google::Cloud::Spanner::V1::SpannerClient.database_path("[PROJECT]", "[INSTANCE]", "[DATABASE]")
response = spanner_client.create_session(formatted_database)

Parameters:

  • database (String)

    Required. The database in which the new session is created.

  • session (Google::Spanner::V1::Session | Hash)

    The session to create. A hash of the same form as Google::Spanner::V1::Session can also be provided.

  • options (Google::Gax::CallOptions)

    Overrides the default settings for this call, e.g, timeout, retries, etc.

Yields:

  • (result, operation)

    Access the result along with the RPC operation

Yield Parameters:

Returns:

Raises:

  • (Google::Gax::GaxError)

    if the RPC is aborted.



325
326
327
328
329
330
331
332
333
334
335
336
# File 'lib/google/cloud/spanner/v1/spanner_client.rb', line 325

def create_session \
    database,
    session: nil,
    options: nil,
    &block
  req = {
    database: database,
    session: session
  }.delete_if { |_, v| v.nil? }
  req = Google::Gax::to_proto(req, Google::Spanner::V1::CreateSessionRequest)
  @create_session.call(req, options, &block)
end

#delete_session(name, options: nil) {|result, operation| ... } ⇒ Object

Ends a session, releasing server resources associated with it.

Examples:

require "google/cloud/spanner"

spanner_client = Google::Cloud::Spanner.new(version: :v1)
formatted_name = Google::Cloud::Spanner::V1::SpannerClient.session_path("[PROJECT]", "[INSTANCE]", "[DATABASE]", "[SESSION]")
spanner_client.delete_session(formatted_name)

Parameters:

  • name (String)

    Required. The name of the session to delete.

  • options (Google::Gax::CallOptions)

    Overrides the default settings for this call, e.g, timeout, retries, etc.

Yields:

  • (result, operation)

    Access the result along with the RPC operation

Yield Parameters:

  • result

    []

  • operation (GRPC::ActiveCall::Operation)

Raises:

  • (Google::Gax::GaxError)

    if the RPC is aborted.



455
456
457
458
459
460
461
462
463
464
465
# File 'lib/google/cloud/spanner/v1/spanner_client.rb', line 455

def delete_session \
    name,
    options: nil,
    &block
  req = {
    name: name
  }.delete_if { |_, v| v.nil? }
  req = Google::Gax::to_proto(req, Google::Spanner::V1::DeleteSessionRequest)
  @delete_session.call(req, options, &block)
  nil
end

#execute_sql(session, sql, transaction: nil, params: nil, param_types: nil, resume_token: nil, query_mode: nil, partition_token: nil, options: nil) {|result, operation| ... } ⇒ Google::Spanner::V1::ResultSet

Executes an SQL query, returning all rows in a single reply. This method cannot be used to return a result set larger than 10 MiB; if the query yields more data than that, the query fails with a +FAILED_PRECONDITION+ error.

Queries inside read-write transactions might return +ABORTED+. If this occurs, the application should restart the transaction from the beginning. See Transaction for more details.

Larger result sets can be fetched in streaming fashion by calling ExecuteStreamingSql instead.

Examples:

require "google/cloud/spanner"

spanner_client = Google::Cloud::Spanner.new(version: :v1)
formatted_session = Google::Cloud::Spanner::V1::SpannerClient.session_path("[PROJECT]", "[INSTANCE]", "[DATABASE]", "[SESSION]")

# TODO: Initialize +sql+:
sql = ''
response = spanner_client.execute_sql(formatted_session, sql)

Parameters:

  • session (String)

    Required. The session in which the SQL query should be performed.

  • sql (String)

    Required. The SQL query string.

  • transaction (Google::Spanner::V1::TransactionSelector | Hash)

    The transaction to use. If none is provided, the default is a temporary read-only transaction with strong concurrency. A hash of the same form as Google::Spanner::V1::TransactionSelector can also be provided.

  • params (Google::Protobuf::Struct | Hash)

    The SQL query string can contain parameter placeholders. A parameter placeholder consists of +'@'+ followed by the parameter name. Parameter names consist of any combination of letters, numbers, and underscores.

    Parameters can appear anywhere that a literal value is expected. The same parameter name can be used more than once, for example: +"WHERE id > @msg_id AND id < @msg_id + 100"+

    It is an error to execute an SQL query with unbound parameters.

    Parameter values are specified using +params+, which is a JSON object whose keys are parameter names, and whose values are the corresponding parameter values. A hash of the same form as Google::Protobuf::Struct can also be provided.

  • param_types (Hash{String => Google::Spanner::V1::Type | Hash})

    It is not always possible for Cloud Spanner to infer the right SQL type from a JSON value. For example, values of type +BYTES+ and values of type +STRING+ both appear in params as JSON strings.

    In these cases, +param_types+ can be used to specify the exact SQL type for some or all of the SQL query parameters. See the definition of Type for more information about SQL types. A hash of the same form as Google::Spanner::V1::Type can also be provided.

  • resume_token (String)

    If this request is resuming a previously interrupted SQL query execution, +resume_token+ should be copied from the last PartialResultSet yielded before the interruption. Doing this enables the new SQL query execution to resume where the last one left off. The rest of the request parameters must exactly match the request that yielded this token.

  • query_mode (Google::Spanner::V1::ExecuteSqlRequest::QueryMode)

    Used to control the amount of debugging information returned in ResultSetStats. If partition_token is set, query_mode can only be set to QueryMode::NORMAL.

  • partition_token (String)

    If present, results will be restricted to the specified partition previously created using PartitionQuery(). There must be an exact match for the values of fields common to this message and the PartitionQueryRequest message used to create this partition_token.

  • options (Google::Gax::CallOptions)

    Overrides the default settings for this call, e.g, timeout, retries, etc.

Yields:

  • (result, operation)

    Access the result along with the RPC operation

Yield Parameters:

Returns:

Raises:

  • (Google::Gax::GaxError)

    if the RPC is aborted.



550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
# File 'lib/google/cloud/spanner/v1/spanner_client.rb', line 550

def execute_sql \
    session,
    sql,
    transaction: nil,
    params: nil,
    param_types: nil,
    resume_token: nil,
    query_mode: nil,
    partition_token: nil,
    options: nil,
    &block
  req = {
    session: session,
    sql: sql,
    transaction: transaction,
    params: params,
    param_types: param_types,
    resume_token: resume_token,
    query_mode: query_mode,
    partition_token: partition_token
  }.delete_if { |_, v| v.nil? }
  req = Google::Gax::to_proto(req, Google::Spanner::V1::ExecuteSqlRequest)
  @execute_sql.call(req, options, &block)
end

#execute_streaming_sql(session, sql, transaction: nil, params: nil, param_types: nil, resume_token: nil, query_mode: nil, partition_token: nil, options: nil) ⇒ Enumerable<Google::Spanner::V1::PartialResultSet>

Like ExecuteSql, except returns the result set as a stream. Unlike ExecuteSql, there is no limit on the size of the returned result set. However, no individual row in the result set can exceed 100 MiB, and no column value can exceed 10 MiB.

Examples:

require "google/cloud/spanner"

spanner_client = Google::Cloud::Spanner.new(version: :v1)
formatted_session = Google::Cloud::Spanner::V1::SpannerClient.session_path("[PROJECT]", "[INSTANCE]", "[DATABASE]", "[SESSION]")

# TODO: Initialize +sql+:
sql = ''
spanner_client.execute_streaming_sql(formatted_session, sql).each do |element|
  # Process element.
end

Parameters:

  • session (String)

    Required. The session in which the SQL query should be performed.

  • sql (String)

    Required. The SQL query string.

  • transaction (Google::Spanner::V1::TransactionSelector | Hash)

    The transaction to use. If none is provided, the default is a temporary read-only transaction with strong concurrency. A hash of the same form as Google::Spanner::V1::TransactionSelector can also be provided.

  • params (Google::Protobuf::Struct | Hash)

    The SQL query string can contain parameter placeholders. A parameter placeholder consists of +'@'+ followed by the parameter name. Parameter names consist of any combination of letters, numbers, and underscores.

    Parameters can appear anywhere that a literal value is expected. The same parameter name can be used more than once, for example: +"WHERE id > @msg_id AND id < @msg_id + 100"+

    It is an error to execute an SQL query with unbound parameters.

    Parameter values are specified using +params+, which is a JSON object whose keys are parameter names, and whose values are the corresponding parameter values. A hash of the same form as Google::Protobuf::Struct can also be provided.

  • param_types (Hash{String => Google::Spanner::V1::Type | Hash})

    It is not always possible for Cloud Spanner to infer the right SQL type from a JSON value. For example, values of type +BYTES+ and values of type +STRING+ both appear in params as JSON strings.

    In these cases, +param_types+ can be used to specify the exact SQL type for some or all of the SQL query parameters. See the definition of Type for more information about SQL types. A hash of the same form as Google::Spanner::V1::Type can also be provided.

  • resume_token (String)

    If this request is resuming a previously interrupted SQL query execution, +resume_token+ should be copied from the last PartialResultSet yielded before the interruption. Doing this enables the new SQL query execution to resume where the last one left off. The rest of the request parameters must exactly match the request that yielded this token.

  • query_mode (Google::Spanner::V1::ExecuteSqlRequest::QueryMode)

    Used to control the amount of debugging information returned in ResultSetStats. If partition_token is set, query_mode can only be set to QueryMode::NORMAL.

  • partition_token (String)

    If present, results will be restricted to the specified partition previously created using PartitionQuery(). There must be an exact match for the values of fields common to this message and the PartitionQueryRequest message used to create this partition_token.

  • options (Google::Gax::CallOptions)

    Overrides the default settings for this call, e.g, timeout, retries, etc.

Returns:

Raises:

  • (Google::Gax::GaxError)

    if the RPC is aborted.



653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
# File 'lib/google/cloud/spanner/v1/spanner_client.rb', line 653

def execute_streaming_sql \
    session,
    sql,
    transaction: nil,
    params: nil,
    param_types: nil,
    resume_token: nil,
    query_mode: nil,
    partition_token: nil,
    options: nil
  req = {
    session: session,
    sql: sql,
    transaction: transaction,
    params: params,
    param_types: param_types,
    resume_token: resume_token,
    query_mode: query_mode,
    partition_token: partition_token
  }.delete_if { |_, v| v.nil? }
  req = Google::Gax::to_proto(req, Google::Spanner::V1::ExecuteSqlRequest)
  @execute_streaming_sql.call(req, options)
end

#get_session(name, options: nil) {|result, operation| ... } ⇒ Google::Spanner::V1::Session

Gets a session. Returns +NOT_FOUND+ if the session does not exist. This is mainly useful for determining whether a session is still alive.

Examples:

require "google/cloud/spanner"

spanner_client = Google::Cloud::Spanner.new(version: :v1)
formatted_name = Google::Cloud::Spanner::V1::SpannerClient.session_path("[PROJECT]", "[INSTANCE]", "[DATABASE]", "[SESSION]")
response = spanner_client.get_session(formatted_name)

Parameters:

  • name (String)

    Required. The name of the session to retrieve.

  • options (Google::Gax::CallOptions)

    Overrides the default settings for this call, e.g, timeout, retries, etc.

Yields:

  • (result, operation)

    Access the result along with the RPC operation

Yield Parameters:

Returns:

Raises:

  • (Google::Gax::GaxError)

    if the RPC is aborted.



359
360
361
362
363
364
365
366
367
368
# File 'lib/google/cloud/spanner/v1/spanner_client.rb', line 359

def get_session \
    name,
    options: nil,
    &block
  req = {
    name: name
  }.delete_if { |_, v| v.nil? }
  req = Google::Gax::to_proto(req, Google::Spanner::V1::GetSessionRequest)
  @get_session.call(req, options, &block)
end

#list_sessions(database, page_size: nil, filter: nil, options: nil) {|result, operation| ... } ⇒ Google::Gax::PagedEnumerable<Google::Spanner::V1::Session>

Lists all sessions in a given database.

Examples:

require "google/cloud/spanner"

spanner_client = Google::Cloud::Spanner.new(version: :v1)
formatted_database = Google::Cloud::Spanner::V1::SpannerClient.database_path("[PROJECT]", "[INSTANCE]", "[DATABASE]")

# Iterate over all results.
spanner_client.list_sessions(formatted_database).each do |element|
  # Process element.
end

# Or iterate over results one page at a time.
spanner_client.list_sessions(formatted_database).each_page do |page|
  # Process each page at a time.
  page.each do |element|
    # Process element.
  end
end

Parameters:

  • database (String)

    Required. The database in which to list sessions.

  • page_size (Integer)

    The maximum number of resources contained in the underlying API response. If page streaming is performed per-resource, this parameter does not affect the return value. If page streaming is performed per-page, this determines the maximum number of resources in a page.

  • filter (String)

    An expression for filtering the results of the request. Filter rules are case insensitive. The fields eligible for filtering are:

    • +labels.key+ where key is the name of a label

    Some examples of using filters are:

    • +labels.env:*+ --> The session has the label "env".
      • +labels.env:dev+ --> The session has the label "env" and the value of the label contains the string "dev".
  • options (Google::Gax::CallOptions)

    Overrides the default settings for this call, e.g, timeout, retries, etc.

Yields:

  • (result, operation)

    Access the result along with the RPC operation

Yield Parameters:

Returns:

  • (Google::Gax::PagedEnumerable<Google::Spanner::V1::Session>)

    An enumerable of Google::Spanner::V1::Session instances. See Google::Gax::PagedEnumerable documentation for other operations such as per-page iteration or access to the response object.

Raises:

  • (Google::Gax::GaxError)

    if the RPC is aborted.



422
423
424
425
426
427
428
429
430
431
432
433
434
435
# File 'lib/google/cloud/spanner/v1/spanner_client.rb', line 422

def list_sessions \
    database,
    page_size: nil,
    filter: nil,
    options: nil,
    &block
  req = {
    database: database,
    page_size: page_size,
    filter: filter
  }.delete_if { |_, v| v.nil? }
  req = Google::Gax::to_proto(req, Google::Spanner::V1::ListSessionsRequest)
  @list_sessions.call(req, options, &block)
end

#partition_query(session, sql, transaction: nil, params: nil, param_types: nil, partition_options: nil, options: nil) {|result, operation| ... } ⇒ Google::Spanner::V1::PartitionResponse

Creates a set of partition tokens that can be used to execute a query operation in parallel. Each of the returned partition tokens can be used by ExecuteStreamingSql to specify a subset of the query result to read. The same session and read-only transaction must be used by the PartitionQueryRequest used to create the partition tokens and the ExecuteSqlRequests that use the partition tokens. Partition tokens become invalid when the session used to create them is deleted or begins a new transaction.

Examples:

require "google/cloud/spanner"

spanner_client = Google::Cloud::Spanner.new(version: :v1)
formatted_session = Google::Cloud::Spanner::V1::SpannerClient.session_path("[PROJECT]", "[INSTANCE]", "[DATABASE]", "[SESSION]")

# TODO: Initialize +sql+:
sql = ''
response = spanner_client.partition_query(formatted_session, sql)

Parameters:

  • session (String)

    Required. The session used to create the partitions.

  • sql (String)

    The query request to generate partitions for. The request will fail if the query is not root partitionable. The query plan of a root partitionable query has a single distributed union operator. A distributed union operator conceptually divides one or more tables into multiple splits, remotely evaluates a subquery independently on each split, and then unions all results.

  • transaction (Google::Spanner::V1::TransactionSelector | Hash)

    Read only snapshot transactions are supported, read/write and single use transactions are not. A hash of the same form as Google::Spanner::V1::TransactionSelector can also be provided.

  • params (Google::Protobuf::Struct | Hash)

    The SQL query string can contain parameter placeholders. A parameter placeholder consists of +'@'+ followed by the parameter name. Parameter names consist of any combination of letters, numbers, and underscores.

    Parameters can appear anywhere that a literal value is expected. The same parameter name can be used more than once, for example: +"WHERE id > @msg_id AND id < @msg_id + 100"+

    It is an error to execute an SQL query with unbound parameters.

    Parameter values are specified using +params+, which is a JSON object whose keys are parameter names, and whose values are the corresponding parameter values. A hash of the same form as Google::Protobuf::Struct can also be provided.

  • param_types (Hash{String => Google::Spanner::V1::Type | Hash})

    It is not always possible for Cloud Spanner to infer the right SQL type from a JSON value. For example, values of type +BYTES+ and values of type +STRING+ both appear in params as JSON strings.

    In these cases, +param_types+ can be used to specify the exact SQL type for some or all of the SQL query parameters. See the definition of Type for more information about SQL types. A hash of the same form as Google::Spanner::V1::Type can also be provided.

  • partition_options (Google::Spanner::V1::PartitionOptions | Hash)

    Additional options that affect how many partitions are created. A hash of the same form as Google::Spanner::V1::PartitionOptions can also be provided.

  • options (Google::Gax::CallOptions)

    Overrides the default settings for this call, e.g, timeout, retries, etc.

Yields:

  • (result, operation)

    Access the result along with the RPC operation

Yield Parameters:

Returns:

Raises:

  • (Google::Gax::GaxError)

    if the RPC is aborted.



1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
# File 'lib/google/cloud/spanner/v1/spanner_client.rb', line 1118

def partition_query \
    session,
    sql,
    transaction: nil,
    params: nil,
    param_types: nil,
    partition_options: nil,
    options: nil,
    &block
  req = {
    session: session,
    sql: sql,
    transaction: transaction,
    params: params,
    param_types: param_types,
    partition_options: partition_options
  }.delete_if { |_, v| v.nil? }
  req = Google::Gax::to_proto(req, Google::Spanner::V1::PartitionQueryRequest)
  @partition_query.call(req, options, &block)
end

#partition_read(session, table, key_set, transaction: nil, index: nil, columns: nil, partition_options: nil, options: nil) {|result, operation| ... } ⇒ Google::Spanner::V1::PartitionResponse

Creates a set of partition tokens that can be used to execute a read operation in parallel. Each of the returned partition tokens can be used by StreamingRead to specify a subset of the read result to read. The same session and read-only transaction must be used by the PartitionReadRequest used to create the partition tokens and the ReadRequests that use the partition tokens. Partition tokens become invalid when the session used to create them is deleted or begins a new transaction.

Examples:

require "google/cloud/spanner"

spanner_client = Google::Cloud::Spanner.new(version: :v1)
formatted_session = Google::Cloud::Spanner::V1::SpannerClient.session_path("[PROJECT]", "[INSTANCE]", "[DATABASE]", "[SESSION]")

# TODO: Initialize +table+:
table = ''

# TODO: Initialize +key_set+:
key_set = {}
response = spanner_client.partition_read(formatted_session, table, key_set)

Parameters:

  • session (String)

    Required. The session used to create the partitions.

  • table (String)

    Required. The name of the table in the database to be read.

  • key_set (Google::Spanner::V1::KeySet | Hash)

    Required. +key_set+ identifies the rows to be yielded. +key_set+ names the primary keys of the rows in table to be yielded, unless index is present. If index is present, then key_set instead names index keys in index.

    It is not an error for the +key_set+ to name rows that do not exist in the database. Read yields nothing for nonexistent rows. A hash of the same form as Google::Spanner::V1::KeySet can also be provided.

  • transaction (Google::Spanner::V1::TransactionSelector | Hash)

    Read only snapshot transactions are supported, read/write and single use transactions are not. A hash of the same form as Google::Spanner::V1::TransactionSelector can also be provided.

  • index (String)

    If non-empty, the name of an index on table. This index is used instead of the table primary key when interpreting key_set and sorting result rows. See key_set for further information.

  • columns (Array<String>)

    The columns of table to be returned for each row matching this request.

  • partition_options (Google::Spanner::V1::PartitionOptions | Hash)

    Additional options that affect how many partitions are created. A hash of the same form as Google::Spanner::V1::PartitionOptions can also be provided.

  • options (Google::Gax::CallOptions)

    Overrides the default settings for this call, e.g, timeout, retries, etc.

Yields:

  • (result, operation)

    Access the result along with the RPC operation

Yield Parameters:

Returns:

Raises:

  • (Google::Gax::GaxError)

    if the RPC is aborted.



1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
# File 'lib/google/cloud/spanner/v1/spanner_client.rb', line 1199

def partition_read \
    session,
    table,
    key_set,
    transaction: nil,
    index: nil,
    columns: nil,
    partition_options: nil,
    options: nil,
    &block
  req = {
    session: session,
    table: table,
    key_set: key_set,
    transaction: transaction,
    index: index,
    columns: columns,
    partition_options: partition_options
  }.delete_if { |_, v| v.nil? }
  req = Google::Gax::to_proto(req, Google::Spanner::V1::PartitionReadRequest)
  @partition_read.call(req, options, &block)
end

#read(session, table, columns, key_set, transaction: nil, index: nil, limit: nil, resume_token: nil, partition_token: nil, options: nil) {|result, operation| ... } ⇒ Google::Spanner::V1::ResultSet

Reads rows from the database using key lookups and scans, as a simple key/value style alternative to ExecuteSql. This method cannot be used to return a result set larger than 10 MiB; if the read matches more data than that, the read fails with a +FAILED_PRECONDITION+ error.

Reads inside read-write transactions might return +ABORTED+. If this occurs, the application should restart the transaction from the beginning. See Transaction for more details.

Larger result sets can be yielded in streaming fashion by calling StreamingRead instead.

Examples:

require "google/cloud/spanner"

spanner_client = Google::Cloud::Spanner.new(version: :v1)
formatted_session = Google::Cloud::Spanner::V1::SpannerClient.session_path("[PROJECT]", "[INSTANCE]", "[DATABASE]", "[SESSION]")

# TODO: Initialize +table+:
table = ''

# TODO: Initialize +columns+:
columns = []

# TODO: Initialize +key_set+:
key_set = {}
response = spanner_client.read(formatted_session, table, columns, key_set)

Parameters:

  • session (String)

    Required. The session in which the read should be performed.

  • table (String)

    Required. The name of the table in the database to be read.

  • columns (Array<String>)

    The columns of table to be returned for each row matching this request.

  • key_set (Google::Spanner::V1::KeySet | Hash)

    Required. +key_set+ identifies the rows to be yielded. +key_set+ names the primary keys of the rows in table to be yielded, unless index is present. If index is present, then key_set instead names index keys in index.

    If the partition_token field is empty, rows are yielded in table primary key order (if index is empty) or index key order (if index is non-empty). If the partition_token field is not empty, rows will be yielded in an unspecified order.

    It is not an error for the +key_set+ to name rows that do not exist in the database. Read yields nothing for nonexistent rows. A hash of the same form as Google::Spanner::V1::KeySet can also be provided.

  • transaction (Google::Spanner::V1::TransactionSelector | Hash)

    The transaction to use. If none is provided, the default is a temporary read-only transaction with strong concurrency. A hash of the same form as Google::Spanner::V1::TransactionSelector can also be provided.

  • index (String)

    If non-empty, the name of an index on table. This index is used instead of the table primary key when interpreting key_set and sorting result rows. See key_set for further information.

  • limit (Integer)

    If greater than zero, only the first +limit+ rows are yielded. If +limit+ is zero, the default is no limit. A limit cannot be specified if +partition_token+ is set.

  • resume_token (String)

    If this request is resuming a previously interrupted read, +resume_token+ should be copied from the last PartialResultSet yielded before the interruption. Doing this enables the new read to resume where the last read left off. The rest of the request parameters must exactly match the request that yielded this token.

  • partition_token (String)

    If present, results will be restricted to the specified partition previously created using PartitionRead(). There must be an exact match for the values of fields common to this message and the PartitionReadRequest message used to create this partition_token.

  • options (Google::Gax::CallOptions)

    Overrides the default settings for this call, e.g, timeout, retries, etc.

Yields:

  • (result, operation)

    Access the result along with the RPC operation

Yield Parameters:

Returns:

Raises:

  • (Google::Gax::GaxError)

    if the RPC is aborted.



762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
# File 'lib/google/cloud/spanner/v1/spanner_client.rb', line 762

def read \
    session,
    table,
    columns,
    key_set,
    transaction: nil,
    index: nil,
    limit: nil,
    resume_token: nil,
    partition_token: nil,
    options: nil,
    &block
  req = {
    session: session,
    table: table,
    columns: columns,
    key_set: key_set,
    transaction: transaction,
    index: index,
    limit: limit,
    resume_token: resume_token,
    partition_token: partition_token
  }.delete_if { |_, v| v.nil? }
  req = Google::Gax::to_proto(req, Google::Spanner::V1::ReadRequest)
  @read.call(req, options, &block)
end

#rollback(session, transaction_id, options: nil) {|result, operation| ... } ⇒ Object

Rolls back a transaction, releasing any locks it holds. It is a good idea to call this for any transaction that includes one or more Read or ExecuteSql requests and ultimately decides not to commit.

+Rollback+ returns +OK+ if it successfully aborts the transaction, the transaction was already aborted, or the transaction is not found. +Rollback+ never returns +ABORTED+.

Examples:

require "google/cloud/spanner"

spanner_client = Google::Cloud::Spanner.new(version: :v1)
formatted_session = Google::Cloud::Spanner::V1::SpannerClient.session_path("[PROJECT]", "[INSTANCE]", "[DATABASE]", "[SESSION]")

# TODO: Initialize +transaction_id+:
transaction_id = ''
spanner_client.rollback(formatted_session, transaction_id)

Parameters:

  • session (String)

    Required. The session in which the transaction to roll back is running.

  • transaction_id (String)

    Required. The transaction to roll back.

  • options (Google::Gax::CallOptions)

    Overrides the default settings for this call, e.g, timeout, retries, etc.

Yields:

  • (result, operation)

    Access the result along with the RPC operation

Yield Parameters:

  • result

    []

  • operation (GRPC::ActiveCall::Operation)

Raises:

  • (Google::Gax::GaxError)

    if the RPC is aborted.



1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
# File 'lib/google/cloud/spanner/v1/spanner_client.rb', line 1031

def rollback \
    session,
    transaction_id,
    options: nil,
    &block
  req = {
    session: session,
    transaction_id: transaction_id
  }.delete_if { |_, v| v.nil? }
  req = Google::Gax::to_proto(req, Google::Spanner::V1::RollbackRequest)
  @rollback.call(req, options, &block)
  nil
end

#streaming_read(session, table, columns, key_set, transaction: nil, index: nil, limit: nil, resume_token: nil, partition_token: nil, options: nil) ⇒ Enumerable<Google::Spanner::V1::PartialResultSet>

Like Read, except returns the result set as a stream. Unlike Read, there is no limit on the size of the returned result set. However, no individual row in the result set can exceed 100 MiB, and no column value can exceed 10 MiB.

Examples:

require "google/cloud/spanner"

spanner_client = Google::Cloud::Spanner.new(version: :v1)
formatted_session = Google::Cloud::Spanner::V1::SpannerClient.session_path("[PROJECT]", "[INSTANCE]", "[DATABASE]", "[SESSION]")

# TODO: Initialize +table+:
table = ''

# TODO: Initialize +columns+:
columns = []

# TODO: Initialize +key_set+:
key_set = {}
spanner_client.streaming_read(formatted_session, table, columns, key_set).each do |element|
  # Process element.
end

Parameters:

  • session (String)

    Required. The session in which the read should be performed.

  • table (String)

    Required. The name of the table in the database to be read.

  • columns (Array<String>)

    The columns of table to be returned for each row matching this request.

  • key_set (Google::Spanner::V1::KeySet | Hash)

    Required. +key_set+ identifies the rows to be yielded. +key_set+ names the primary keys of the rows in table to be yielded, unless index is present. If index is present, then key_set instead names index keys in index.

    If the partition_token field is empty, rows are yielded in table primary key order (if index is empty) or index key order (if index is non-empty). If the partition_token field is not empty, rows will be yielded in an unspecified order.

    It is not an error for the +key_set+ to name rows that do not exist in the database. Read yields nothing for nonexistent rows. A hash of the same form as Google::Spanner::V1::KeySet can also be provided.

  • transaction (Google::Spanner::V1::TransactionSelector | Hash)

    The transaction to use. If none is provided, the default is a temporary read-only transaction with strong concurrency. A hash of the same form as Google::Spanner::V1::TransactionSelector can also be provided.

  • index (String)

    If non-empty, the name of an index on table. This index is used instead of the table primary key when interpreting key_set and sorting result rows. See key_set for further information.

  • limit (Integer)

    If greater than zero, only the first +limit+ rows are yielded. If +limit+ is zero, the default is no limit. A limit cannot be specified if +partition_token+ is set.

  • resume_token (String)

    If this request is resuming a previously interrupted read, +resume_token+ should be copied from the last PartialResultSet yielded before the interruption. Doing this enables the new read to resume where the last read left off. The rest of the request parameters must exactly match the request that yielded this token.

  • partition_token (String)

    If present, results will be restricted to the specified partition previously created using PartitionRead(). There must be an exact match for the values of fields common to this message and the PartitionReadRequest message used to create this partition_token.

  • options (Google::Gax::CallOptions)

    Overrides the default settings for this call, e.g, timeout, retries, etc.

Returns:

Raises:

  • (Google::Gax::GaxError)

    if the RPC is aborted.



867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
# File 'lib/google/cloud/spanner/v1/spanner_client.rb', line 867

def streaming_read \
    session,
    table,
    columns,
    key_set,
    transaction: nil,
    index: nil,
    limit: nil,
    resume_token: nil,
    partition_token: nil,
    options: nil
  req = {
    session: session,
    table: table,
    columns: columns,
    key_set: key_set,
    transaction: transaction,
    index: index,
    limit: limit,
    resume_token: resume_token,
    partition_token: partition_token
  }.delete_if { |_, v| v.nil? }
  req = Google::Gax::to_proto(req, Google::Spanner::V1::ReadRequest)
  @streaming_read.call(req, options)
end