Skip to content

Commit 077859b

Browse files
authored
fix: add missing interval_day derivation expression (#175)
The `_evaluate()` function in `derivation_expression.py` now returns `Type(interval_day=Type.IntervalDay(...))` instead of raising an exception. Fixes: #174 Signed-off-by: Thomas Gschwind <thg@zurich.ibm.com>
1 parent 1e34f42 commit 077859b

2 files changed

Lines changed: 23 additions & 0 deletions

File tree

src/substrait/derivation_expression.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,16 @@ def _evaluate(x, values: dict):
148148
nullability=nullability,
149149
)
150150
)
151+
elif isinstance(
152+
parametrized_type, SubstraitTypeParser.PrecisionIntervalDayContext
153+
):
154+
precision = _evaluate(parametrized_type.precision, values)
155+
return Type(
156+
interval_day=Type.IntervalDay(
157+
precision=precision,
158+
nullability=nullability,
159+
)
160+
)
151161
elif isinstance(parametrized_type, SubstraitTypeParser.StructContext):
152162
types = list(
153163
map(lambda x: _evaluate(x, values), parametrized_type.expr())

tests/test_derivation_expression.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,19 @@ def func(P1, S1, P2, S2):
116116
)
117117

118118

119+
def test_interval_day():
120+
assert evaluate("interval_day<6>") == Type(
121+
interval_day=Type.IntervalDay(
122+
precision=6, nullability=Type.NULLABILITY_REQUIRED
123+
)
124+
)
125+
assert evaluate("interval_day?<3>") == Type(
126+
interval_day=Type.IntervalDay(
127+
precision=3, nullability=Type.NULLABILITY_NULLABLE
128+
)
129+
)
130+
131+
119132
def test_struct_simple():
120133
"""Test simple struct with two i32 fields."""
121134
result = evaluate("struct<i32, i32>", {})

0 commit comments

Comments
 (0)