@@ -1392,6 +1392,49 @@ def query_data_with_timestamp_parameter(instance_id, database_id):
1392
1392
# [END spanner_query_with_timestamp_parameter]
1393
1393
1394
1394
1395
+ def query_data_with_query_options (instance_id , database_id ):
1396
+ """Queries sample data using SQL with query options."""
1397
+ # [START spanner_query_with_query_options]
1398
+ # instance_id = "your-spanner-instance"
1399
+ # database_id = "your-spanner-db-id"
1400
+ spanner_client = spanner .Client ()
1401
+ instance = spanner_client .instance (instance_id )
1402
+ database = instance .database (database_id )
1403
+
1404
+ with database .snapshot () as snapshot :
1405
+ results = snapshot .execute_sql (
1406
+ 'SELECT VenueId, VenueName, LastUpdateTime FROM Venues' ,
1407
+ query_options = {'optimizer_version' : '1' }
1408
+ )
1409
+
1410
+ for row in results :
1411
+ print (u"VenueId: {}, VenueName: {}, LastUpdateTime: {}" .format (
1412
+ * row ))
1413
+ # [END spanner_query_with_query_options]
1414
+
1415
+
1416
+ def create_client_with_query_options (instance_id , database_id ):
1417
+ """Create a client with query options."""
1418
+ # [START spanner_create_client_with_query_options]
1419
+ # instance_id = "your-spanner-instance"
1420
+ # database_id = "your-spanner-db-id"
1421
+ spanner_client = spanner .Client (
1422
+ query_options = {'optimizer_version' : '1' }
1423
+ )
1424
+ instance = spanner_client .instance (instance_id )
1425
+ database = instance .database (database_id )
1426
+
1427
+ with database .snapshot () as snapshot :
1428
+ results = snapshot .execute_sql (
1429
+ 'SELECT VenueId, VenueName, LastUpdateTime FROM Venues'
1430
+ )
1431
+
1432
+ for row in results :
1433
+ print (u"VenueId: {}, VenueName: {}, LastUpdateTime: {}" .format (
1434
+ * row ))
1435
+ # [END spanner_create_client_with_query_options]
1436
+
1437
+
1395
1438
if __name__ == '__main__' : # noqa: C901
1396
1439
parser = argparse .ArgumentParser (
1397
1440
description = __doc__ ,
@@ -1506,6 +1549,12 @@ def query_data_with_timestamp_parameter(instance_id, database_id):
1506
1549
subparsers .add_parser (
1507
1550
'query_data_with_timestamp_parameter' ,
1508
1551
help = query_data_with_timestamp_parameter .__doc__ )
1552
+ subparsers .add_parser (
1553
+ 'query_data_with_query_options' ,
1554
+ help = query_data_with_query_options .__doc__ )
1555
+ subparsers .add_parser (
1556
+ 'create_client_with_query_options' ,
1557
+ help = create_client_with_query_options .__doc__ )
1509
1558
1510
1559
args = parser .parse_args ()
1511
1560
@@ -1607,3 +1656,7 @@ def query_data_with_timestamp_parameter(instance_id, database_id):
1607
1656
query_data_with_string (args .instance_id , args .database_id )
1608
1657
elif args .command == 'query_data_with_timestamp_parameter' :
1609
1658
query_data_with_timestamp_parameter (args .instance_id , args .database_id )
1659
+ elif args .command == 'query_data_with_query_options' :
1660
+ query_data_with_query_options (args .instance_id , args .database_id )
1661
+ elif args .command == 'create_client_with_query_options' :
1662
+ create_client_with_query_options (args .instance_id , args .database_id )
0 commit comments