4paradigm / 4paradigm/OpenMLDB
After inserting data with precompiled SQL, when queried, certain fields have additional null characters ('\x00') appended at the end
- Ngôn ngữ chính
- C++
- Star
- 1.7k
- Fork
- 331
- Merge trung bình
- 12 ngày 12 giờ
- Pull request đã merge (30 ngày)
- 1
Mô tả
**Bug Description**
Service Version: Code from the main branch after version 0.8.4, compiled and deployed on macOS 13.5.1.
Client Version: The current project branch python-sdk, accessing the database using the dbapi method.
After inserting data with precompiled SQL, when queried, certain fields have additional null characters ('\x00') appended at the end, as shown in the fourth column:
`
[(1001, '2022-05-01', 'province1', 'city1\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00', 1, 1590738991000),
(1002, '2022-05-02', 'province2', 'city2\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00', 2, 1590738992000),
(1003, '2022-05-03', 'province3', 'city3\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00', 3, 1590738993000),
(1004, '2022-05-04', 'province0', 'city4\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00', 4, 1590738994000)]
`
**Expected Behavior**
The field contents should not have additional null characters appended and should match the inserted content.
**Relation Case**
**Steps to Reproduce**
1. Use the python-sdk code from the main branch after version 0.8.4.
2. Run the test cases below to reproduce the corresponding error.
```
import sys
import os
from openmldb.dbapi import connect
import pytest
from .case_conf import OpenMLDB_ZK_CLUSTER, OpenMLDB_ZK_PATH
class TestOpenmldbDBAPI:
cursor_without_db = None
cursor = None
db_name = "dbapi_test"
@classmethod
def setup_class(cls):
# connect without db to create it
db = connect(zk=OpenMLDB_ZK_CLUSTER, zkPath=OpenMLDB_ZK_PATH)
cls.cursor_without_db = db.cursor()
cls.cursor_without_db.execute(
f"create database if not exists {cls.db_name};")
# then we can use the db to connect
db = connect(database=cls.db_name,
zk=OpenMLDB_ZK_CLUSTER,
zkPath=OpenMLDB_ZK_PATH)
cls.cursor = db.cursor()
cls.cursor.execute("create database if not exists {};".format(cls.db_name))
assert cls.db_name in cls.cursor.get_databases()
def recreate_table(self, table, schema):
if table in self.cursor.get_tables(self.db_name):
self.cursor.execute("drop table {}".format(table))
assert table not in self.cursor.get_tables(self.db_name)
self.cursor.execute("create table {}({}) OPTIONS(partitionnum=1);".format(table, schema))
assert table in self.cursor.get_tables(self.db_name)
def test_more_parameterized_query(self):
table = "test_param_query"
schema_str = "col1 bigint, col2 date, col3 string, col4 string, col5 int, col6 timestamp, " \
"index(key=col3, ts=col1), index(key=col3, ts=col6)"
self.recreate_table(table, schema_str)
test_rows = [(1000 + i, '2022-05-0' + str(i), 'province' + str(i % 4),
'city' + str(i), i, (1590738990 + i) * 1000)
for i in range(1, 5)]
self.cursor.executemany('insert into {} values (?, ?, ?, ?, ?, ?);'.format(table), test_rows)
result = self.cursor.execute("select * from {};".format(table)).fetchall()
result = sorted(list(result), key=lambda x: x[0])
assert result == test_rows
if __name__ == "__main__":
sys.exit(pytest.main(["-vv", os.path.abspath(__file__)]))
```
Hướng dẫn đóng góp
Hướng nghiên cứu
Issue bao gồm một test case Python bị lỗi, thực hiện chèn và truy vấn dữ liệu thông qua OpenMLDB Python SDK. Trước tiên, hãy chạy test được cung cấp để tái hiện việc đệm bằng ký tự null. Kiểm tra cách database engine C++ xử lý các trường string trong SQL được biên dịch trước, đặc biệt là logic cấp phát bộ nhớ và đệm. Kiểm tra layer dbapi của Python SDK để tìm các vấn đề về mã hóa/giải mã string. Mục tiêu là đảm bảo các string được trả về mà không có thêm ký tự null.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- python, sql
- Lĩnh vực
- backend-api-design, databases, machine-learning
- Loại issue
- Lỗi
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức phù hợp với người mới
- 45/100