Skip to content

Commit

Permalink
case support in sa render
Browse files Browse the repository at this point in the history
  • Loading branch information
ea-rus committed Sep 20, 2024
1 parent 67e1db2 commit 4b6ff7a
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions mindsdb_sql/render/sqlalchemy_render.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,12 +279,26 @@ def to_expression(self, t):
elif isinstance(t, ast.NotExists):
sub_stmt = self.prepare_select(t.query)
col = ~sub_stmt.exists()
elif isinstance(t, ast.Case):
col = self.prepare_case(t)
else:
# some other complex object?
raise NotImplementedError(f'Column {t}')

return col

def prepare_case(self, t: ast.Case):
conditions = []
for condition, result in t.rules:
conditions.append(
(self.to_expression(condition), self.to_expression(result))
)
else_ = None
if t.default is not None:
else_ = self.to_expression(t.default)

return sa.case(conditions, else_=else_)

def to_function(self, t):
op = getattr(sa.func, t.op)
if t.from_arg is not None:
Expand Down

0 comments on commit 4b6ff7a

Please sign in to comment.