File tree Expand file tree Collapse file tree 2 files changed +56
-2
lines changed Expand file tree Collapse file tree 2 files changed +56
-2
lines changed Original file line number Diff line number Diff line change
1
+ import base64
2
+ import time
3
+ from google .cloud import spanner
4
+ from google .auth .credentials import AnonymousCredentials
5
+
6
+ instance_id = 'test-instance'
7
+ database_id = 'test-db'
8
+
9
+ spanner_client = spanner .Client (
10
+ project = 'test-project' ,
11
+ client_options = {"api_endpoint" : 'localhost:9010' },
12
+ credentials = AnonymousCredentials ()
13
+ )
14
+
15
+ instance = spanner_client .instance (instance_id )
16
+ op = instance .create ()
17
+ op .result ()
18
+
19
+ database = instance .database (database_id , ddl_statements = [
20
+ "CREATE TABLE Test (id STRING(36) NOT NULL, megafield BYTES(MAX)) PRIMARY KEY (id)"
21
+ ])
22
+ op = database .create ()
23
+ op .result ()
24
+
25
+ # This must be large enough that the SDK will split the megafield payload across two query chunks
26
+ # and try to recombine them, causing the error:
27
+ data = base64 .standard_b64encode (("a" * 1000000 ).encode ("utf8" ))
28
+
29
+ try :
30
+ with database .batch () as batch :
31
+ batch .insert (
32
+ table = "Test" ,
33
+ columns = ("id" , "megafield" ),
34
+ values = [
35
+ (1 , data ),
36
+ ],
37
+ )
38
+
39
+ with database .snapshot () as snapshot :
40
+ toc = time .time ()
41
+ results = snapshot .execute_sql (
42
+ "SELECT * FROM Test"
43
+ )
44
+ tic = time .time ()
45
+
46
+ print ("TIME: " , tic - toc )
47
+
48
+ for row in results :
49
+ print ("Id: " , row [0 ])
50
+ print ("Megafield: " , row [1 ][:100 ])
51
+ finally :
52
+ database .drop ()
53
+ instance .delete ()
Original file line number Diff line number Diff line change @@ -725,11 +725,12 @@ def test_backup_workflow(self):
725
725
operation = database .restore (source = backup )
726
726
restored_db = operation .result ()
727
727
self .assertEqual (
728
- self .database_version_time , restored_db .restore_info .backup_info .create_time
728
+ self .database_version_time ,
729
+ restored_db .restore_info .backup_info .version_time ,
729
730
)
730
731
731
732
metadata = operation .metadata
732
- self .assertEqual (self .database_version_time , metadata .backup_info .create_time )
733
+ self .assertEqual (self .database_version_time , metadata .backup_info .version_time )
733
734
734
735
database .drop ()
735
736
backup .delete ()
You can’t perform that action at this time.
0 commit comments