提交 059533b4 编写于 作者: wmmhello's avatar wmmhello

TD-6129<feature> add json nchar & json binary from python connector & fix json bug

上级 dfb7b6ee
......@@ -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):
......
......@@ -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
......
......@@ -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
......
......@@ -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
......
......@@ -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;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册