diff --git a/src/connector/python/taos/bind.py b/src/connector/python/taos/bind.py index 05659714ef86da3bda383bfe7d7b25403848637f..23f797dc87bdba2ff8b364a36e489df896540395 100644 --- a/src/connector/python/taos/bind.py +++ b/src/connector/python/taos/bind.py @@ -124,7 +124,7 @@ class TaosBind(ctypes.Structure): self.buffer_length = length self.length = pointer(c_size_t(self.buffer_length)) - def json(self, value): + def json_binary(self, value): buffer = None length = 0 if isinstance(value, str): @@ -134,7 +134,22 @@ class TaosBind(ctypes.Structure): else: buffer = value length = len(value) - self.buffer_type = FieldType.C_JSON + self.buffer_type = FieldType.C_JSON_BINARY + self.buffer = cast(buffer, c_void_p) + self.buffer_length = length + self.length = pointer(c_size_t(self.buffer_length)) + + def json_nchar(self, value): + buffer = None + length = 0 + if isinstance(value, str): + bytes = value.encode("utf-8") + buffer = create_string_buffer(bytes) + length = len(bytes) + else: + buffer = value + length = len(value) + self.buffer_type = FieldType.C_JSON_NCHAR self.buffer = cast(buffer, c_void_p) self.buffer_length = length self.length = pointer(c_size_t(self.buffer_length)) @@ -371,9 +386,13 @@ class TaosMultiBind(ctypes.Structure): self.buffer_type = FieldType.C_NCHAR self._str_to_buffer(values) - def json(self, values): + def json_binary(self, values): + self.buffer_type = FieldType.C_JSON_BINARY + self._str_to_buffer(values) + + def json_nchar(self, values): # type: (list[str]) -> None - self.buffer_type = FieldType.C_JSON + self.buffer_type = FieldType.C_JSON_NCHAR self._str_to_buffer(values) def tinyint_unsigned(self, values): diff --git a/src/connector/python/taos/constants.py b/src/connector/python/taos/constants.py index 34044a15fc0cd73323552f1b4b8c280d6cad5a9b..4d9591e0f347ceade47ac780271ae3b512afb59e 100644 --- a/src/connector/python/taos/constants.py +++ b/src/connector/python/taos/constants.py @@ -25,7 +25,8 @@ class FieldType(object): C_SMALLINT_UNSIGNED = 12 C_INT_UNSIGNED = 13 C_BIGINT_UNSIGNED = 14 - C_JSON = 15 + C_JSON_BINARY = 15 + C_JSON_NCHAR = 16 # NULL value definition # NOTE: These values should change according to C definition in tsdb.h C_BOOL_NULL = 0x02 diff --git a/src/connector/python/taos/cursor.py b/src/connector/python/taos/cursor.py index a8d82bea2ea188f8a08d6603dd33735ea0a0a5af..87d625fdc3713afb474050923b90d2e95d151fe9 100644 --- a/src/connector/python/taos/cursor.py +++ b/src/connector/python/taos/cursor.py @@ -188,8 +188,11 @@ class TaosCursor(object): if dataType.upper() == "NCHAR": if self._description[col][1] == FieldType.C_NCHAR: return True - if dataType.upper() == "JSON": - if self._description[col][1] == FieldType.C_JSON: + if dataType.upper() == "JSON BINARY": + if self._description[col][1] == FieldType.C_JSON_BINARY: + return True + if dataType.upper() == "JSON NCHAR": + if self._description[col][1] == FieldType.C_JSON_NCHAR: return True return False diff --git a/src/connector/python/taos/field.py b/src/connector/python/taos/field.py index 9d1799d367185e28b69f3cd1fe0bc0d0d14aa7fd..9743c44b1d1c5d72afd64fd8c15c5da1ca7fe6b4 100644 --- a/src/connector/python/taos/field.py +++ b/src/connector/python/taos/field.py @@ -207,7 +207,8 @@ CONVERT_FUNC = { FieldType.C_SMALLINT_UNSIGNED: _crow_smallint_unsigned_to_python, FieldType.C_INT_UNSIGNED: _crow_int_unsigned_to_python, FieldType.C_BIGINT_UNSIGNED: _crow_bigint_unsigned_to_python, - FieldType.C_JSON: _crow_nchar_to_python, + FieldType.C_JSON_NCHAR: _crow_nchar_to_python, + FieldType.C_JSON_BINARY: _crow_binary_to_python, } CONVERT_FUNC_BLOCK = { @@ -225,7 +226,8 @@ CONVERT_FUNC_BLOCK = { FieldType.C_SMALLINT_UNSIGNED: _crow_smallint_unsigned_to_python, FieldType.C_INT_UNSIGNED: _crow_int_unsigned_to_python, FieldType.C_BIGINT_UNSIGNED: _crow_bigint_unsigned_to_python, - FieldType.C_JSON: _crow_nchar_to_python_block, + FieldType.C_JSON_NCHAR: _crow_nchar_to_python_block, + FieldType.C_JSON_BINARY: _crow_binary_to_python_block, } # Corresponding TAOS_FIELD structure in C diff --git a/src/tsdb/src/tsdbRead.c b/src/tsdb/src/tsdbRead.c index 8500d33cf150d0494db176b1bf693dc84cf13887..f309375c8f57d3f82d1adbc223cbed9bae1768ae 100644 --- a/src/tsdb/src/tsdbRead.c +++ b/src/tsdb/src/tsdbRead.c @@ -2678,7 +2678,7 @@ static int tsdbReadRowsFromCache(STableCheckInfo* pCheckInfo, TSKEY maxKey, int static int32_t getAllTableList(STable* pSuperTable, SArray* list) { STSchema* pTagSchema = tsdbGetTableTagSchema(pSuperTable); - if(pTagSchema->numOfCols == 1 && IS_JSON_DATA_TYPE(pTagSchema->columns[0].type)){ + if(pTagSchema && pTagSchema->numOfCols == 1 && IS_JSON_DATA_TYPE(pTagSchema->columns[0].type)){ SArray** pRecord = taosHashIterate(pSuperTable->jsonKeyMap, NULL); SArray* tablist = taosArrayInit(32, sizeof(JsonMapValue)); @@ -4081,7 +4081,7 @@ static FORCE_INLINE int32_t tsdbGetJsonTagDataFromId(void *param, int32_t id, ch if (id == TSDB_TBNAME_COLUMN_INDEX) { *data = TABLE_NAME(pTable); } else { - void* jsonData = getJsonTagValue(pTable, name, strlen(name), pTable->tagSchema->columns->type); + void* jsonData = getJsonTagValue(pTable, name, strlen(name), pTable->pSuper->tagSchema->columns->type); if (jsonData != NULL) jsonData += CHAR_BYTES; // jump type *data = jsonData; }