Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
370aea26
T
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
370aea26
编写于
9月 17, 2021
作者:
wmmhello
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
TD-6129<feature> fix json encode error
上级
4af0ba9e
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
105 addition
and
5 deletion
+105
-5
src/client/inc/tscUtil.h
src/client/inc/tscUtil.h
+1
-1
src/client/src/tscSubquery.c
src/client/src/tscSubquery.c
+1
-1
src/client/src/tscUtil.c
src/client/src/tscUtil.c
+88
-0
src/common/src/ttypes.c
src/common/src/ttypes.c
+1
-1
src/kit/shell/src/shellEngine.c
src/kit/shell/src/shellEngine.c
+1
-0
src/query/src/qExecutor.c
src/query/src/qExecutor.c
+6
-1
src/tsdb/src/tsdbMeta.c
src/tsdb/src/tsdbMeta.c
+7
-1
未找到文件。
src/client/inc/tscUtil.h
浏览文件 @
370aea26
...
...
@@ -375,7 +375,7 @@ void tscRemoveCachedTableMeta(STableMetaInfo* pTableMetaInfo, uint64_t id);
char
*
cloneCurrentDBName
(
SSqlObj
*
pSql
);
int
parseJsontoTagData
(
char
*
json
,
SKVRowBuilder
*
kvRowBuilder
,
char
*
errMsg
,
int16_t
startColId
);
char
*
parseTagDatatoJson
(
void
*
p
);
#ifdef __cplusplus
}
#endif
...
...
src/client/src/tscSubquery.c
浏览文件 @
370aea26
...
...
@@ -3552,7 +3552,7 @@ TAOS_ROW doSetResultRowData(SSqlObj *pSql) {
int32_t
type
=
pInfo
->
field
.
type
;
int32_t
bytes
=
pInfo
->
field
.
bytes
;
if
(
type
!=
TSDB_DATA_TYPE_BINARY
&&
type
!=
TSDB_DATA_TYPE_NCHAR
)
{
if
(
type
!=
TSDB_DATA_TYPE_BINARY
&&
type
!=
TSDB_DATA_TYPE_NCHAR
&&
type
!=
TSDB_DATA_TYPE_JSON
)
{
pRes
->
tsrow
[
j
]
=
isNull
(
pRes
->
urow
[
i
],
type
)
?
NULL
:
pRes
->
urow
[
i
];
}
else
{
pRes
->
tsrow
[
j
]
=
isNull
(
pRes
->
urow
[
i
],
type
)
?
NULL
:
varDataVal
(
pRes
->
urow
[
i
]);
...
...
src/client/src/tscUtil.c
浏览文件 @
370aea26
...
...
@@ -712,6 +712,35 @@ static void setResRawPtrImpl(SSqlRes* pRes, SInternalField* pInfo, int32_t i, bo
p
+=
pInfo
->
field
.
bytes
;
}
memcpy
(
pRes
->
urow
[
i
],
pRes
->
buffer
[
i
],
pInfo
->
field
.
bytes
*
pRes
->
numOfRows
);
}
else
if
(
pInfo
->
field
.
type
==
TSDB_DATA_TYPE_JSON
)
{
// convert unicode to native code in a temporary buffer extra one byte for terminated symbol
char
*
buffer
=
realloc
(
pRes
->
buffer
[
i
],
pInfo
->
field
.
bytes
*
pRes
->
numOfRows
);
if
(
buffer
==
NULL
)
return
;
pRes
->
buffer
[
i
]
=
buffer
;
// string terminated char for binary data
memset
(
pRes
->
buffer
[
i
],
0
,
pInfo
->
field
.
bytes
*
pRes
->
numOfRows
);
char
*
p
=
pRes
->
urow
[
i
];
for
(
int32_t
k
=
0
;
k
<
pRes
->
numOfRows
;
++
k
)
{
char
*
dst
=
pRes
->
buffer
[
i
]
+
k
*
pInfo
->
field
.
bytes
;
if
(
isNull
(
p
,
TSDB_DATA_TYPE_NCHAR
))
{
memcpy
(
dst
,
p
,
varDataTLen
(
p
));
}
else
{
char
*
json
=
parseTagDatatoJson
(
p
);
if
(
json
){
memcpy
(
varDataVal
(
dst
),
json
,
strlen
(
json
));
varDataSetLen
(
dst
,
strlen
(
json
));
tfree
(
json
);
}
else
{
tscError
(
"construct json error"
);
}
}
p
+=
pInfo
->
field
.
bytes
;
}
memcpy
(
pRes
->
urow
[
i
],
pRes
->
buffer
[
i
],
pInfo
->
field
.
bytes
*
pRes
->
numOfRows
);
}
}
...
...
@@ -5145,6 +5174,65 @@ char* cloneCurrentDBName(SSqlObj* pSql) {
return
p
;
}
char
*
parseTagDatatoJson
(
void
*
p
){
char
*
string
=
NULL
;
cJSON
*
json
=
cJSON_CreateObject
();
if
(
json
==
NULL
)
{
goto
end
;
}
int16_t
nCols
=
kvRowNCols
(
p
);
ASSERT
(
nCols
%
2
==
1
);
char
tagJsonKey
[
TSDB_MAX_TAGS_LEN
]
=
{
0
};
for
(
int
j
=
0
;
j
<
nCols
;
++
j
)
{
SColIdx
*
pColIdx
=
kvRowColIdxAt
(
p
,
j
);
void
*
val
=
(
kvRowColVal
(
p
,
pColIdx
));
if
(
j
==
0
){
// json value is the first
int8_t
jsonVal
=
*
(
int8_t
*
)
val
;
ASSERT
(
jsonVal
==
TSDB_DATA_BINARY_PLACEHOLDER
);
continue
;
}
if
(
j
%
2
==
0
)
{
// json key
memset
(
tagJsonKey
,
0
,
TSDB_MAX_TAGS_LEN
);
int32_t
length
=
taosUcs4ToMbs
(
varDataVal
(
val
),
varDataLen
(
val
),
tagJsonKey
);
if
(
length
==
0
)
{
tscError
(
"charset:%s to %s. val:%s convert json key failed."
,
DEFAULT_UNICODE_ENCODEC
,
tsCharset
,
(
char
*
)
val
);
goto
end
;
}
}
else
{
// json value
char
tagJsonValue
[
TSDB_MAX_TAGS_LEN
]
=
{
0
};
if
(
*
(
char
*
)
val
==
cJSON_String
){
int32_t
length
=
taosUcs4ToMbs
(
varDataVal
(
val
+
CHAR_BYTES
),
varDataLen
(
val
+
CHAR_BYTES
),
tagJsonValue
);
if
(
length
==
0
)
{
tscError
(
"charset:%s to %s. val:%s convert json value failed."
,
DEFAULT_UNICODE_ENCODEC
,
tsCharset
,
(
char
*
)
val
);
goto
end
;
}
cJSON
*
value
=
cJSON_CreateString
(
tagJsonValue
);
if
(
value
==
NULL
)
{
goto
end
;
}
cJSON_AddItemToObject
(
json
,
tagJsonKey
,
value
);
}
else
if
(
*
(
char
*
)
val
==
cJSON_Number
){
double
jsonVd
=
*
(
double
*
)(
val
+
CHAR_BYTES
);
cJSON
*
value
=
cJSON_CreateNumber
(
jsonVd
);
if
(
value
==
NULL
)
{
goto
end
;
}
cJSON_AddItemToObject
(
json
,
tagJsonKey
,
value
);
}
else
{
tscError
(
"unsupportted json value"
);
}
}
}
string
=
cJSON_PrintUnformatted
(
json
);
end:
cJSON_Delete
(
json
);
return
string
;
}
int
parseJsontoTagData
(
char
*
json
,
SKVRowBuilder
*
kvRowBuilder
,
char
*
errMsg
,
int16_t
startColId
){
cJSON
*
root
=
cJSON_Parse
(
json
);
if
(
root
==
NULL
){
...
...
src/common/src/ttypes.c
浏览文件 @
370aea26
...
...
@@ -384,7 +384,7 @@ tDataTypeDescriptor tDataTypes[16] = {
{
TSDB_DATA_TYPE_USMALLINT
,
17
,
SHORT_BYTES
,
"SMALLINT UNSIGNED"
,
0
,
UINT16_MAX
,
tsCompressSmallint
,
tsDecompressSmallint
,
getStatics_u16
},
{
TSDB_DATA_TYPE_UINT
,
12
,
INT_BYTES
,
"INT UNSIGNED"
,
0
,
UINT32_MAX
,
tsCompressInt
,
tsDecompressInt
,
getStatics_u32
},
{
TSDB_DATA_TYPE_UBIGINT
,
15
,
LONG_BYTES
,
"BIGINT UNSIGNED"
,
0
,
UINT64_MAX
,
tsCompressBigint
,
tsDecompressBigint
,
getStatics_u64
},
{
TSDB_DATA_TYPE_JSON
,
4
,
CHAR_BYTES
,
"JSON"
,
INT8_MIN
,
INT8_MAX
,
tsCompressTinyint
,
tsDecompressTinyint
,
getStatics_i8
},
{
TSDB_DATA_TYPE_JSON
,
4
,
TSDB_MAX_NCHAR_LEN
,
"JSON"
,
INT8_MIN
,
TSDB_MAX_NCHAR_LEN
,
tsCompressString
,
tsDecompressString
,
getStatics_nchr
},
};
char
tTokenTypeSwitcher
[
13
]
=
{
...
...
src/kit/shell/src/shellEngine.c
浏览文件 @
370aea26
...
...
@@ -676,6 +676,7 @@ static void printField(const char* val, TAOS_FIELD* field, int width, int32_t le
break
;
case
TSDB_DATA_TYPE_BINARY
:
case
TSDB_DATA_TYPE_NCHAR
:
case
TSDB_DATA_TYPE_JSON
:
shellPrintNChar
(
val
,
length
,
width
);
break
;
case
TSDB_DATA_TYPE_TIMESTAMP
:
...
...
src/query/src/qExecutor.c
浏览文件 @
370aea26
...
...
@@ -4290,6 +4290,7 @@ static int32_t compressQueryColData(SColumnInfoData *pColRes, int32_t numOfRows,
colSize
+
COMP_OVERFLOW_BYTES
,
compressed
,
NULL
,
0
);
}
}
static
void
doCopyQueryResultToMsg
(
SQInfo
*
pQInfo
,
int32_t
numOfRows
,
char
*
data
,
int8_t
compressed
,
int32_t
*
compLen
)
{
SQueryRuntimeEnv
*
pRuntimeEnv
=
&
pQInfo
->
runtimeEnv
;
SQueryAttr
*
pQueryAttr
=
pRuntimeEnv
->
pQueryAttr
;
...
...
@@ -4312,7 +4313,7 @@ static void doCopyQueryResultToMsg(SQInfo *pQInfo, int32_t numOfRows, char *data
*
compLen
+=
compSizes
[
col
];
compSizes
[
col
]
=
htonl
(
compSizes
[
col
]);
}
else
{
memmove
(
data
,
pColRes
->
pData
,
pColRes
->
info
.
bytes
*
pRes
->
info
.
rows
);
memmove
(
data
,
pColRes
->
pData
,
pColRes
->
info
.
bytes
*
pRes
->
info
.
rows
);
// todo json
data
+=
pColRes
->
info
.
bytes
*
pRes
->
info
.
rows
;
}
}
...
...
@@ -4325,6 +4326,10 @@ static void doCopyQueryResultToMsg(SQInfo *pQInfo, int32_t numOfRows, char *data
*
compLen
+=
compSizes
[
col
];
compSizes
[
col
]
=
htonl
(
compSizes
[
col
]);
}
else
{
if
(
pColRes
->
info
.
type
==
TSDB_DATA_TYPE_JSON
){
// todo json
//pColRes->info.bytes =
}
memmove
(
data
,
pColRes
->
pData
,
pColRes
->
info
.
bytes
*
numOfRows
);
data
+=
pColRes
->
info
.
bytes
*
numOfRows
;
}
...
...
src/tsdb/src/tsdbMeta.c
浏览文件 @
370aea26
...
...
@@ -210,7 +210,13 @@ void *tsdbGetTableTagVal(const void* pTable, int32_t colId, int16_t type, int16_
return
NULL
;
// No matched tag volumn
}
char
*
val
=
tdGetKVRowValOfCol
(((
STable
*
)
pTable
)
->
tagVal
,
colId
);
char
*
val
=
NULL
;
if
(
type
==
TSDB_DATA_TYPE_JSON
){
val
=
kvRowValues
(((
STable
*
)
pTable
)
->
tagVal
);
}
else
{
val
=
tdGetKVRowValOfCol
(((
STable
*
)
pTable
)
->
tagVal
,
colId
);
}
assert
(
type
==
pCol
->
type
&&
bytes
>=
pCol
->
bytes
);
// if (val != NULL && IS_VAR_DATA_TYPE(type)) {
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录