Skip to content
This repository was archived by the owner on Jan 22, 2025. It is now read-only.

Commit 74f98e2

Browse files
authored
Merge pull request #73 from datafuselabs/fix/upload-encoding-utf8
fix: encoding uploaded stage file as utf8
2 parents dbf52a4 + b054848 commit 74f98e2

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

databend_py/uploader.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,11 @@ def _serialize_data(self, data, compress):
7272
buf = io.StringIO()
7373
csvwriter = csv.writer(buf, delimiter=',', quoting=csv.QUOTE_MINIMAL)
7474
csvwriter.writerows(data)
75-
output = buf.getvalue()
75+
output = buf.getvalue().encode('utf-8')
7676
if compress:
7777
buf = io.BytesIO()
7878
with gzip.GzipFile(fileobj=buf, mode="wb") as gzwriter:
79-
gzwriter.write(output.encode('utf-8'))
79+
gzwriter.write(output)
8080
output = buf.getvalue()
8181
if self._debug:
8282
print('upload:_serialize_data %s' % (time.time() - start_time))

tests/test_client.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,13 @@ def test_null_to_none(self):
198198
_, data = client.execute("select NULL as test")
199199
self.assertIsNone(data[0][0])
200200

201+
def test_special_chars(self):
202+
client = Client.from_url(self.databend_url)
203+
client.execute("create or replace table test_special_chars (x string)")
204+
client.execute("INSERT INTO test_special_chars (x) VALUES", [('ó')])
205+
_, data = client.execute("select * from test_special_chars")
206+
self.assertEqual(data, [('ó')])
207+
201208
def test_set_query_id_header(self):
202209
os.environ["ADDITIONAL_HEADERS"] = "X-DATABENDCLOUD-TENANT=TENANT,X-DATABENDCLOUD-WAREHOUSE=WAREHOUSE"
203210
client = Client.from_url(self.databend_url)

0 commit comments

Comments
 (0)