Skip to content

Commit e59b5ae

Browse files
authored
Merge pull request #247 from taosdata/feat/TD-25871
Feat/td 25871
2 parents 433377c + 7cfc954 commit e59b5ae

13 files changed

+376
-29
lines changed

.github/workflows/mac.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,8 @@ jobs:
196196
#----------------------------------------------
197197
- name: Install dependencies
198198
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
199-
run: poetry install --no-interaction --no-root
199+
run: |
200+
poetry install --no-interaction --no-root
200201
201202
#----------------------------------------------
202203
# install your root project, if required

.github/workflows/test-ubuntu-2204.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ jobs:
168168
uses: codecov/codecov-action@v3
169169
with:
170170
files: coverage.xml
171-
fail_ci_if_error: true
171+
fail_ci_if_error: false
172172

173173
- name: Build Artifacts
174174
run: |

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ packages = [
1818
"taosws" = "taos.sqlalchemy:TaosWsDialect"
1919

2020
[tool.poetry.dependencies]
21-
python = ">=3.6.2,<4.0"
21+
python = ">=3.6.2,<3.12"
2222
pytz = "*"
2323
iso8601 = "1.0.2"
2424
requests = ">=2.27.1"

taos/bind.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ def double(self, values):
374374
self.num = len(values)
375375
self.is_null = cast((c_char * len(values))(*[1 if value is None else 0 for value in values]), c_char_p)
376376

377-
def _str_to_buffer(self, values):
377+
def _str_to_buffer(self, values, encode=True):
378378
self.num = len(values)
379379
is_null = [1 if v is None else 0 for v in values]
380380
self.is_null = cast((c_byte * self.num)(*is_null), c_char_p)
@@ -392,7 +392,12 @@ def _str_to_buffer(self, values):
392392
buffer_all = b"".join(v[:] for v in buffers)
393393
self.buffer = cast(c_char_p(buffer_all), c_void_p)
394394
else:
395-
_bytes = [value.encode("utf-8") if value is not None else None for value in values]
395+
_bytes = []
396+
if encode:
397+
_bytes = [value.encode("utf-8") if value is not None else None for value in values]
398+
else:
399+
_bytes = [bytes(value) if value is not None else None for value in values]
400+
396401
buffer_length = max(len(b) for b in _bytes if b is not None)
397402
self.buffer = cast(
398403
c_char_p(
@@ -523,6 +528,18 @@ def varchar(self, values):
523528
self.buffer_type = FieldType.C_VARCHAR
524529
self._str_to_buffer(values)
525530

531+
def varbinary(self, values):
532+
if type(values) is not tuple and type(values) is not list:
533+
values = tuple([values])
534+
self.buffer_type = FieldType.C_VARBINARY
535+
self._str_to_buffer(values, False)
536+
537+
def geometry(self, values):
538+
if type(values) is not tuple and type(values) is not list:
539+
values = tuple([values])
540+
self.buffer_type = FieldType.C_GEOMETRY
541+
self._str_to_buffer(values, False)
542+
526543

527544
def new_bind_param():
528545
# type: () -> TaosBind

taos/cinterface.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,7 @@ def taos_fetch_block_v3(result, fields=None, field_count=None, decode_binary=Tru
534534
raise DatabaseError("Invalid data type returned from database")
535535
offsets = []
536536
is_null = []
537-
if fields[i]["type"] in (FieldType.C_VARCHAR, FieldType.C_NCHAR, FieldType.C_JSON, FieldType.C_VARBINARY):
537+
if fields[i]["type"] in (FieldType.C_VARCHAR, FieldType.C_NCHAR, FieldType.C_JSON, FieldType.C_VARBINARY, FieldType.C_GEOMETRY):
538538
offsets = taos_get_column_data_offset(result, i, num_of_rows)
539539
f = convert_block_func_v3(fields[i]["type"], decode_binary=decode_binary)
540540
blocks[i] = f(data, is_null, num_of_rows, offsets, precision)

taos/constants.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ class FieldType(object):
2828
C_BIGINT_UNSIGNED = 14
2929
C_JSON = 15
3030
C_VARBINARY = 16
31+
C_GEOMETRY = 20
3132
# NULL value definition
3233
# NOTE: These values should change according to C definition in tsdb.h
3334
C_BOOL_NULL = 0x02

taos/field.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,7 @@ def convert_block_func(field_type: FieldType, decode_binary=True):
283283
FieldType.C_BIGINT_UNSIGNED: _crow_bigint_unsigned_to_python,
284284
FieldType.C_JSON: _crow_nchar_to_python,
285285
FieldType.C_VARBINARY: _crow_varbinary_to_python,
286+
FieldType.C_GEOMETRY: _crow_varbinary_to_python,
286287
}
287288

288289
CONVERT_FUNC_BLOCK = {
@@ -302,6 +303,7 @@ def convert_block_func(field_type: FieldType, decode_binary=True):
302303
FieldType.C_BIGINT_UNSIGNED: _crow_bigint_unsigned_to_python,
303304
FieldType.C_JSON: _crow_nchar_to_python_block,
304305
FieldType.C_VARBINARY: _crow_varbinary_to_python_block,
306+
FieldType.C_GEOMETRY: _crow_varbinary_to_python_block,
305307
}
306308

307309

taos/field_v3.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ def convert_block_func_v3(field_type: FieldType, decode_binary=True):
6262
FieldType.C_NCHAR: _crow_nchar_to_python_block_v3,
6363
FieldType.C_JSON: _crow_nchar_to_python_block_v3,
6464
FieldType.C_VARBINARY: _crow_varbinary_to_python_block_v3,
65+
FieldType.C_GEOMETRY: _crow_varbinary_to_python_block_v3,
6566
}
6667

6768

taos/tmq.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ def value(self):
125125

126126
block_data = ctypes.cast(block, ctypes.POINTER(ctypes.c_void_p))[i]
127127
if fields[i]["type"] in (
128-
FieldType.C_VARCHAR, FieldType.C_NCHAR, FieldType.C_JSON, FieldType.C_VARBINARY):
128+
FieldType.C_VARCHAR, FieldType.C_NCHAR, FieldType.C_JSON, FieldType.C_VARBINARY, FieldType.C_GEOMETRY):
129129
f = convert_block_func_v3(fields[i]["type"], self.decode_binary)
130130
offsets = taos_get_column_data_offset(self.msg, i, num_rows)
131131
blocks[i] = f(block_data, [], num_rows, offsets, precision)

tests/test_query.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,15 +108,15 @@ def test_varbinary():
108108
conn.execute("create database if not exists test_varbinary_py")
109109
conn.execute("use test_varbinary_py")
110110
conn.execute(
111-
"create stable if not exists stb1 (ts timestamp, v1 int, v2 varchar(50), v3 varbinary(50)) tags(t1 int)"
111+
"create stable if not exists stb1 (ts timestamp, v1 int, v2 varchar(50), v3 varbinary(50), v4 geometry(512)) tags(t1 int)"
112112
)
113113
conn.execute(
114-
"insert into tb1 using stb1 tags(1) values(now, 1, 'varchar\\x8f4e3e', '\\x8f4e3e') "
115-
"(now + 1s, 2, 'varchar value 2', 'binary value_1')"
114+
"insert into tb1 using stb1 tags(1) values(now, 1, 'varchar\\x8f4e3e', '\\x8f4e3e', 'POINT (4.0 8.0)') "
115+
"(now + 1s, 2, 'varchar value 2', 'binary value_1', 'POINT (3.0 5.0)')"
116116
)
117117
conn.execute(
118-
"insert into tb2 using stb1 tags(2) values(now, 1, 'varchar value 3', '\\x8f4e3e') "
119-
"(now + 1s, 2, 'varchar value 4', 'binary value_2')"
118+
"insert into tb2 using stb1 tags(2) values(now, 1, 'varchar value 3', '\\x8f4e3e', 'LINESTRING (1.000000 1.000000, 2.000000 2.000000, 5.000000 5.000000)') "
119+
"(now + 1s, 2, 'varchar value 4', 'binary value_2', 'POLYGON ((3.000000 6.000000, 5.000000 6.000000, 5.000000 8.000000, 3.000000 8.000000, 3.000000 6.000000))')"
120120
)
121121
result = conn.query("select * from stb1")
122122

tests/test_stmt.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,4 +286,4 @@ def test_stmt_null(conn):
286286
test_stmt_insert(connect())
287287
test_stmt_insert_multi(connect())
288288
test_stmt_set_tbname_tag(connect())
289-
test_stmt_null(connect())
289+
test_stmt_null(connect())

0 commit comments

Comments
 (0)