Skip to content

Commit

Permalink
refactor(mssql): simplify lpad and rpad ops (#10085)
Browse files Browse the repository at this point in the history
## Description of changes

Simplifying the previous implementation from `sge.Case(ifs...)` per
#10060 (comment).
  • Loading branch information
IndexSeek authored Sep 10, 2024
1 parent 77af14b commit ef5d58d
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions ibis/backends/sql/compilers/mssql.py
Original file line number Diff line number Diff line change
Expand Up @@ -525,18 +525,20 @@ def visit_EndsWith(self, op, *, arg, end):
return arg.like(self.f.concat("%", end))

def visit_LPad(self, op, *, arg, length, pad):
return sge.Case(
ifs=[self.if_(length <= self.f.length(arg), arg)],
default=self.f.left(
return self.if_(
length <= self.f.length(arg),
arg,
self.f.left(
self.f.concat(self.f.replicate(pad, length - self.f.length(arg)), arg),
length,
),
)

def visit_RPad(self, op, *, arg, length, pad):
return sge.Case(
ifs=[self.if_(length <= self.f.length(arg), arg)],
default=self.f.left(
return self.if_(
length <= self.f.length(arg),
arg,
self.f.left(
self.f.concat(arg, self.f.replicate(pad, length - self.f.length(arg))),
length,
),
Expand Down

0 comments on commit ef5d58d

Please sign in to comment.