@@ -235,7 +235,9 @@ def __init__(
235
235
236
236
self ._anonymous_dataset = (
237
237
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__" ,
239
241
)
240
242
)
241
243
@@ -420,9 +422,11 @@ def _query_to_destination(
420
422
# bother trying to do a CREATE TEMP TABLE ... AS SELECT ... statement.
421
423
dry_run_config = bigquery .QueryJobConfig ()
422
424
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
+ )
424
428
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 )
426
430
return query_job .destination , query_job
427
431
428
432
# Create a table to workaround BigQuery 10 GB query results limit. See:
@@ -451,23 +455,25 @@ def _query_to_destination(
451
455
bigquery .QueryJobConfig ,
452
456
bigquery .QueryJobConfig .from_api_repr (configuration ),
453
457
)
454
- job_config .labels ["bigframes-api" ] = api_name
455
458
job_config .destination = temp_table
456
459
457
460
try :
458
461
# Write to temp table to workaround BigQuery 10 GB query results
459
462
# limit. See: internal issue 303057336.
460
463
job_config .labels ["error_caught" ] = "true"
461
464
_ , 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 ,
463
469
)
464
470
return query_job .destination , query_job
465
471
except google .api_core .exceptions .BadRequest :
466
472
# Some SELECT statements still aren't compatible with cluster
467
473
# tables as the destination. For example, if the query has a
468
474
# top-level ORDER BY, this conflicts with our ability to cluster
469
475
# 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 )
471
477
return query_job .destination , query_job
472
478
473
479
def read_gbq_query (
@@ -811,7 +817,7 @@ def _read_gbq_table(
811
817
dry_run_config = bigquery .QueryJobConfig ()
812
818
dry_run_config .dry_run = True
813
819
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 )
815
821
except google .api_core .exceptions .NotFound :
816
822
# note that a notfound caused by a simple typo will be
817
823
# caught above when the metadata is fetched, not here
@@ -1777,12 +1783,6 @@ def _prepare_query_job_config(
1777
1783
bigframes .options .compute .maximum_bytes_billed
1778
1784
)
1779
1785
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
-
1786
1786
if self ._bq_kms_key_name :
1787
1787
job_config .destination_encryption_configuration = (
1788
1788
bigquery .EncryptionConfiguration (kms_key_name = self ._bq_kms_key_name )
@@ -1818,13 +1818,19 @@ def _start_query(
1818
1818
job_config : Optional [bigquery .job .QueryJobConfig ] = None ,
1819
1819
max_results : Optional [int ] = None ,
1820
1820
timeout : Optional [float ] = None ,
1821
+ api_name : Optional [str ] = None ,
1821
1822
) -> Tuple [bigquery .table .RowIterator , bigquery .QueryJob ]:
1822
1823
"""
1823
1824
Starts BigQuery query job and waits for results.
1824
1825
"""
1825
1826
job_config = self ._prepare_query_job_config (job_config )
1826
1827
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 ,
1828
1834
)
1829
1835
1830
1836
def _start_query_ml_ddl (
@@ -1970,6 +1976,9 @@ def _execute(
1970
1976
job_config = bigquery .QueryJobConfig (dry_run = dry_run )
1971
1977
else :
1972
1978
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.
1973
1982
return self ._start_query (
1974
1983
sql = sql ,
1975
1984
job_config = job_config ,
@@ -1982,6 +1991,9 @@ def _peek(
1982
1991
if not tree_properties .peekable (self ._with_cached_executions (array_value .node )):
1983
1992
warnings .warn ("Peeking this value cannot be done efficiently." )
1984
1993
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.
1985
1997
return self ._start_query (
1986
1998
sql = sql ,
1987
1999
)
0 commit comments