Skip to content

Commit 413df3b

Browse files
gforsythcpcloud
authored andcommitted
fix(impala): fix lstrip, rstrip, strip
1 parent 3f5a304 commit 413df3b

File tree

5 files changed

+11
-18
lines changed

5 files changed

+11
-18
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
SELECT
2-
LTRIM(`t0`.`string_col`) AS `LStrip(string_col)`
2+
LTRIM(`t0`.`string_col`, ' \t\n\r\v\f') AS `LStrip(string_col)`
33
FROM `functional_alltypes` AS `t0`
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
SELECT
2-
RTRIM(`t0`.`string_col`) AS `RStrip(string_col)`
2+
RTRIM(`t0`.`string_col`, ' \t\n\r\v\f') AS `RStrip(string_col)`
33
FROM `functional_alltypes` AS `t0`
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
SELECT
2-
TRIM(`t0`.`string_col`) AS `Strip(string_col)`
2+
RTRIM(LTRIM(`t0`.`string_col`, ' \t\n\r\v\f'), ' \t\n\r\v\f') AS `Strip(string_col)`
33
FROM `functional_alltypes` AS `t0`

ibis/backends/sql/compilers/impala.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,7 @@ class ImpalaCompiler(SQLGlotCompiler):
6060
ops.DayOfWeekName: "dayname",
6161
ops.ExtractEpochSeconds: "unix_timestamp",
6262
ops.Hash: "fnv_hash",
63-
ops.LStrip: "ltrim",
6463
ops.Ln: "ln",
65-
ops.RStrip: "rtrim",
66-
ops.Strip: "trim",
6764
ops.TypeOf: "typeof",
6865
}
6966

@@ -324,5 +321,11 @@ def visit_DateDelta(self, op, *, left, right, part):
324321
)
325322
return self.f.datediff(left, right)
326323

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

328331
compiler = ImpalaCompiler()

ibis/backends/tests/test_string.py

+2-12
Original file line numberDiff line numberDiff line change
@@ -1265,7 +1265,7 @@ def string_temp_table(backend, con):
12651265
id="lstrip",
12661266
marks=[
12671267
pytest.mark.notimpl(
1268-
["impala", "pyspark"],
1268+
["pyspark"],
12691269
raises=AssertionError,
12701270
reason="doesn't strip newline or tabs",
12711271
),
@@ -1282,7 +1282,7 @@ def string_temp_table(backend, con):
12821282
id="rstrip",
12831283
marks=[
12841284
pytest.mark.notimpl(
1285-
["impala", "pyspark"],
1285+
["pyspark"],
12861286
raises=AssertionError,
12871287
reason="doesn't strip newline or tabs",
12881288
),
@@ -1298,16 +1298,6 @@ def string_temp_table(backend, con):
12981298
lambda t: t.str.strip(),
12991299
id="strip",
13001300
marks=[
1301-
pytest.mark.notimpl(
1302-
["impala"],
1303-
raises=AssertionError,
1304-
reason="""
1305-
not stripping anything but space
1306-
can use
1307-
TRIM(TRAILING '\t\n\r ' FROM string_col)
1308-
TRIM(LEADING '\t\n\r ' FROM string_col)
1309-
""",
1310-
),
13111301
pytest.mark.notimpl(
13121302
["flink"],
13131303
raises=AssertionError,

0 commit comments

Comments
 (0)