Skip to content

Commit

Permalink
fix(impala): fix lstrip, rstrip, strip
Browse files Browse the repository at this point in the history
  • Loading branch information
gforsyth authored and cpcloud committed Sep 6, 2024
1 parent 3f5a304 commit 413df3b
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
SELECT
LTRIM(`t0`.`string_col`) AS `LStrip(string_col)`
LTRIM(`t0`.`string_col`, ' \t\n\r\v\f') AS `LStrip(string_col)`
FROM `functional_alltypes` AS `t0`
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
SELECT
RTRIM(`t0`.`string_col`) AS `RStrip(string_col)`
RTRIM(`t0`.`string_col`, ' \t\n\r\v\f') AS `RStrip(string_col)`
FROM `functional_alltypes` AS `t0`
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
SELECT
TRIM(`t0`.`string_col`) AS `Strip(string_col)`
RTRIM(LTRIM(`t0`.`string_col`, ' \t\n\r\v\f'), ' \t\n\r\v\f') AS `Strip(string_col)`
FROM `functional_alltypes` AS `t0`
9 changes: 6 additions & 3 deletions ibis/backends/sql/compilers/impala.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,7 @@ class ImpalaCompiler(SQLGlotCompiler):
ops.DayOfWeekName: "dayname",
ops.ExtractEpochSeconds: "unix_timestamp",
ops.Hash: "fnv_hash",
ops.LStrip: "ltrim",
ops.Ln: "ln",
ops.RStrip: "rtrim",
ops.Strip: "trim",
ops.TypeOf: "typeof",
}

Expand Down Expand Up @@ -324,5 +321,11 @@ def visit_DateDelta(self, op, *, left, right, part):
)
return self.f.datediff(left, right)

def visit_Strip(self, op, *, arg):
# Impala's `TRIM` doesn't allow specifying characters to trim off, unlike
# Impala's `RTRIM` and `LTRIM` which accept a set of characters to
# remove.
return self.visit_RStrip(op, arg=self.visit_LStrip(op, arg=arg))


compiler = ImpalaCompiler()
14 changes: 2 additions & 12 deletions ibis/backends/tests/test_string.py
Original file line number Diff line number Diff line change
Expand Up @@ -1265,7 +1265,7 @@ def string_temp_table(backend, con):
id="lstrip",
marks=[
pytest.mark.notimpl(
["impala", "pyspark"],
["pyspark"],
raises=AssertionError,
reason="doesn't strip newline or tabs",
),
Expand All @@ -1282,7 +1282,7 @@ def string_temp_table(backend, con):
id="rstrip",
marks=[
pytest.mark.notimpl(
["impala", "pyspark"],
["pyspark"],
raises=AssertionError,
reason="doesn't strip newline or tabs",
),
Expand All @@ -1298,16 +1298,6 @@ def string_temp_table(backend, con):
lambda t: t.str.strip(),
id="strip",
marks=[
pytest.mark.notimpl(
["impala"],
raises=AssertionError,
reason="""
not stripping anything but space
can use
TRIM(TRAILING '\t\n\r ' FROM string_col)
TRIM(LEADING '\t\n\r ' FROM string_col)
""",
),
pytest.mark.notimpl(
["flink"],
raises=AssertionError,
Expand Down

0 comments on commit 413df3b

Please sign in to comment.