diff --git a/packages/bigframes/bigframes/core/compile/sqlglot/sql/base.py b/packages/bigframes/bigframes/core/compile/sqlglot/sql/base.py index f77dcbee4d93..9f5136cb8226 100644 --- a/packages/bigframes/bigframes/core/compile/sqlglot/sql/base.py +++ b/packages/bigframes/bigframes/core/compile/sqlglot/sql/base.py @@ -113,6 +113,8 @@ def literal(value: typing.Any, dtype: dtypes.Dtype | None = None) -> sge.Express return sge.func("ST_GEOGFROMTEXT", sge.convert(wkt)) elif dtype == dtypes.TIMEDELTA_DTYPE: return sge.convert(utils.timedelta_to_micros(value)) + elif dtype == dtypes.STRING_DTYPE: + return sge.convert(str(value)) else: if isinstance(value, np.generic): value = value.item() diff --git a/packages/bigframes/tests/unit/core/compile/sqlglot/sql/test_base.py b/packages/bigframes/tests/unit/core/compile/sqlglot/sql/test_base.py index 617f3636d403..41a44c4f6c34 100644 --- a/packages/bigframes/tests/unit/core/compile/sqlglot/sql/test_base.py +++ b/packages/bigframes/tests/unit/core/compile/sqlglot/sql/test_base.py @@ -127,11 +127,28 @@ def test_literal_for_geo(): "PARSE_JSON('{\\'a\\': 10}')", id="json", ), + pytest.param( + 2019, + sql.dtypes.STRING_DTYPE, + "'2019'", + id="string_from_int", + ), + pytest.param( + pa.scalar(2019), + sql.dtypes.STRING_DTYPE, + "'2019'", + id="string_from_pyarrow_scalar", + ), + pytest.param( + True, + sql.dtypes.STRING_DTYPE, + "'True'", + id="string_from_bool", + ), ), ) def test_literal_explicit_dtype(value, dtype, expected): - got = sql.to_sql(sql.literal(value, dtype=dtype)) - assert got == expected + assert sql.to_sql(sql.literal(value, dtype=dtype)) == expected @pytest.mark.parametrize(