@@ -235,7 +235,9 @@ def __init__(
235235
236236 self ._anonymous_dataset = (
237237 bigframes .session ._io .bigquery .create_bq_dataset_reference (
238- self .bqclient , location = self ._location
238+ self .bqclient ,
239+ location = self ._location ,
240+ api_name = "session-__init__" ,
239241 )
240242 )
241243
@@ -420,9 +422,11 @@ def _query_to_destination(
420422 # bother trying to do a CREATE TEMP TABLE ... AS SELECT ... statement.
421423 dry_run_config = bigquery .QueryJobConfig ()
422424 dry_run_config .dry_run = True
423- _ , dry_run_job = self ._start_query (query , job_config = dry_run_config )
425+ _ , dry_run_job = self ._start_query (
426+ query , job_config = dry_run_config , api_name = api_name
427+ )
424428 if dry_run_job .statement_type != "SELECT" :
425- _ , query_job = self ._start_query (query )
429+ _ , query_job = self ._start_query (query , api_name = api_name )
426430 return query_job .destination , query_job
427431
428432 # Create a table to workaround BigQuery 10 GB query results limit. See:
@@ -451,23 +455,25 @@ def _query_to_destination(
451455 bigquery .QueryJobConfig ,
452456 bigquery .QueryJobConfig .from_api_repr (configuration ),
453457 )
454- job_config .labels ["bigframes-api" ] = api_name
455458 job_config .destination = temp_table
456459
457460 try :
458461 # Write to temp table to workaround BigQuery 10 GB query results
459462 # limit. See: internal issue 303057336.
460463 job_config .labels ["error_caught" ] = "true"
461464 _ , query_job = self ._start_query (
462- query , job_config = job_config , timeout = timeout
465+ query ,
466+ job_config = job_config ,
467+ timeout = timeout ,
468+ api_name = api_name ,
463469 )
464470 return query_job .destination , query_job
465471 except google .api_core .exceptions .BadRequest :
466472 # Some SELECT statements still aren't compatible with cluster
467473 # tables as the destination. For example, if the query has a
468474 # top-level ORDER BY, this conflicts with our ability to cluster
469475 # the table by the index column(s).
470- _ , query_job = self ._start_query (query , timeout = timeout )
476+ _ , query_job = self ._start_query (query , timeout = timeout , api_name = api_name )
471477 return query_job .destination , query_job
472478
473479 def read_gbq_query (
@@ -811,7 +817,7 @@ def _read_gbq_table(
811817 dry_run_config = bigquery .QueryJobConfig ()
812818 dry_run_config .dry_run = True
813819 try :
814- self ._start_query (sql , job_config = dry_run_config )
820+ self ._start_query (sql , job_config = dry_run_config , api_name = api_name )
815821 except google .api_core .exceptions .NotFound :
816822 # note that a notfound caused by a simple typo will be
817823 # caught above when the metadata is fetched, not here
@@ -1777,12 +1783,6 @@ def _prepare_query_job_config(
17771783 bigframes .options .compute .maximum_bytes_billed
17781784 )
17791785
1780- current_labels = job_config .labels if job_config .labels else {}
1781- for key , value in bigframes .options .compute .extra_query_labels .items ():
1782- if key not in current_labels :
1783- current_labels [key ] = value
1784- job_config .labels = current_labels
1785-
17861786 if self ._bq_kms_key_name :
17871787 job_config .destination_encryption_configuration = (
17881788 bigquery .EncryptionConfiguration (kms_key_name = self ._bq_kms_key_name )
@@ -1818,13 +1818,19 @@ def _start_query(
18181818 job_config : Optional [bigquery .job .QueryJobConfig ] = None ,
18191819 max_results : Optional [int ] = None ,
18201820 timeout : Optional [float ] = None ,
1821+ api_name : Optional [str ] = None ,
18211822 ) -> Tuple [bigquery .table .RowIterator , bigquery .QueryJob ]:
18221823 """
18231824 Starts BigQuery query job and waits for results.
18241825 """
18251826 job_config = self ._prepare_query_job_config (job_config )
18261827 return bigframes .session ._io .bigquery .start_query_with_client (
1827- self .bqclient , sql , job_config , max_results , timeout
1828+ self .bqclient ,
1829+ sql ,
1830+ job_config ,
1831+ max_results ,
1832+ timeout ,
1833+ api_name = api_name ,
18281834 )
18291835
18301836 def _start_query_ml_ddl (
@@ -1970,6 +1976,9 @@ def _execute(
19701976 job_config = bigquery .QueryJobConfig (dry_run = dry_run )
19711977 else :
19721978 job_config .dry_run = dry_run
1979+
1980+ # TODO(swast): plumb through the api_name of the user-facing api that
1981+ # caused this query.
19731982 return self ._start_query (
19741983 sql = sql ,
19751984 job_config = job_config ,
@@ -1982,6 +1991,9 @@ def _peek(
19821991 if not tree_properties .peekable (self ._with_cached_executions (array_value .node )):
19831992 warnings .warn ("Peeking this value cannot be done efficiently." )
19841993 sql = self ._compile_unordered (array_value ).peek_sql (n_rows )
1994+
1995+ # TODO(swast): plumb through the api_name of the user-facing api that
1996+ # caused this query.
19851997 return self ._start_query (
19861998 sql = sql ,
19871999 )
0 commit comments