Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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
3 changes: 3 additions & 0 deletions bigframes/core/pyformat.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ def _field_to_template_value(
if isinstance(value, bigframes.dataframe.DataFrame):
return _table_to_sql(value._to_placeholder_table(dry_run=dry_run))

if isinstance(value, str):
return value

return bigframes.core.sql.simple_literal(value)


Expand Down
12 changes: 5 additions & 7 deletions tests/unit/core/test_pyformat.py
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ def test_pyformat_with_pandas_dataframe_not_dry_run_no_session_raises_valueerror

def test_pyformat_with_query_string_replaces_variables(session):
pyformat_args = {
"my_string": "some string value",
"my_string": "`my_table`",
"max_value": 2.25,
"year": 2025,
"null_value": None,
Expand All @@ -456,19 +456,17 @@ def test_pyformat_with_query_string_replaces_variables(session):
SELECT {year} - year AS age,
@myparam AS myparam,
'{{my_string}}' AS escaped_string,
{my_string} AS my_string,
{null_value} AS null_value,
FROM my_dataset.my_table
*
FROM {my_string}
WHERE height < {max_value}
""".strip()

expected_sql = """
SELECT 2025 - year AS age,
@myparam AS myparam,
'{my_string}' AS escaped_string,
'some string value' AS my_string,
NULL AS null_value,
FROM my_dataset.my_table
*
FROM `my_table`
WHERE height < 2.25
""".strip()

Expand Down
2 changes: 1 addition & 1 deletion tests/unit/pandas/io/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def test_read_gbq_colab_calls_set_location(
mock_with_default_session.return_value = mock_df

query_or_table = "SELECT {param1} AS param1"
sample_pyformat_args = {"param1": "value1"}
sample_pyformat_args = {"param1": "'value1'"}
result = bf_io_api._read_gbq_colab(
query_or_table, pyformat_args=sample_pyformat_args, dry_run=False
)
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/session/test_read_gbq_colab.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def test_read_gbq_colab_includes_formatted_values_in_dry_run(monkeypatch, dry_ru

pyformat_args = {
"some_integer": 123,
"some_string": "This could be dangerous, but we escape it",
"some_string": "some_column",
"bf_df": bf_df,
"pd_df": pd_df,
# This is not a supported type, but ignored if not referenced.
Expand All @@ -84,7 +84,7 @@ def test_read_gbq_colab_includes_formatted_values_in_dry_run(monkeypatch, dry_ru
expected = textwrap.dedent(
f"""
SELECT 123 as some_integer,
'This could be dangerous, but we escape it' as some_string,
some_column as some_string,
'{{escaped}}' as escaped
FROM `proj`.`dset`.`temp_{"table" if dry_run else "view"}` AS bf_df
FULL OUTER JOIN `proj`.`dset`.`temp_{"table" if dry_run else "view"}` AS pd_df
Expand Down