@@ -81,3 +81,71 @@ def test_get_query_stats():
8181 assert isinstance (result , pandas .Series )
8282 pandas .testing .assert_index_equal (expected_index , result .index )
8383 assert result ["totalBytesProcessed" ] == total_bytes_processed
84+
85+
86+ def test_get_query_stats_missing_bytes_use_zero ():
87+ mock_query_job = mock .create_autospec (bigquery .QueryJob )
88+ mock_query_job ._properties = {
89+ "kind" : "bigquery#job" ,
90+ "etag" : "e-tag" ,
91+ "id" : "id" ,
92+ "selfLink" : "self-link" ,
93+ "user_email" : "user-emial" ,
94+ "configuration" : {
95+ "query" : {
96+ "query" : "SELECT * FROM `test_table`" ,
97+ "destinationTable" : {
98+ "projectId" : "project-id" ,
99+ "datasetId" : "dataset-id" ,
100+ "tableId" : "table-id" ,
101+ },
102+ "writeDisposition" : "WRITE_TRUNCATE" ,
103+ "priority" : "INTERACTIVE" ,
104+ "useLegacySql" : False ,
105+ },
106+ "jobType" : "QUERY" ,
107+ },
108+ "jobReference" : {
109+ "projectId" : "project-id" ,
110+ "jobId" : "job-id" ,
111+ "location" : "US" ,
112+ },
113+ "statistics" : {
114+ "creationTime" : 1767037135155.0 ,
115+ "startTime" : 1767037135238.0 ,
116+ "endTime" : 1767037135353.0 ,
117+ "query" : {
118+ "cacheHit" : True ,
119+ "statementType" : "SELECT" ,
120+ },
121+ "reservation_id" : "reservation_id" ,
122+ "edition" : "ENTERPRISE" ,
123+ "reservationGroupPath" : ["" ],
124+ },
125+ "status" : {"state" : "DONE" },
126+ "principal_subject" : "principal_subject" ,
127+ "jobCreationReason" : {"code" : "REQUESTED" },
128+ }
129+ expected_index = pandas .Index (
130+ [
131+ "bigquerySchema" ,
132+ "projectId" ,
133+ "jobId" ,
134+ "location" ,
135+ "jobType" ,
136+ "dispatchedSql" ,
137+ "destinationTable" ,
138+ "useLegacySql" ,
139+ "referencedTables" ,
140+ "totalBytesProcessed" ,
141+ "cacheHit" ,
142+ "statementType" ,
143+ "creationTime" ,
144+ ]
145+ )
146+
147+ result = dry_runs .get_query_stats (mock_query_job )
148+
149+ assert isinstance (result , pandas .Series )
150+ pandas .testing .assert_index_equal (expected_index , result .index )
151+ assert result ["totalBytesProcessed" ] == 0
0 commit comments