@@ -40,32 +40,54 @@ def count_job_stats(
40
40
):
41
41
if query_job is None :
42
42
assert row_iterator is not None
43
- total_bytes_processed = getattr (row_iterator , "total_bytes_processed" , None )
44
- query = getattr (row_iterator , "query" , None )
45
- if total_bytes_processed is None or query is None :
46
- return
43
+
44
+ # TODO(tswast): Pass None after making benchmark publishing robust to missing data.
45
+ bytes_processed = getattr (row_iterator , "total_bytes_processed" , 0 )
46
+ query_char_count = len (getattr (row_iterator , "query" , "" ))
47
+ slot_millis = getattr (row_iterator , "slot_millis" , 0 )
48
+ exec_seconds = 0.0
47
49
48
50
self .execution_count += 1
49
- self .query_char_count += len (query )
50
- self .bytes_processed += total_bytes_processed
51
- write_stats_to_disk (len (query ), total_bytes_processed )
52
- return
51
+ self .query_char_count += query_char_count
52
+ self .bytes_processed += bytes_processed
53
+ self .slot_millis += slot_millis
54
+
55
+ elif query_job .configuration .dry_run :
56
+ query_char_count = len (query_job .query )
53
57
54
- if query_job .configuration .dry_run :
55
- write_stats_to_disk (len (query_job .query ), 0 , 0 , 0 )
58
+ # TODO(tswast): Pass None after making benchmark publishing robust to missing data.
59
+ bytes_processed = 0
60
+ slot_millis = 0
61
+ exec_seconds = 0.0
56
62
57
- stats = get_performance_stats (query_job )
58
- if stats is not None :
59
- query_char_count , bytes_processed , slot_millis , execution_secs = stats
63
+ elif (stats := get_performance_stats (query_job )) is not None :
64
+ query_char_count , bytes_processed , slot_millis , exec_seconds = stats
60
65
self .execution_count += 1
61
66
self .query_char_count += query_char_count
62
67
self .bytes_processed += bytes_processed
63
68
self .slot_millis += slot_millis
64
- self .execution_secs += execution_secs
69
+ self .execution_secs += exec_seconds
65
70
write_stats_to_disk (
66
- query_char_count , bytes_processed , slot_millis , execution_secs
71
+ query_char_count = query_char_count ,
72
+ bytes_processed = bytes_processed ,
73
+ slot_millis = slot_millis ,
74
+ exec_seconds = exec_seconds ,
67
75
)
68
76
77
+ else :
78
+ # TODO(tswast): Pass None after making benchmark publishing robust to missing data.
79
+ bytes_processed = 0
80
+ query_char_count = 0
81
+ slot_millis = 0
82
+ exec_seconds = 0
83
+
84
+ write_stats_to_disk (
85
+ query_char_count = query_char_count ,
86
+ bytes_processed = bytes_processed ,
87
+ slot_millis = slot_millis ,
88
+ exec_seconds = exec_seconds ,
89
+ )
90
+
69
91
70
92
def get_performance_stats (
71
93
query_job : bigquery .QueryJob ,
@@ -103,10 +125,11 @@ def get_performance_stats(
103
125
104
126
105
127
def write_stats_to_disk (
128
+ * ,
106
129
query_char_count : int ,
107
130
bytes_processed : int ,
108
- slot_millis : Optional [ int ] = None ,
109
- exec_seconds : Optional [ float ] = None ,
131
+ slot_millis : int ,
132
+ exec_seconds : float ,
110
133
):
111
134
"""For pytest runs only, log information about the query job
112
135
to a file in order to create a performance report.
@@ -118,18 +141,17 @@ def write_stats_to_disk(
118
141
test_name = os .environ [LOGGING_NAME_ENV_VAR ]
119
142
current_directory = os .getcwd ()
120
143
121
- if (slot_millis is not None ) and (exec_seconds is not None ):
122
- # store slot milliseconds
123
- slot_file = os .path .join (current_directory , test_name + ".slotmillis" )
124
- with open (slot_file , "a" ) as f :
125
- f .write (str (slot_millis ) + "\n " )
144
+ # store slot milliseconds
145
+ slot_file = os .path .join (current_directory , test_name + ".slotmillis" )
146
+ with open (slot_file , "a" ) as f :
147
+ f .write (str (slot_millis ) + "\n " )
126
148
127
- # store execution time seconds
128
- exec_time_file = os .path .join (
129
- current_directory , test_name + ".bq_exec_time_seconds"
130
- )
131
- with open (exec_time_file , "a" ) as f :
132
- f .write (str (exec_seconds ) + "\n " )
149
+ # store execution time seconds
150
+ exec_time_file = os .path .join (
151
+ current_directory , test_name + ".bq_exec_time_seconds"
152
+ )
153
+ with open (exec_time_file , "a" ) as f :
154
+ f .write (str (exec_seconds ) + "\n " )
133
155
134
156
# store length of query
135
157
query_char_count_file = os .path .join (
0 commit comments