@@ -151,12 +151,6 @@ def progress_callback(
151151 display .HTML (previous_display_html ),
152152 display_id = current_display_id ,
153153 )
154- elif isinstance (event , bigframes .core .events .BigQueryUnknownEvent ):
155- previous_display_html = render_bqquery_unknown_event_html (event )
156- display .update_display (
157- display .HTML (previous_display_html ),
158- display_id = current_display_id ,
159- )
160154 elif isinstance (event , bigframes .core .events .ExecutionFinished ):
161155 display .update_display (
162156 display .HTML (f"{ previous_display_html } Execution done." ),
@@ -177,9 +171,6 @@ def progress_callback(
177171 elif isinstance (event , bigframes .core .events .BigQueryFinishedEvent ):
178172 message = render_bqquery_finished_event_plaintext (event )
179173 print (message )
180- elif isinstance (event , bigframes .core .events .BigQueryUnknownEvent ):
181- message = render_bqquery_unknown_event_plaintext (event )
182- print (message )
183174 elif isinstance (event , bigframes .core .events .ExecutionFinished ):
184175 print ("Execution done." )
185176
@@ -232,6 +223,57 @@ def wait_for_job(job: GenericJob, progress_bar: Optional[str] = None):
232223 raise
233224
234225
226+ def render_query_references (
227+ * ,
228+ project_id : Optional [str ],
229+ location : Optional [str ],
230+ job_id : Optional [str ],
231+ request_id : Optional [str ],
232+ ) -> str :
233+ query_id = ""
234+ if job_id :
235+ query_id = f" with job ID { project_id } :{ location } .{ job_id } "
236+ elif request_id :
237+ query_id = f" with request ID { project_id } :{ location } .{ request_id } "
238+ return query_id
239+
240+
241+ def render_job_link_html (
242+ * ,
243+ project_id : Optional [str ],
244+ location : Optional [str ],
245+ job_id : Optional [str ],
246+ ) -> str :
247+ job_url = get_job_url (
248+ project_id = project_id ,
249+ location = location ,
250+ job_id = job_id ,
251+ )
252+ if job_url :
253+ job_link = f' <a target="_blank" href="{ job_url } ">Open Job</a>'
254+ else :
255+ job_link = ""
256+ return job_link
257+
258+
259+ def render_job_link_plaintext (
260+ * ,
261+ project_id : Optional [str ],
262+ location : Optional [str ],
263+ job_id : Optional [str ],
264+ ) -> str :
265+ job_url = get_job_url (
266+ project_id = project_id ,
267+ location = location ,
268+ job_id = job_id ,
269+ )
270+ if job_url :
271+ job_link = f" Open Job: { job_url } "
272+ else :
273+ job_link = ""
274+ return job_link
275+
276+
235277def get_job_url (
236278 * ,
237279 project_id : Optional [str ],
@@ -259,22 +301,17 @@ def render_bqquery_sent_event_html(
259301 Html string.
260302 """
261303
262- job_url = get_job_url (
304+ job_link = render_job_link_html (
263305 project_id = event .billing_project ,
264306 location = event .location ,
265307 job_id = event .job_id ,
266308 )
267- if job_url :
268- job_link = f'<a target="_blank" href="{ job_url } ">Open Job</a>'
269- else :
270- job_link = ""
271-
272- query_id = ""
273- if event .job_id :
274- query_id = f" with job ID { event .job_id } :{ event .billing_project } .{ event .job_id } "
275- elif event .request_id :
276- query_id = f" with request ID { event .job_id } :{ event .billing_project } .{ event .request_id } "
277-
309+ query_id = render_query_references (
310+ project_id = event .billing_project ,
311+ location = event .location ,
312+ job_id = event .job_id ,
313+ request_id = event .request_id ,
314+ )
278315 query_text_details = f"<details><summary>SQL</summary><pre>{ html .escape (event .query )} </pre></details>"
279316
280317 return f"""
@@ -293,21 +330,17 @@ def render_bqquery_sent_event_plaintext(
293330 Html string.
294331 """
295332
296- job_url = get_job_url (
333+ job_link = render_job_link_plaintext (
297334 project_id = event .billing_project ,
298335 location = event .location ,
299336 job_id = event .job_id ,
300337 )
301- if job_url :
302- job_link = f" Open job: { job_url } "
303- else :
304- job_link = ""
305-
306- query_id = ""
307- if event .job_id :
308- query_id = f" with job ID { event .job_id } :{ event .billing_project } .{ event .job_id } "
309- elif event .request_id :
310- query_id = f" with request ID { event .job_id } :{ event .billing_project } .{ event .request_id } "
338+ query_id = render_query_references (
339+ project_id = event .billing_project ,
340+ location = event .location ,
341+ job_id = event .job_id ,
342+ request_id = event .request_id ,
343+ )
311344
312345 return f"Query started{ query_id } .{ job_link } "
313346
@@ -317,25 +350,18 @@ def render_bqquery_retry_event_html(
317350) -> str :
318351 """Return progress bar html string for retry event."""
319352
320- job_url = get_job_url (
353+ job_link = render_job_link_html (
321354 project_id = event .billing_project ,
322355 location = event .location ,
323356 job_id = event .job_id ,
324357 )
325- if job_url :
326- job_link = f'<a target="_blank" href="{ job_url } ">Open Job</a>'
327- else :
328- job_link = ""
329-
330- query_id = ""
331- if event .job_id :
332- query_id = f" with job ID { event .billing_project } .{ event .job_id } "
333- elif event .request_id :
334- query_id = f" with request ID { event .billing_project } .{ event .request_id } "
335-
336- query_text_details = (
337- f"<details><summary>SQL</summary><pre>{ html .escape (event .query )} </pre></details>"
358+ query_id = render_query_references (
359+ project_id = event .billing_project ,
360+ location = event .location ,
361+ job_id = event .job_id ,
362+ request_id = event .request_id ,
338363 )
364+ query_text_details = f"<details><summary>SQL</summary><pre>{ html .escape (event .query )} </pre></details>"
339365
340366 return f"""
341367 Retrying query{ query_id } .{ job_link } { query_text_details }
@@ -347,22 +373,17 @@ def render_bqquery_retry_event_plaintext(
347373) -> str :
348374 """Return progress bar plaintext string for retry event."""
349375
350- job_url = get_job_url (
376+ job_link = render_job_link_plaintext (
351377 project_id = event .billing_project ,
352378 location = event .location ,
353379 job_id = event .job_id ,
354380 )
355- if job_url :
356- job_link = f" Open job: { job_url } "
357- else :
358- job_link = ""
359-
360- query_id = ""
361- if event .job_id :
362- query_id = f" with job ID { event .billing_project } .{ event .job_id } "
363- elif event .request_id :
364- query_id = f" with request ID { event .billing_project } .{ event .request_id } "
365-
381+ query_id = render_query_references (
382+ project_id = event .billing_project ,
383+ location = event .location ,
384+ job_id = event .job_id ,
385+ request_id = event .request_id ,
386+ )
366387 return f"Retrying query{ query_id } .{ job_link } "
367388
368389
@@ -371,29 +392,25 @@ def render_bqquery_received_event_html(
371392) -> str :
372393 """Return progress bar html string for received event."""
373394
374- job_url = get_job_url (
395+ job_link = render_job_link_html (
375396 project_id = event .billing_project ,
376397 location = event .location ,
377398 job_id = event .job_id ,
378399 )
379- if job_url :
380- job_link = f'<a target="_blank" href="{ job_url } ">Open Job</a>'
381- else :
382- job_link = ""
383-
384- # Don't have billing project and job ID in the same string, as that's
385- # redundant with the job link.
386- job_id_str = ""
387- if event .job_id :
388- job_id_str = f" { event .job_id } "
400+ query_id = render_query_references (
401+ project_id = event .billing_project ,
402+ location = event .location ,
403+ job_id = event .job_id ,
404+ request_id = None ,
405+ )
389406
390407 query_plan_details = ""
391408 if event .query_plan :
392409 plan_str = "\n " .join ([str (entry ) for entry in event .query_plan ])
393410 query_plan_details = f"<details><summary>Query Plan</summary><pre>{ html .escape (plan_str )} </pre></details>"
394411
395412 return f"""
396- Query job { job_id_str } is { event .state } .{ job_link } { query_plan_details }
413+ Query{ query_id } is { event .state } .{ job_link } { query_plan_details }
397414 """
398415
399416
@@ -402,44 +419,25 @@ def render_bqquery_received_event_plaintext(
402419) -> str :
403420 """Return progress bar plaintext string for received event."""
404421
405- job_url = get_job_url (
422+ job_link = render_job_link_plaintext (
406423 project_id = event .billing_project ,
407424 location = event .location ,
408425 job_id = event .job_id ,
409426 )
410- if job_url :
411- job_link = f" Open job: { job_url } "
412- else :
413- job_link = ""
414-
415- job_id_str = ""
416- if event .job_id :
417- job_id_str = f" { event .job_id } "
418-
419- return f"Query job{ job_id_str } is { event .state } .{ job_link } "
427+ query_id = render_query_references (
428+ project_id = event .billing_project ,
429+ location = event .location ,
430+ job_id = event .job_id ,
431+ request_id = None ,
432+ )
433+ return f"Query{ query_id } is { event .state } .{ job_link } "
420434
421435
422436def render_bqquery_finished_event_html (
423437 event : bigframes .core .events .BigQueryFinishedEvent ,
424438) -> str :
425439 """Return progress bar html string for finished event."""
426440
427- job_url = get_job_url (
428- project_id = event .billing_project ,
429- location = event .location ,
430- job_id = event .job_id ,
431- )
432- if job_url :
433- job_link = f'<a target="_blank" href="{ job_url } ">Open Job</a>'
434- else :
435- job_link = ""
436-
437- # Don't have billing project and job ID in the same string, as that's
438- # redundant with the job link.
439- job_id_str = ""
440- if event .job_id :
441- job_id_str = f" { event .job_id } "
442-
443441 bytes_str = ""
444442 if event .total_bytes_processed is not None :
445443 bytes_str = f" { humanize .naturalsize (event .total_bytes_processed )} processed."
@@ -449,8 +447,19 @@ def render_bqquery_finished_event_html(
449447 slot_time = datetime .timedelta (milliseconds = event .slot_millis )
450448 slot_time_str = f" Slot time: { humanize .naturaldelta (slot_time )} ."
451449
450+ job_link = render_job_link_html (
451+ project_id = event .billing_project ,
452+ location = event .location ,
453+ job_id = event .job_id ,
454+ )
455+ query_id = render_query_references (
456+ project_id = event .billing_project ,
457+ location = event .location ,
458+ job_id = event .job_id ,
459+ request_id = None ,
460+ )
452461 return f"""
453- Query job { job_id_str } finished.{ bytes_str } { slot_time_str } { job_link }
462+ Query{ query_id } finished.{ bytes_str } { slot_time_str } { job_link }
454463 """
455464
456465
@@ -459,20 +468,6 @@ def render_bqquery_finished_event_plaintext(
459468) -> str :
460469 """Return progress bar plaintext string for finished event."""
461470
462- job_url = get_job_url (
463- project_id = event .billing_project ,
464- location = event .location ,
465- job_id = event .job_id ,
466- )
467- if job_url :
468- job_link = f" Open job: { job_url } "
469- else :
470- job_link = ""
471-
472- job_id_str = ""
473- if event .job_id :
474- job_id_str = f" { event .job_id } "
475-
476471 bytes_str = ""
477472 if event .total_bytes_processed is not None :
478473 bytes_str = f" { humanize .naturalsize (event .total_bytes_processed )} processed."
@@ -482,21 +477,18 @@ def render_bqquery_finished_event_plaintext(
482477 slot_time = datetime .timedelta (milliseconds = event .slot_millis )
483478 slot_time_str = f" Slot time: { humanize .naturaldelta (slot_time )} ."
484479
485- return f"Query job{ job_id_str } finished.{ bytes_str } { slot_time_str } { job_link } "
486-
487-
488- def render_bqquery_unknown_event_html (
489- event : bigframes .core .events .BigQueryUnknownEvent ,
490- ) -> str :
491- """Return progress bar html string for unknown event."""
492- return "Received unknown event."
493-
494-
495- def render_bqquery_unknown_event_plaintext (
496- event : bigframes .core .events .BigQueryUnknownEvent ,
497- ) -> str :
498- """Return progress bar plaintext string for unknown event."""
499- return "Received unknown event."
480+ job_link = render_job_link_plaintext (
481+ project_id = event .billing_project ,
482+ location = event .location ,
483+ job_id = event .job_id ,
484+ )
485+ query_id = render_query_references (
486+ project_id = event .billing_project ,
487+ location = event .location ,
488+ job_id = event .job_id ,
489+ request_id = None ,
490+ )
491+ return f"Query{ query_id } finished.{ bytes_str } { slot_time_str } { job_link } "
500492
501493
502494def get_base_job_loading_html (job : GenericJob ):
0 commit comments