@@ -37,30 +37,41 @@ def _table_to_sql(table: _BQ_TABLE_TYPES) -> str:
3737 return f"`{ table .project } `.`{ table .dataset_id } `.`{ table .table_id } `"
3838
3939
40- def _field_to_template_value (name : str , value : Any ) -> str :
40+ def _field_to_template_value (
41+ name : str ,
42+ value : Any ,
43+ ) -> str :
4144 """Convert value to something embeddable in a SQL string."""
4245 import bigframes .core .sql # Avoid circular imports
46+ import bigframes .dataframe # Avoid circular imports
4347
4448 _validate_type (name , value )
4549
4650 table_types = typing .get_args (_BQ_TABLE_TYPES )
4751 if isinstance (value , table_types ):
4852 return _table_to_sql (value )
4953
50- # TODO(tswast): convert DataFrame objects to gbq tables or a literals subquery.
54+ # TODO(tswast): convert pandas DataFrame objects to gbq tables or a literals subquery.
55+ if isinstance (value , bigframes .dataframe .DataFrame ):
56+ return _table_to_sql (value ._to_view ())
57+
5158 return bigframes .core .sql .simple_literal (value )
5259
5360
5461def _validate_type (name : str , value : Any ):
5562 """Raises TypeError if value is unsupported."""
5663 import bigframes .core .sql # Avoid circular imports
64+ import bigframes .dataframe # Avoid circular imports
5765
5866 if value is None :
5967 return # None can't be used in isinstance, but is a valid literal.
6068
61- supported_types = typing .get_args (_BQ_TABLE_TYPES ) + typing .get_args (
62- bigframes .core .sql .SIMPLE_LITERAL_TYPES
69+ supported_types = (
70+ typing .get_args (_BQ_TABLE_TYPES )
71+ + typing .get_args (bigframes .core .sql .SIMPLE_LITERAL_TYPES )
72+ + (bigframes .dataframe .DataFrame ,)
6373 )
74+
6475 if not isinstance (value , supported_types ):
6576 raise TypeError (
6677 f"{ name } has unsupported type: { type (value )} . "
@@ -80,8 +91,6 @@ def pyformat(
8091 sql_template : str ,
8192 * ,
8293 pyformat_args : dict ,
83- # TODO: add dry_run parameter to avoid expensive API calls in conversion
84- # TODO: and session to upload data / convert to table if necessary
8594) -> str :
8695 """Unsafe Python-style string formatting of SQL string.
8796
0 commit comments