From 2d23d48f3fec44ee10322595f392660af0c5f9f2 Mon Sep 17 00:00:00 2001 From: Tyler White <50381805+IndexSeek@users.noreply.github.com> Date: Tue, 10 Sep 2024 22:53:45 +0000 Subject: [PATCH] refactor(mssql): simplify lpad and rpad ops --- ibis/backends/sql/compilers/mssql.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/ibis/backends/sql/compilers/mssql.py b/ibis/backends/sql/compilers/mssql.py index 31cba1126d38..cadc8b30cc1b 100644 --- a/ibis/backends/sql/compilers/mssql.py +++ b/ibis/backends/sql/compilers/mssql.py @@ -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, ),