Skip to content

Commit 2715002

Browse files
committed
add chinese col name test
1 parent e233981 commit 2715002

File tree

2 files changed

+78
-0
lines changed

2 files changed

+78
-0
lines changed

ibis-server/app/model/data_source.py

+4
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,10 @@ def get_mssql_connection(cls, info: MSSqlConnectionInfo) -> BaseBackend:
154154
def get_mysql_connection(cls, info: MySqlConnectionInfo) -> BaseBackend:
155155
ssl_context = cls._create_ssl_context(info)
156156
kwargs = {"ssl": ssl_context} if ssl_context else {}
157+
158+
# utf8mb4 is the actual charset used by MySQL for utf8
159+
kwargs.setdefault("charset", "utf8mb4")
160+
157161
if info.kwargs:
158162
kwargs.update(info.kwargs)
159163
return ibis.mysql.connect(

ibis-server/tests/routers/v2/connector/test_mysql.py

+74
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,80 @@ async def test_connection_valid_ssl_mode(client, mysql_ssl_off: MySqlContainer):
475475
assert response.text == '"8.0.40"'
476476

477477

478+
# MySQL specific chinese tests
479+
# So we dont mess up with the other tests's connection
480+
async def test_chinese_column_name_and_data(client):
481+
mysql = MySqlContainer(image="mysql:8.0.40", dialect="pymysql").start()
482+
connection_url = mysql.get_connection_url()
483+
engine = sqlalchemy.create_engine(connection_url)
484+
485+
# Create table with Chinese column name
486+
with engine.begin() as conn:
487+
conn.execute(
488+
text("""
489+
CREATE TABLE chinese_test (
490+
id INT PRIMARY KEY,
491+
`中文` VARCHAR(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci,
492+
data VARCHAR(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci
493+
)
494+
""")
495+
)
496+
497+
# Insert data with Chinese characters
498+
conn.execute(
499+
text("""
500+
INSERT INTO chinese_test (id, `中文`, data)
501+
VALUES
502+
(1, '一', '天'),
503+
(2, '二', '地'),
504+
(3, '三', '人')
505+
""")
506+
)
507+
508+
chinese_manifest = {
509+
"catalog": "my_catalog",
510+
"schema": "my_schema",
511+
"models": [
512+
{
513+
"name": "ChineseTest",
514+
"refSql": "select * from chinese_test",
515+
"columns": [
516+
{"name": "id", "expression": "id", "type": "integer"},
517+
{"name": "中文", "expression": '"中文"', "type": "varchar"},
518+
{"name": "data", "expression": "data", "type": "varchar"},
519+
],
520+
"primaryKey": "id",
521+
}
522+
],
523+
}
524+
525+
chinese_manifest_str = base64.b64encode(orjson.dumps(chinese_manifest)).decode(
526+
"utf-8"
527+
)
528+
529+
connection_info = _to_connection_info(mysql)
530+
response = await client.post(
531+
url=f"{base_url}/query",
532+
json={
533+
"connectionInfo": connection_info,
534+
"manifestStr": chinese_manifest_str,
535+
"sql": 'SELECT * FROM "ChineseTest" ORDER BY id',
536+
},
537+
)
538+
539+
assert response.status_code == 200
540+
result = response.json()
541+
542+
assert len(result["columns"]) == 3
543+
assert "中文" in result["columns"]
544+
assert len(result["data"]) == 3
545+
546+
assert result["data"][0][1] == "一"
547+
548+
conn.close()
549+
mysql.stop()
550+
551+
478552
def _to_connection_info(mysql: MySqlContainer):
479553
return {
480554
"host": mysql.get_container_host_ip(),

0 commit comments

Comments
 (0)