Skip to content

Commit 4c74ddd

Browse files
authored
fix(athena): only replace commas instead of all special characters in column names (#11138)
1 parent 4bb0b78 commit 4c74ddd

File tree

5 files changed

+16
-14
lines changed

5 files changed

+16
-14
lines changed

ibis/backends/athena/tests/test_client.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import pytest
44

5+
import ibis
56
from ibis.backends.tests.errors import PyAthenaOperationalError
67
from ibis.util import gen_name
78

@@ -28,3 +29,14 @@ def test_create_and_drop_database(con):
2829
# drop it again (should fail)
2930
with pytest.raises(PyAthenaOperationalError):
3031
con.drop_database(name)
32+
33+
34+
def test_column_name_with_slash(con):
35+
table = ibis.memtable({"inventarnr_/_mde_dummy": [1, 2, 3]})
36+
37+
renamed_table = con.execute(
38+
table.select("inventarnr_/_mde_dummy")
39+
.rename({"dummy": "inventarnr_/_mde_dummy"})
40+
.dummy
41+
)
42+
assert set(renamed_table.values) == {1, 2, 3}

ibis/backends/sql/compilers/athena.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
11
from __future__ import annotations
22

3-
import re
4-
53
from sqlglot.dialects import Athena
64

75
import ibis.expr.datatypes as dt
86
import ibis.expr.operations as ops
97
from ibis.backends.sql.compilers.trino import TrinoCompiler
108
from ibis.backends.sql.datatypes import AthenaType
119

12-
_NAME_REGEX = re.compile(r'[^!"$()*,./;?@[\\\]^`{}~\n]+')
13-
1410

1511
class AthenaCompiler(TrinoCompiler):
1612
__slots__ = ()
@@ -35,7 +31,7 @@ class AthenaCompiler(TrinoCompiler):
3531

3632
@staticmethod
3733
def _gen_valid_name(name: str) -> str:
38-
return "_".join(map(str.strip, _NAME_REGEX.findall(name))) or "tmp"
34+
return name.replace(",", ";")
3935

4036
def visit_Cast(self, op, *, arg, to):
4137
from_ = op.arg.dtype

ibis/backends/tests/snapshots/test_sql/test_isin_bug/athena/out.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ SELECT
55
FROM "t" AS "t0"
66
WHERE
77
"t0"."x" > 2
8-
) AS "InSubquery_x"
8+
) AS "InSubquery(x)"
99
FROM "t" AS "t0"

ibis/backends/tests/snapshots/test_sql/test_to_sql_default_backend/athena/to_sql.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
SELECT
2-
COUNT(*) AS "CountStar"
2+
COUNT(*) AS "CountStar()"
33
FROM (
44
SELECT
55
*

ibis/backends/tests/test_temporal.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1765,13 +1765,8 @@ def test_timestamp_extract_milliseconds_with_big_value(con):
17651765
assert result == 333
17661766

17671767

1768-
@pytest.mark.notimpl(
1769-
["oracle"],
1770-
raises=OracleDatabaseError,
1771-
reason="ORA-00932",
1772-
)
1768+
@pytest.mark.notimpl(["oracle"], raises=OracleDatabaseError, reason="ORA-00932")
17731769
@pytest.mark.notimpl(["exasol"], raises=ExaQueryError)
1774-
@pytest.mark.notimpl(["athena"], raises=PyAthenaOperationalError)
17751770
def test_integer_cast_to_timestamp_column(backend, alltypes, df):
17761771
expr = alltypes.int_col.cast("timestamp")
17771772
expected = pd.to_datetime(df.int_col, unit="s").rename(expr.get_name())
@@ -1781,7 +1776,6 @@ def test_integer_cast_to_timestamp_column(backend, alltypes, df):
17811776

17821777
@pytest.mark.notimpl(["exasol"], raises=ExaQueryError)
17831778
@pytest.mark.notimpl(["oracle"], raises=OracleDatabaseError)
1784-
@pytest.mark.notimpl(["athena"], raises=PyAthenaOperationalError)
17851779
def test_integer_cast_to_timestamp_scalar(alltypes, df):
17861780
expr = alltypes.int_col.min().cast("timestamp")
17871781
result = expr.execute()

0 commit comments

Comments
 (0)