Skip to content

Commit 30e11d9

Browse files
refactor: Limit access to ArrayValue node field. (#977)
1 parent 42b0724 commit 30e11d9

File tree

4 files changed

+23
-12
lines changed

4 files changed

+23
-12
lines changed

bigframes/core/__init__.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import bigframes.core.ordering as orderings
3737
import bigframes.core.rewrite
3838
import bigframes.core.schema as schemata
39+
import bigframes.core.tree_properties
3940
import bigframes.core.utils
4041
from bigframes.core.window_spec import WindowSpec
4142
import bigframes.dtypes
@@ -124,6 +125,20 @@ def schema(self) -> schemata.ArraySchema:
124125
def _compiled_schema(self) -> schemata.ArraySchema:
125126
return bigframes.core.compile.test_only_ibis_inferred_schema(self.node)
126127

128+
@property
129+
def explicitly_ordered(self) -> bool:
130+
# see BigFrameNode.explicitly_ordered
131+
return self.node.explicitly_ordered
132+
133+
@property
134+
def order_ambiguous(self) -> bool:
135+
# see BigFrameNode.order_ambiguous
136+
return self.node.order_ambiguous
137+
138+
@property
139+
def supports_fast_peek(self) -> bool:
140+
return bigframes.core.tree_properties.can_fast_peek(self.node)
141+
127142
def as_cached(
128143
self: ArrayValue,
129144
cache_table: google.cloud.bigquery.Table,

bigframes/core/blocks.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@
4949
import bigframes.core.ordering as ordering
5050
import bigframes.core.schema as bf_schema
5151
import bigframes.core.sql as sql
52-
import bigframes.core.tree_properties as tree_properties
5352
import bigframes.core.utils as utils
5453
import bigframes.core.window_spec as window_specs
5554
import bigframes.dtypes
@@ -205,7 +204,7 @@ def shape(self) -> typing.Tuple[int, int]:
205204
row_count_expr = self.expr.row_count()
206205

207206
# Support in-memory engines for hermetic unit tests.
208-
if self.expr.node.session is None:
207+
if self.expr.session is None:
209208
try:
210209
row_count = row_count_expr._try_evaluate_local().squeeze()
211210
return (row_count, len(self.value_columns))
@@ -283,7 +282,7 @@ def index_name_to_col_id(self) -> typing.Mapping[Label, typing.Sequence[str]]:
283282

284283
@property
285284
def explicitly_ordered(self) -> bool:
286-
return self.expr.node.explicitly_ordered
285+
return self.expr.explicitly_ordered
287286

288287
def cols_matching_label(self, partial_label: Label) -> typing.Sequence[str]:
289288
"""
@@ -466,7 +465,7 @@ def _validate_result_schema(
466465
):
467466
actual_schema = tuple(bq_result_schema)
468467
ibis_schema = self.expr._compiled_schema
469-
internal_schema = self.expr.node.schema
468+
internal_schema = self.expr.schema
470469
if not bigframes.features.PANDAS_VERSIONS.is_arrow_list_dtype_usable:
471470
return
472471
if internal_schema.to_bigquery() != actual_schema:
@@ -561,7 +560,7 @@ def to_pandas(
561560
def try_peek(
562561
self, n: int = 20, force: bool = False
563562
) -> typing.Optional[pd.DataFrame]:
564-
if force or tree_properties.can_fast_peek(self.expr.node):
563+
if force or self.expr.supports_fast_peek:
565564
iterator, _ = self.session._peek(self.expr, n)
566565
df = self._to_dataframe(iterator)
567566
self._copy_index_to_pandas(df)
@@ -2365,10 +2364,7 @@ def cached(self, *, force: bool = False, session_aware: bool = False) -> None:
23652364
if (not force) and self.session._executor._is_trivially_executable(self.expr):
23662365
return
23672366
elif session_aware:
2368-
bfet_roots = [obj._block._expr.node for obj in self.session.objects]
2369-
self.session._executor._cache_with_session_awareness(
2370-
self.expr, session_forest=bfet_roots
2371-
)
2367+
self.session._executor._cache_with_session_awareness(self.expr)
23722368
else:
23732369
self.session._executor._cache_with_cluster_cols(
23742370
self.expr, cluster_cols=self.index_columns

bigframes/core/validations.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def enforce_ordered(
6666
object: HasSession, opname: str, suggestion: Optional[str] = None
6767
) -> None:
6868
session = object._session
69-
if session._strictly_ordered or not object._block.expr.node.order_ambiguous:
69+
if session._strictly_ordered or not object._block.expr.order_ambiguous:
7070
# No ambiguity for how to calculate ordering, so no error or warning
7171
return None
7272
if not session._allows_ambiguity:

bigframes/session/executor.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from __future__ import annotations
1616

1717
import math
18-
from typing import cast, Iterable, Literal, Mapping, Optional, Sequence, Tuple, Union
18+
from typing import cast, Literal, Mapping, Optional, Sequence, Tuple, Union
1919
import warnings
2020
import weakref
2121

@@ -381,8 +381,8 @@ def _cache_with_offsets(self, array_value: bigframes.core.ArrayValue):
381381
def _cache_with_session_awareness(
382382
self,
383383
array_value: bigframes.core.ArrayValue,
384-
session_forest: Iterable[nodes.BigFrameNode],
385384
) -> None:
385+
session_forest = [obj._block._expr.node for obj in array_value.session.objects]
386386
# These node types are cheap to re-compute
387387
target, cluster_cols = bigframes.session.planner.session_aware_cache_plan(
388388
array_value.node, list(session_forest)

0 commit comments

Comments
 (0)