@@ -403,13 +403,15 @@ def insert_data(instance_id, database_id):
403403# [END spanner_insert_data]
404404
405405
406- # [START spanner_batch_write ]
406+ # [START spanner_batch_write_at_least_once ]
407407def batch_write (instance_id , database_id ):
408408 """Inserts sample data into the given database via BatchWrite API.
409409
410410 The database and table must already exist and can be created using
411411 `create_database`.
412412 """
413+ from google .rpc .code_pb2 import OK
414+
413415 spanner_client = spanner .Client ()
414416 instance = spanner_client .instance (instance_id )
415417 database = instance .database (database_id )
@@ -429,7 +431,7 @@ def batch_write(instance_id, database_id):
429431 table = "Singers" ,
430432 columns = ("SingerId" , "FirstName" , "LastName" ),
431433 values = [
432- (17 , "Marc" , "Richards " ),
434+ (17 , "Marc" , "" ),
433435 (18 , "Catalina" , "Smith" ),
434436 ],
435437 )
@@ -443,12 +445,21 @@ def batch_write(instance_id, database_id):
443445 )
444446
445447 for response in groups .batch_write ():
446- print (response )
447-
448- print ("Inserted data." )
448+ if response .status .code == OK :
449+ print (
450+ "Mutation group indexes {} have been applied with commit timestamp {}" .format (
451+ response .indexes , response .commit_timestamp
452+ )
453+ )
454+ else :
455+ print (
456+ "Mutation group indexes {} could not be applied with error {}" .format (
457+ response .indexes , response .status
458+ )
459+ )
449460
450461
451- # [END spanner_batch_write ]
462+ # [END spanner_batch_write_at_least_once ]
452463
453464
454465# [START spanner_delete_data]
0 commit comments