21
21
"""
22
22
23
23
import argparse
24
- import base64
25
- import datetime
26
- import decimal
27
- import json
28
- import logging
29
- import time
30
24
31
25
from google .cloud import spanner
32
- from google .cloud .spanner_admin_instance_v1 .types import spanner_instance_admin
33
- from google .cloud .spanner_v1 import DirectedReadOptions , param_types
34
- from google .cloud .spanner_v1 .data_types import JsonObject
35
- from google .protobuf import field_mask_pb2 # type: ignore
36
- from testdata import singer_pb2
37
26
38
27
OPERATION_TIMEOUT_SECONDS = 240
39
28
@@ -54,7 +43,6 @@ def create_database_with_property_graph(instance_id, database_id):
54
43
"""CREATE TABLE Person (
55
44
id INT64 NOT NULL,
56
45
name STRING(MAX),
57
- gender STRING(40),
58
46
birthday TIMESTAMP,
59
47
country STRING(MAX),
60
48
city STRING(MAX),
@@ -167,11 +155,11 @@ def insert_data(instance_id, database_id):
167
155
168
156
batch .insert (
169
157
table = "Person" ,
170
- columns = ("id" , "name" , "gender" , " birthday" , "country" , "city" ),
158
+ columns = ("id" , "name" , "birthday" , "country" , "city" ),
171
159
values = [
172
- (1 , "Alex" , "male" , '1991-12-21T00:00:00.12Z' , "Australia" ," Adelaide" ),
173
- (2 , "Dana" , "female" , '1980-10-31T00:00:00.12Z' ,"Czech_Republic" , "Moravia" ),
174
- (3 , "Lee" , "male" , '1986-12-07T00:00:00.12Z' , "India" , "Kollam" )
160
+ (1 , "Alex" , '1991-12-21T00:00:00.12Z' , "Australia" ," Adelaide" ),
161
+ (2 , "Dana" , '1980-10-31T00:00:00.12Z' ,"Czech_Republic" , "Moravia" ),
162
+ (3 , "Lee" , '1986-12-07T00:00:00.12Z' , "India" , "Kollam" )
175
163
],
176
164
)
177
165
@@ -206,7 +194,7 @@ def insert_data(instance_id, database_id):
206
194
# [START spanner_insert_graph_data_with_dml]
207
195
def insert_data_with_dml (instance_id , database_id ):
208
196
"""Inserts sample data into the given database using a DML statement."""
209
-
197
+
210
198
# instance_id = "your-spanner-instance"
211
199
# database_id = "your-spanner-db-id"
212
200
@@ -234,7 +222,6 @@ def insert_transfers(transaction):
234
222
235
223
print ("{} record(s) inserted into AccountTransferAccount." .format (row_ct ))
236
224
237
-
238
225
database .run_in_transaction (insert_accounts )
239
226
database .run_in_transaction (insert_transfers )
240
227
@@ -324,7 +311,7 @@ def query_data(instance_id, database_id):
324
311
# [START spanner_with_graph_query_data_with_parameter]
325
312
def query_data_with_parameter (instance_id , database_id ):
326
313
"""Queries sample data from the database using SQL with a parameter."""
327
-
314
+
328
315
# instance_id = "your-spanner-instance"
329
316
# database_id = "your-spanner-db-id"
330
317
spanner_client = spanner .Client ()
@@ -351,7 +338,7 @@ def query_data_with_parameter(instance_id, database_id):
351
338
# [START spanner_delete_graph_data_with_dml]
352
339
def delete_data_with_dml (instance_id , database_id ):
353
340
"""Deletes sample data from the database using a DML statement."""
354
-
341
+
355
342
# instance_id = "your-spanner-instance"
356
343
# database_id = "your-spanner-db-id"
357
344
@@ -430,12 +417,12 @@ def delete_data(instance_id, database_id):
430
417
"create_database_with_property_graph" ,
431
418
help = create_database_with_property_graph .__doc__ )
432
419
subparsers .add_parser ("update_allow_commit_timestamps" ,
433
- help = update_allow_commit_timestamps .__doc__ )
420
+ help = update_allow_commit_timestamps .__doc__ )
434
421
subparsers .add_parser ("insert_data" , help = insert_data .__doc__ )
435
422
subparsers .add_parser ("insert_data_with_dml" , help = insert_data_with_dml .__doc__ )
436
423
subparsers .add_parser ("update_data_with_dml" , help = update_data_with_dml .__doc__ )
437
424
subparsers .add_parser ("update_data_with_graph_query_in_dml" ,
438
- help = update_data_with_graph_query_in_dml .__doc__ )
425
+ help = update_data_with_graph_query_in_dml .__doc__ )
439
426
subparsers .add_parser ("query_data" , help = query_data .__doc__ )
440
427
subparsers .add_parser (
441
428
"query_data_with_parameter" , help = query_data_with_parameter .__doc__
@@ -465,4 +452,3 @@ def delete_data(instance_id, database_id):
465
452
delete_data_with_dml (args .instance_id , args .database_id )
466
453
elif args .command == "delete_data" :
467
454
delete_data (args .instance_id , args .database_id )
468
-
0 commit comments