File tree Expand file tree Collapse file tree 3 files changed +35
-10
lines changed
Expand file tree Collapse file tree 3 files changed +35
-10
lines changed Original file line number Diff line number Diff line change @@ -51,5 +51,9 @@ class OrderRequiredError(ValueError):
5151 """Operation requires total row ordering to be enabled."""
5252
5353
54+ class QueryComplexityError (RuntimeError ):
55+ """Query plan is too complex to execute."""
56+
57+
5458class TimeTravelDisabledWarning (Warning ):
5559 """A query was reattempted without time travel."""
Original file line number Diff line number Diff line change @@ -1833,14 +1833,22 @@ def _start_query(
18331833 Starts BigQuery query job and waits for results.
18341834 """
18351835 job_config = self ._prepare_query_job_config (job_config )
1836- return bigframes .session ._io .bigquery .start_query_with_client (
1837- self ,
1838- sql ,
1839- job_config ,
1840- max_results ,
1841- timeout ,
1842- api_name = api_name ,
1843- )
1836+ try :
1837+ return bigframes .session ._io .bigquery .start_query_with_client (
1838+ self ,
1839+ sql ,
1840+ job_config ,
1841+ max_results ,
1842+ timeout ,
1843+ api_name = api_name ,
1844+ )
1845+ except google .api_core .exceptions .BadRequest as e :
1846+ # Unfortunately, this error type does not have a separate error code or exception type
1847+ if "Resources exceeded during query execution" in e .message :
1848+ new_message = "Computation is too complex to execute as a single query. Try using DataFrame.cache() on intermediate results, or setting bigframes.options.compute.enable_multi_query_execution."
1849+ raise bigframes .exceptions .QueryComplexityError (new_message ) from e
1850+ else :
1851+ raise
18441852
18451853 def _start_query_ml_ddl (
18461854 self ,
Original file line number Diff line number Diff line change @@ -4472,13 +4472,26 @@ def test_recursion_limit(scalars_df_index):
44724472 scalars_df_index .to_pandas ()
44734473
44744474
4475+ def test_query_complexity_error (scalars_df_index ):
4476+ # This test requires automatic caching/query decomposition to be turned off
4477+ bf_df = scalars_df_index
4478+ for _ in range (8 ):
4479+ bf_df = bf_df .merge (bf_df , on = "int64_col" ).head (30 )
4480+ bf_df = bf_df [bf_df .columns [:20 ]]
4481+
4482+ with pytest .raises (
4483+ bigframes .exceptions .QueryComplexityError , match = r"Try using DataFrame\.cache"
4484+ ):
4485+ bf_df .to_pandas ()
4486+
4487+
44754488def test_query_complexity_repeated_joins (
44764489 scalars_df_index , scalars_pandas_df_index , with_multiquery_execution
44774490):
44784491 pd_df = scalars_pandas_df_index
44794492 bf_df = scalars_df_index
4480- for _ in range (6 ):
4481- # recursively join, resuling in 2^6 - 1 = 63 joins
4493+ for _ in range (8 ):
4494+ # recursively join, resuling in 2^8 - 1 = 255 joins
44824495 pd_df = pd_df .merge (pd_df , on = "int64_col" ).head (30 )
44834496 pd_df = pd_df [pd_df .columns [:20 ]]
44844497 bf_df = bf_df .merge (bf_df , on = "int64_col" ).head (30 )
You can’t perform that action at this time.
0 commit comments