Skip to content

Commit

Permalink
feat: fix ifthen and switch visitor
Browse files Browse the repository at this point in the history
  • Loading branch information
EpsilonPrime committed May 30, 2024
1 parent 308cef6 commit d71f923
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 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
11 changes: 9 additions & 2 deletions src/gateway/converter/substrait_plan_visitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ def visit_record(self, record: algebra_pb2.Expression.MultiOrList.Record) -> Any
def visit_if_value(self, if_clause: algebra_pb2.Expression.SwitchExpression.IfValue) -> Any:
"""Visits an if value."""
if if_clause.HasField('if'):
self.visit_expression(getattr(if_clause, 'if'))
self.visit_literal(getattr(if_clause, 'if'))
if if_clause.HasField('then'):
self.visit_expression(if_clause.then)

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 d71f923

Please sign in to comment.