+
Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion google/colab/sql/bigquery.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@
# Extracts the line and column number from a dry-run error message.
_LINE_COLUMN_REGEX = re.compile(r'\[(\d+):(\d+)\]', re.MULTILINE)

# Option pair to disable the progress bar when running queries.
_NO_PROGRESS_BAR = ('display.progress_bar', None)

# Option pair to add additional query labels for telemetry purposes.
_QUERY_LABELS = (
'compute.extra_query_labels',
{'bigframes-connector': 'sql-cell'},
)


class TableReference(TypedDict):
"""A reference to a BigQuery table."""
Expand Down Expand Up @@ -140,7 +149,7 @@ def run(sql: str) -> bpd.DataFrame:
"""Executes the SQL and returns the BigQuery DataFrame."""
# repr_mode cannot be set in context manager.
bpd.options.display.repr_mode = 'anywidget'
with bpd.option_context('display.progress_bar', None):
with bpd.option_context(*_NO_PROGRESS_BAR, *_QUERY_LABELS):
# pylint: disable=protected-access
return bpd._read_gbq_colab(sql, pyformat_args=_get_ipython_locals())

Expand Down
10 changes: 8 additions & 2 deletions google/colab/sql/bigquery_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,10 @@ def test_run(self):
self.assertEqual(bigquery.run(_QUERY), expected)

self.mock_bpd_option_context.assert_called_once_with(
'display.progress_bar', None
'display.progress_bar',
None,
'compute.extra_query_labels',
{'bigframes-connector': 'sql-cell'},
)
self.mock_read_gbq_colab.assert_called_once_with(_QUERY, pyformat_args={})
self.assertEqual(bpd.options.display.repr_mode, 'anywidget')
Expand All @@ -420,7 +423,10 @@ def test_run_with_pyformat_args(self, mock_get_ipython):
self.assertEqual(bigquery.run(query), expected)

self.mock_bpd_option_context.assert_called_once_with(
'display.progress_bar', None
'display.progress_bar',
None,
'compute.extra_query_labels',
{'bigframes-connector': 'sql-cell'},
)
self.mock_read_gbq_colab.assert_called_once_with(
query, pyformat_args=user_ns
Expand Down
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载