Skip to content

Commit 294510f

Browse files
committed
replace the field attribute by id, dtype, nullable
1 parent ef6d580 commit 294510f

File tree

3 files changed

+13
-24
lines changed

3 files changed

+13
-24
lines changed

bigframes/core/compile/polars/compiler.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ def _(
122122
self,
123123
expression: ex.ResolvedDerefOp,
124124
) -> pl.Expr:
125-
return pl.col(expression.field.id.sql)
125+
return pl.col(expression.id.sql)
126126

127127
@compile_expression.register
128128
def _(

bigframes/core/expression.py

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -432,31 +432,20 @@ def transform_children(self, t: Callable[[Expression], Expression]) -> Expressio
432432
class ResolvedDerefOp(DerefOp):
433433
"""An expression that refers to a column by ID and resolved with schema bound."""
434434

435-
field: field.Field
435+
dtype: dtypes.Dtype
436+
nullable: bool = True
436437

437-
# Re-declare 'id' from the parent to remove it from the __init__ method
438-
id: ids.ColumnId = dataclasses.field(init=False)
439-
440-
def __post_init__(self):
441-
# Initialize the parent's 'id' field after the object is created.
442-
# We must use object.__setattr__ because the dataclass is frozen.
443-
object.__setattr__(self, "id", self.field.id)
444-
445-
@property
446-
def column_references(self) -> typing.Tuple[ids.ColumnId, ...]:
447-
return (self.field.id,)
448-
449-
@property
450-
def nullable(self) -> bool:
451-
return self.field.nullable
438+
@classmethod
439+
def from_field(cls, f: field.Field):
440+
return cls(f.id, f.dtype, f.nullable)
452441

453442
@property
454443
def is_resolved(self) -> bool:
455444
return True
456445

457446
@property
458447
def output_type(self) -> dtypes.ExpressionType:
459-
return self.field.dtype
448+
return self.dtype
460449

461450
def bind_variables(
462451
self, bindings: Mapping[str, Expression], allow_partial_bindings: bool = False
@@ -469,8 +458,8 @@ def bind_refs(
469458
allow_partial_bindings: bool = False,
470459
) -> Expression:
471460
# TODO: Check if we can remove.
472-
if self.field.id in bindings.keys():
473-
return bindings[self.field.id]
461+
if self.id in bindings.keys():
462+
return bindings[self.id]
474463
return self
475464

476465

@@ -582,7 +571,9 @@ def bind_schema_fields(
582571
if expr.is_resolved:
583572
return expr
584573

585-
expr_by_id = {id: ResolvedDerefOp(field) for id, field in field_by_id.items()}
574+
expr_by_id = {
575+
id: ResolvedDerefOp.from_field(field) for id, field in field_by_id.items()
576+
}
586577
return expr.bind_refs(expr_by_id)
587578

588579

tests/unit/core/test_expression.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,7 @@ def test_deref_op_dtype_resolution():
7777

7878

7979
def test_field_ref_expr_dtype_resolution_short_circuit():
80-
expression = ex.ResolvedDerefOp(
81-
field.Field(ids.ColumnId("mycol"), dtype=dtypes.INT_DTYPE)
82-
)
80+
expression = ex.ResolvedDerefOp(id=ids.ColumnId("mycol"), dtype=dtypes.INT_DTYPE)
8381
field_bindings = _create_field_bindings({"anotherCol": dtypes.STRING_DTYPE})
8482

8583
result = ex.bind_schema_fields(expression, field_bindings)

0 commit comments

Comments
 (0)