Skip to content

Commit

Permalink
feat: fix ifthen and switch visitor (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
EpsilonPrime authored May 30, 2024
1 parent b2c0a51 commit 7bc86e8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
4 changes: 3 additions & 1 deletion src/gateway/converter/conversion_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ def arrow():

def datafusion():
"""Return standard options to connect to a Datafusion backend."""
return ConversionOptions(backend=BackendOptions(BackendEngine.DATAFUSION))
options = ConversionOptions(backend=BackendOptions(BackendEngine.DATAFUSION))
options.use_switch_expressions_where_possible = False
return options


def duck_db():
Expand Down
19 changes: 13 additions & 6 deletions src/gateway/converter/substrait_plan_visitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,12 +175,12 @@ def visit_record(self, record: algebra_pb2.Expression.MultiOrList.Record) -> Any
for field in record.fields:
self.visit_expression(field)

def visit_if_value(self, if_clause: algebra_pb2.Expression.SwitchExpression.IfValue) -> Any:
def visit_if_value(self, if_value: algebra_pb2.Expression.SwitchExpression.IfValue) -> Any:
"""Visits an if value."""
if if_clause.HasField('if'):
self.visit_expression(getattr(if_clause, 'if'))
if if_clause.HasField('then'):
self.visit_expression(if_clause.then)
if if_value.HasField('if'):
self.visit_literal(getattr(if_value, 'if'))
if if_value.HasField('then'):
self.visit_expression(if_value.then)

def visit_struct(self, structure: type_pb2.Type.Struct) -> Any:
"""Visits a struct."""
Expand Down Expand Up @@ -239,10 +239,17 @@ def visit_window_rel_function(
if function.HasField('output_type'):
self.visit_type(function.output_type)

def visit_if_clause(self, if_clause: algebra_pb2.Expression.IfThen.IfClause) -> Any:
"""Visits an if value."""
if if_clause.HasField('if'):
self.visit_expression(getattr(if_clause, 'if'))
if if_clause.HasField('then'):
self.visit_expression(if_clause.then)

def visit_if_then(self, if_then: algebra_pb2.Expression.IfThen) -> Any:
"""Visits an if then."""
for if_then_if in if_then.ifs:
self.visit_if_value(if_then_if)
self.visit_if_clause(if_then_if)
if if_then.HasField('else'):
self.visit_expression(getattr(if_then, 'else'))

Expand Down

0 comments on commit 7bc86e8

Please sign in to comment.