Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
This repository was archived by the owner on May 7, 2026. It is now read-only.

Commit d2d38f9

Browse filesBrowse files
feat: SQL Cell no longer escapes formatted string values (#2245)
This change updates bigframes/core/pyformat.py to directly embed str values rather than escaping them first. Unit tests have been updated to reflect this change. --- *PR created automatically by Jules for task [5189763854933796072](https://jules.google.com/task/5189763854933796072)* --------- Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com> Co-authored-by: Shenyang Cai <sycai@users.noreply.github.com>
1 parent 0d7d7e4 commit d2d38f9
Copy full SHA for d2d38f9

5 files changed

+14-13Lines changed: 14 additions & 13 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎bigframes/core/pyformat.py‎

Copy file name to clipboardExpand all lines: bigframes/core/pyformat.py
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,9 @@ def _field_to_template_value(
104104
if isinstance(value, bigframes.dataframe.DataFrame):
105105
return _table_to_sql(value._to_placeholder_table(dry_run=dry_run))
106106

107+
if isinstance(value, str):
108+
return value
109+
107110
return bigframes.core.sql.simple_literal(value)
108111

109112

Collapse file

‎tests/system/small/session/test_read_gbq_colab.py‎

Copy file name to clipboardExpand all lines: tests/system/small/session/test_read_gbq_colab.py
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ def test_read_gbq_colab_repr_avoids_requery(maybe_ordered_session):
143143
def test_read_gbq_colab_includes_formatted_scalars(session):
144144
pyformat_args = {
145145
"some_integer": 123,
146-
"some_string": "This could be dangerous, but we escape it",
146+
"some_string": "This could be dangerous.",
147147
# This is not a supported type, but ignored if not referenced.
148148
"some_object": object(),
149149
}
@@ -153,7 +153,7 @@ def test_read_gbq_colab_includes_formatted_scalars(session):
153153
df = session._read_gbq_colab(
154154
"""
155155
SELECT {some_integer} as some_integer,
156-
{some_string} as some_string,
156+
'{some_string}' as some_string,
157157
'{{escaped}}' as escaped
158158
""",
159159
pyformat_args=pyformat_args,
@@ -165,7 +165,7 @@ def test_read_gbq_colab_includes_formatted_scalars(session):
165165
{
166166
"some_integer": pandas.Series([123], dtype=pandas.Int64Dtype()),
167167
"some_string": pandas.Series(
168-
["This could be dangerous, but we escape it"],
168+
["This could be dangerous."],
169169
dtype="string[pyarrow]",
170170
),
171171
"escaped": pandas.Series(["{escaped}"], dtype="string[pyarrow]"),
Collapse file

‎tests/unit/core/test_pyformat.py‎

Copy file name to clipboardExpand all lines: tests/unit/core/test_pyformat.py
+5-7Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@ def test_pyformat_with_pandas_dataframe_not_dry_run_no_session_raises_valueerror
444444

445445
def test_pyformat_with_query_string_replaces_variables(session):
446446
pyformat_args = {
447-
"my_string": "some string value",
447+
"my_string": "`my_table`",
448448
"max_value": 2.25,
449449
"year": 2025,
450450
"null_value": None,
@@ -456,19 +456,17 @@ def test_pyformat_with_query_string_replaces_variables(session):
456456
SELECT {year} - year AS age,
457457
@myparam AS myparam,
458458
'{{my_string}}' AS escaped_string,
459-
{my_string} AS my_string,
460-
{null_value} AS null_value,
461-
FROM my_dataset.my_table
459+
*
460+
FROM {my_string}
462461
WHERE height < {max_value}
463462
""".strip()
464463

465464
expected_sql = """
466465
SELECT 2025 - year AS age,
467466
@myparam AS myparam,
468467
'{my_string}' AS escaped_string,
469-
'some string value' AS my_string,
470-
NULL AS null_value,
471-
FROM my_dataset.my_table
468+
*
469+
FROM `my_table`
472470
WHERE height < 2.25
473471
""".strip()
474472

Collapse file

‎tests/unit/pandas/io/test_api.py‎

Copy file name to clipboardExpand all lines: tests/unit/pandas/io/test_api.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ def test_read_gbq_colab_calls_set_location(
108108
mock_with_default_session.return_value = mock_df
109109

110110
query_or_table = "SELECT {param1} AS param1"
111-
sample_pyformat_args = {"param1": "value1"}
111+
sample_pyformat_args = {"param1": "'value1'"}
112112
result = bf_io_api._read_gbq_colab(
113113
query_or_table, pyformat_args=sample_pyformat_args, dry_run=False
114114
)
Collapse file

‎tests/unit/session/test_read_gbq_colab.py‎

Copy file name to clipboardExpand all lines: tests/unit/session/test_read_gbq_colab.py
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def test_read_gbq_colab_includes_formatted_values_in_dry_run(monkeypatch, dry_ru
6060

6161
pyformat_args = {
6262
"some_integer": 123,
63-
"some_string": "This could be dangerous, but we escape it",
63+
"some_string": "some_column",
6464
"bf_df": bf_df,
6565
"pd_df": pd_df,
6666
# This is not a supported type, but ignored if not referenced.
@@ -84,7 +84,7 @@ def test_read_gbq_colab_includes_formatted_values_in_dry_run(monkeypatch, dry_ru
8484
expected = textwrap.dedent(
8585
f"""
8686
SELECT 123 as some_integer,
87-
'This could be dangerous, but we escape it' as some_string,
87+
some_column as some_string,
8888
'{{escaped}}' as escaped
8989
FROM `proj`.`dset`.`temp_{"table" if dry_run else "view"}` AS bf_df
9090
FULL OUTER JOIN `proj`.`dset`.`temp_{"table" if dry_run else "view"}` AS pd_df

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.