Skip to content

Commit 9752da1

Browse files
refactor: Reduce executor cache interface to one method (#1133)
1 parent 7216b21 commit 9752da1

File tree

2 files changed

+24
-8
lines changed

2 files changed

+24
-8
lines changed

bigframes/core/blocks.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2426,14 +2426,12 @@ def to_sql_query(
24262426
def cached(self, *, force: bool = False, session_aware: bool = False) -> None:
24272427
"""Write the block to a session table."""
24282428
# use a heuristic for whether something needs to be cached
2429-
if (not force) and self.session._executor._is_trivially_executable(self.expr):
2430-
return
2431-
elif session_aware:
2432-
self.session._executor._cache_with_session_awareness(self.expr)
2433-
else:
2434-
self.session._executor._cache_with_cluster_cols(
2435-
self.expr, cluster_cols=self.index_columns
2436-
)
2429+
self.session._executor.cached(
2430+
self.expr,
2431+
force=force,
2432+
use_session=session_aware,
2433+
cluster_cols=self.index_columns,
2434+
)
24372435

24382436
def _is_monotonic(
24392437
self, column_ids: typing.Union[str, Sequence[str]], increasing: bool

bigframes/session/executor.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ def __init__(
9494
bqclient: bigquery.Client,
9595
storage_manager: bigframes.session.temp_storage.TemporaryGbqStorageManager,
9696
bqstoragereadclient: google.cloud.bigquery_storage_v1.BigQueryReadClient,
97+
*,
9798
strictly_ordered: bool = True,
9899
metrics: Optional[bigframes.session.metrics.ExecutionMetrics] = None,
99100
):
@@ -354,6 +355,23 @@ def get_row_count(self, array_value: bigframes.core.ArrayValue) -> int:
354355
iter, _ = self._run_execute_query(sql)
355356
return next(iter)[0]
356357

358+
def cached(
359+
self,
360+
array_value: bigframes.core.ArrayValue,
361+
*,
362+
force: bool = False,
363+
use_session: bool = False,
364+
cluster_cols: Sequence[str] = (),
365+
) -> None:
366+
"""Write the block to a session table."""
367+
# use a heuristic for whether something needs to be cached
368+
if (not force) and self._is_trivially_executable(array_value):
369+
return
370+
elif use_session:
371+
self._cache_with_session_awareness(array_value)
372+
else:
373+
self._cache_with_cluster_cols(array_value, cluster_cols=cluster_cols)
374+
357375
def _local_get_row_count(
358376
self, array_value: bigframes.core.ArrayValue
359377
) -> Optional[int]:

0 commit comments

Comments
 (0)