Skip to content

Commit 4b6ff7a

Browse files
committed
case support in sa render
1 parent 67e1db2 commit 4b6ff7a

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

mindsdb_sql/render/sqlalchemy_render.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,12 +279,26 @@ def to_expression(self, t):
279279
elif isinstance(t, ast.NotExists):
280280
sub_stmt = self.prepare_select(t.query)
281281
col = ~sub_stmt.exists()
282+
elif isinstance(t, ast.Case):
283+
col = self.prepare_case(t)
282284
else:
283285
# some other complex object?
284286
raise NotImplementedError(f'Column {t}')
285287

286288
return col
287289

290+
def prepare_case(self, t: ast.Case):
291+
conditions = []
292+
for condition, result in t.rules:
293+
conditions.append(
294+
(self.to_expression(condition), self.to_expression(result))
295+
)
296+
else_ = None
297+
if t.default is not None:
298+
else_ = self.to_expression(t.default)
299+
300+
return sa.case(conditions, else_=else_)
301+
288302
def to_function(self, t):
289303
op = getattr(sa.func, t.op)
290304
if t.from_arg is not None:

0 commit comments

Comments
 (0)