Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(mssql): add lpad and rpad ops #10060

Merged
merged 3 commits into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 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,23 @@ 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 sge.Case(
ifs=[self.if_(length <= self.f.length(arg), arg)],
default=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(
self.f.concat(arg, self.f.replicate(pad, length - self.f.length(arg))),
length,
),
)
IndexSeek marked this conversation as resolved.
Show resolved Hide resolved


compiler = MSSQLCompiler()
14 changes: 2 additions & 12 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 All @@ -1120,7 +1114,7 @@ def string_temp_table(backend, con):
reason="Treats len(🐍) == 4, len(Éé) == 4",
),
pytest.mark.notyet(
["dask", "pandas", "polars"],
["dask", "mssql", "pandas", "polars"],
raises=AssertionError,
reason="Python style padding, e.g. doesn't trim strings to pad-length",
),
Expand All @@ -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 All @@ -1151,7 +1141,7 @@ def string_temp_table(backend, con):
reason="Treats len(🐍) == 4, len(Éé) == 4",
),
pytest.mark.notyet(
["dask", "pandas", "polars"],
["dask", "mssql", "pandas", "polars"],
raises=AssertionError,
reason="Python style padding, e.g. doesn't trim strings to pad-length",
),
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