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 1 commit
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
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=" "):
cpcloud marked this conversation as resolved.
Show resolved Hide resolved
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=" "):
cpcloud marked this conversation as resolved.
Show resolved Hide resolved
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