Skip to content

Commit

Permalink
refactor(ir): dereference literal expressions
Browse files Browse the repository at this point in the history
  • Loading branch information
kszucs authored and cpcloud committed Apr 3, 2024
1 parent 9dabae0 commit cd9219b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
20 changes: 20 additions & 0 deletions ibis/expr/tests/test_newrels.py
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,26 @@ def test_subsequent_filter():
assert f2.op() == expected


def test_project_dereferences_literal_expressions():
one = ibis.literal(1)
two = ibis.literal(2)
four = (one + one) * two
t1 = t.mutate(four=four)
assert t1.op() == Project(
parent=t,
values={
"bool_col": t.bool_col,
"int_col": t.int_col,
"float_col": t.float_col,
"string_col": t.string_col,
"four": four,
},
)

t2 = t1.select(four)
assert t2.op() == Project(parent=t1, values={four.get_name(): t1.four})


def test_project_before_and_after_filter():
t1 = t.select(
bool_col=~t.bool_col, int_col=t.int_col + 1, float_col=t.float_col * 3
Expand Down
2 changes: 1 addition & 1 deletion ibis/expr/types/relations.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ def dereference_mapping(parents):
while isinstance(v, ops.Field) and v not in mapping:
mapping[v] = ops.Field(parent, k)
v = v.rel.values.get(v.name)
elif v.relations and v not in mapping:
elif v not in mapping:
# do not dereference literal expressions
mapping[v] = ops.Field(parent, k)

Expand Down

0 comments on commit cd9219b

Please sign in to comment.