Skip to content

Commit

Permalink
feat(mssql): add lpad and rpad ops
Browse files Browse the repository at this point in the history
  • Loading branch information
IndexSeek committed Sep 9, 2024
1 parent 422d361 commit 7c128db
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 14 deletions.
14 changes: 12 additions & 2 deletions ibis/backends/sql/compilers/mssql.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ class MSSQLCompiler(SQLGlotCompiler):
ops.IntervalFloorDivide,
ops.IsInf,
ops.IsNan,
ops.LPad,
ops.Levenshtein,
ops.Map,
ops.Median,
Expand All @@ -106,7 +105,6 @@ class MSSQLCompiler(SQLGlotCompiler):
ops.RegexSearch,
ops.RegexSplit,
ops.RowID,
ops.RPad,
ops.StringSplit,
ops.StringToDate,
ops.StringToTimestamp,
Expand Down Expand Up @@ -526,5 +524,17 @@ def visit_StartsWith(self, op, *, arg, start):
def visit_EndsWith(self, op, *, arg, end):
return arg.like(self.f.concat("%", end))

def visit_LPad(self, op, *, arg, length, pad=" "):
return self.f.left(
self.f.right(
self.f.concat(self.f.replicate(pad, length - self.f.length(arg)), arg),
length + self.f.length(arg),
),
length,
)

def visit_RPad(self, op, *, arg, length, pad=" "):
return self.f.left(self.f.concat(arg, self.f.replicate(pad, length)), length)


compiler = MSSQLCompiler()
10 changes: 0 additions & 10 deletions ibis/backends/tests/test_string.py
Original file line number Diff line number Diff line change
Expand Up @@ -417,13 +417,11 @@ def uses_java_re(t):
lambda t: t.string_col.lpad(10, "a"),
lambda t: t.string_col.str.pad(10, fillchar="a", side="left"),
id="lpad",
marks=pytest.mark.notimpl(["mssql"], raises=com.OperationNotDefinedError),
),
param(
lambda t: t.string_col.rpad(10, "a"),
lambda t: t.string_col.str.pad(10, fillchar="a", side="right"),
id="rpad",
marks=pytest.mark.notimpl(["mssql"], raises=com.OperationNotDefinedError),
),
param(
lambda t: t.string_col.find_in_set(["1"]),
Expand Down Expand Up @@ -1105,10 +1103,6 @@ def string_temp_table(backend, con):
lambda t: t.str[:4].str.pad(4, side="right", fillchar="-"),
id="rpad",
marks=[
pytest.mark.notimpl(
["mssql"],
raises=com.OperationNotDefinedError,
),
pytest.mark.notyet(
["flink", "oracle"],
raises=AssertionError,
Expand Down Expand Up @@ -1136,10 +1130,6 @@ def string_temp_table(backend, con):
lambda t: t.str[:4].str.pad(4, side="left", fillchar="-"),
id="lpad",
marks=[
pytest.mark.notimpl(
["mssql"],
raises=com.OperationNotDefinedError,
),
pytest.mark.notyet(
["flink", "oracle"],
raises=AssertionError,
Expand Down
2 changes: 0 additions & 2 deletions ibis/backends/tests/test_temporal.py
Original file line number Diff line number Diff line change
Expand Up @@ -1734,7 +1734,6 @@ def test_date_scalar_from_iso(con):
assert result.strftime("%Y-%m-%d") == "2022-02-24"


@pytest.mark.notimpl(["mssql"], raises=com.OperationNotDefinedError)
@pytest.mark.notimpl(["exasol"], raises=AssertionError, strict=False)
def test_date_column_from_iso(backend, con, alltypes, df):
expr = (
Expand Down Expand Up @@ -1821,7 +1820,6 @@ def build_date_col(t):
).cast("date")


@pytest.mark.notimpl(["mssql"], raises=com.OperationNotDefinedError)
@pytest.mark.notimpl(["druid"], raises=PyDruidProgrammingError)
@pytest.mark.parametrize(
("left_fn", "right_fn"),
Expand Down

0 comments on commit 7c128db

Please sign in to comment.