Skip to content

Commit cd9219b

Browse files
kszucscpcloud
authored andcommitted
refactor(ir): dereference literal expressions
1 parent 9dabae0 commit cd9219b

2 files changed

Lines changed: 21 additions & 1 deletion

File tree

ibis/expr/tests/test_newrels.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,26 @@ def test_subsequent_filter():
499499
assert f2.op() == expected
500500

501501

502+
def test_project_dereferences_literal_expressions():
503+
one = ibis.literal(1)
504+
two = ibis.literal(2)
505+
four = (one + one) * two
506+
t1 = t.mutate(four=four)
507+
assert t1.op() == Project(
508+
parent=t,
509+
values={
510+
"bool_col": t.bool_col,
511+
"int_col": t.int_col,
512+
"float_col": t.float_col,
513+
"string_col": t.string_col,
514+
"four": four,
515+
},
516+
)
517+
518+
t2 = t1.select(four)
519+
assert t2.op() == Project(parent=t1, values={four.get_name(): t1.four})
520+
521+
502522
def test_project_before_and_after_filter():
503523
t1 = t.select(
504524
bool_col=~t.bool_col, int_col=t.int_col + 1, float_col=t.float_col * 3

ibis/expr/types/relations.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ def dereference_mapping(parents):
163163
while isinstance(v, ops.Field) and v not in mapping:
164164
mapping[v] = ops.Field(parent, k)
165165
v = v.rel.values.get(v.name)
166-
elif v.relations and v not in mapping:
166+
elif v not in mapping:
167167
# do not dereference literal expressions
168168
mapping[v] = ops.Field(parent, k)
169169

0 commit comments

Comments
 (0)