GeezerVison is showing github.com — feat: SQL Cell no longer escapes formatted string values (#2245) · google/bigframes@d2d38f9
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: bigframes/core/pyformat.py +3Lines changed: 3 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -104,6 +104,9 @@ def _field_to_template_value( | 104 | 104 | if isinstance(value, bigframes.dataframe.DataFrame): | 105 | 105 | return _table_to_sql(value._to_placeholder_table(dry_run=dry_run)) | 106 | 106 |
| | 107 | + if isinstance(value, str): | | 108 | + return value | | 109 | + | 107 | 110 | return bigframes.core.sql.simple_literal(value) | 108 | 111 |
| 109 | 112 |
| |
Collapse file 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 number | Diff line number | Diff line change |
|---|
@@ -143,7 +143,7 @@ def test_read_gbq_colab_repr_avoids_requery(maybe_ordered_session): | 143 | 143 | def test_read_gbq_colab_includes_formatted_scalars(session): | 144 | 144 | pyformat_args = { | 145 | 145 | "some_integer": 123, | 146 | | - "some_string": "This could be dangerous, but we escape it", | | 146 | + "some_string": "This could be dangerous.", | 147 | 147 | # This is not a supported type, but ignored if not referenced. | 148 | 148 | "some_object": object(), | 149 | 149 | } | @@ -153,7 +153,7 @@ def test_read_gbq_colab_includes_formatted_scalars(session): | 153 | 153 | df = session._read_gbq_colab( | 154 | 154 | """ | 155 | 155 | SELECT {some_integer} as some_integer, | 156 | | - {some_string} as some_string, | | 156 | + '{some_string}' as some_string, | 157 | 157 | '{{escaped}}' as escaped | 158 | 158 | """, | 159 | 159 | pyformat_args=pyformat_args, | @@ -165,7 +165,7 @@ def test_read_gbq_colab_includes_formatted_scalars(session): | 165 | 165 | { | 166 | 166 | "some_integer": pandas.Series([123], dtype=pandas.Int64Dtype()), | 167 | 167 | "some_string": pandas.Series( | 168 | | - ["This could be dangerous, but we escape it"], | | 168 | + ["This could be dangerous."], | 169 | 169 | dtype="string[pyarrow]", | 170 | 170 | ), | 171 | 171 | "escaped": pandas.Series(["{escaped}"], dtype="string[pyarrow]"), | |
Collapse file Copy file name to clipboardExpand all lines: tests/unit/core/test_pyformat.py +5-7Lines changed: 5 additions & 7 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -444,7 +444,7 @@ def test_pyformat_with_pandas_dataframe_not_dry_run_no_session_raises_valueerror | 444 | 444 |
| 445 | 445 | def test_pyformat_with_query_string_replaces_variables(session): | 446 | 446 | pyformat_args = { | 447 | | - "my_string": "some string value", | | 447 | + "my_string": "`my_table`", | 448 | 448 | "max_value": 2.25, | 449 | 449 | "year": 2025, | 450 | 450 | "null_value": None, | @@ -456,19 +456,17 @@ def test_pyformat_with_query_string_replaces_variables(session): | 456 | 456 | SELECT {year} - year AS age, | 457 | 457 | @myparam AS myparam, | 458 | 458 | '{{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} | 462 | 461 | WHERE height < {max_value} | 463 | 462 | """.strip() | 464 | 463 |
| 465 | 464 | expected_sql = """ | 466 | 465 | SELECT 2025 - year AS age, | 467 | 466 | @myparam AS myparam, | 468 | 467 | '{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` | 472 | 470 | WHERE height < 2.25 | 473 | 471 | """.strip() | 474 | 472 |
| |
Collapse file Copy file name to clipboardExpand all lines: tests/unit/pandas/io/test_api.py +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -108,7 +108,7 @@ def test_read_gbq_colab_calls_set_location( | 108 | 108 | mock_with_default_session.return_value = mock_df | 109 | 109 |
| 110 | 110 | query_or_table = "SELECT {param1} AS param1" | 111 | | - sample_pyformat_args = {"param1": "value1"} | | 111 | + sample_pyformat_args = {"param1": "'value1'"} | 112 | 112 | result = bf_io_api._read_gbq_colab( | 113 | 113 | query_or_table, pyformat_args=sample_pyformat_args, dry_run=False | 114 | 114 | ) | |
Collapse file 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 number | Diff line number | Diff line change |
|---|
@@ -60,7 +60,7 @@ def test_read_gbq_colab_includes_formatted_values_in_dry_run(monkeypatch, dry_ru | 60 | 60 |
| 61 | 61 | pyformat_args = { | 62 | 62 | "some_integer": 123, | 63 | | - "some_string": "This could be dangerous, but we escape it", | | 63 | + "some_string": "some_column", | 64 | 64 | "bf_df": bf_df, | 65 | 65 | "pd_df": pd_df, | 66 | 66 | # 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 | 84 | 84 | expected = textwrap.dedent( | 85 | 85 | f""" | 86 | 86 | SELECT 123 as some_integer, | 87 | | - 'This could be dangerous, but we escape it' as some_string, | | 87 | + some_column as some_string, | 88 | 88 | '{{escaped}}' as escaped | 89 | 89 | FROM `proj`.`dset`.`temp_{"table" if dry_run else "view"}` AS bf_df | 90 | 90 | FULL OUTER JOIN `proj`.`dset`.`temp_{"table" if dry_run else "view"}` AS pd_df | |
|