Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
91dc9e90
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看板
提交
91dc9e90
编写于
5月 19, 2022
作者:
wmmhello
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fea:add select json logic
上级
e818e279
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
79 addition
and
82 deletion
+79
-82
include/util/tdef.h
include/util/tdef.h
+1
-1
source/client/src/clientImpl.c
source/client/src/clientImpl.c
+48
-56
source/common/src/tdatablock.c
source/common/src/tdatablock.c
+15
-14
source/libs/executor/src/scanoperator.c
source/libs/executor/src/scanoperator.c
+9
-1
source/libs/parser/src/parUtil.c
source/libs/parser/src/parUtil.c
+5
-9
source/libs/scalar/src/sclvector.c
source/libs/scalar/src/sclvector.c
+1
-1
未找到文件。
include/util/tdef.h
浏览文件 @
91dc9e90
...
...
@@ -232,7 +232,7 @@ typedef enum ELogicConditionType {
#define TSDB_MAX_TAGS 128
#define TSDB_MAX_TAG_CONDITIONS 1024
#define TSDB_MAX_JSON_TAG_LEN
(16384 + VARSTR_HEADER_SIZE)
#define TSDB_MAX_JSON_TAG_LEN
16384
#define TSDB_AUTH_LEN 16
#define TSDB_PASSWORD_LEN 32
...
...
source/client/src/clientImpl.c
浏览文件 @
91dc9e90
...
...
@@ -23,6 +23,8 @@
#include "tmsgtype.h"
#include "tpagedbuf.h"
#include "tref.h"
#include "cJSON.h"
#include "tdataformat.h"
static
int32_t
initEpSetFromCfg
(
const
char
*
firstEp
,
const
char
*
secondEp
,
SCorEpSet
*
pEpSet
);
static
SMsgSendInfo
*
buildConnectMsg
(
SRequestObj
*
pRequest
);
...
...
@@ -745,7 +747,6 @@ static int32_t doPrepareResPtr(SReqResultInfo* pResInfo) {
return
TSDB_CODE_SUCCESS
;
}
#include "cJSON.h"
static
char
*
parseTagDatatoJson
(
void
*
p
){
char
*
string
=
NULL
;
cJSON
*
json
=
cJSON_CreateObject
();
...
...
@@ -815,14 +816,14 @@ static char* parseTagDatatoJson(void *p){
goto
end
;
}
cJSON_AddItemToObject
(
json
,
tagJsonKey
,
value
);
}
else
if
(
type
==
TSDB_DATA_TYPE_BIGINT
){
int64_t
jsonVd
=
*
(
int64_t
*
)(
realData
);
cJSON
*
value
=
cJSON_CreateNumber
((
double
)
jsonVd
);
if
(
value
==
NULL
)
{
goto
end
;
}
cJSON_AddItemToObject
(
json
,
tagJsonKey
,
value
);
//
}else if(type == TSDB_DATA_TYPE_BIGINT){
//
int64_t jsonVd = *(int64_t*)(realData);
//
cJSON* value = cJSON_CreateNumber((double)jsonVd);
//
if (value == NULL)
//
{
//
goto end;
//
}
//
cJSON_AddItemToObject(json, tagJsonKey, value);
}
else
if
(
type
==
TSDB_DATA_TYPE_BOOL
)
{
char
jsonVd
=
*
(
char
*
)(
realData
);
cJSON
*
value
=
cJSON_CreateBool
(
jsonVd
);
...
...
@@ -833,7 +834,7 @@ static char* parseTagDatatoJson(void *p){
cJSON_AddItemToObject
(
json
,
tagJsonKey
,
value
);
}
else
{
tscError
(
"unsupportted json value"
);
ASSERT
(
0
);
}
}
...
...
@@ -842,7 +843,6 @@ end:
cJSON_Delete
(
json
);
return
string
;
}
#include "tdataformat.h"
static
int32_t
doConvertUCS4
(
SReqResultInfo
*
pResultInfo
,
int32_t
numOfRows
,
int32_t
numOfCols
,
int32_t
*
colLength
)
{
for
(
int32_t
i
=
0
;
i
<
numOfCols
;
++
i
)
{
...
...
@@ -886,51 +886,43 @@ static int32_t doConvertUCS4(SReqResultInfo* pResultInfo, int32_t numOfRows, int
for
(
int32_t
j
=
0
;
j
<
numOfRows
;
++
j
)
{
if
(
pCol
->
offset
[
j
]
!=
-
1
)
{
char
*
pStart
=
pCol
->
offset
[
j
]
+
pCol
->
pData
;
char
dst
[
TSDB_MAX_JSON_TAG_LEN
]
=
{
0
};
char
*
jsonString
=
parseTagDatatoJson
(
pStart
);
STR_TO_VARSTR
(
dst
,
jsonString
);
taosMemoryFree
(
jsonString
);
// int32_t jsonInnerType = *pStart;
// char* jsonInnerData = pStart + CHAR_BYTES;
// char dst[TSDB_MAX_JSON_TAG_LEN] = {0};
// if (jsonInnerType == TSDB_DATA_TYPE_NULL) {
// sprintf(varDataVal(dst), "%s", TSDB_DATA_NULL_STR_L);
// varDataSetLen(dst, strlen(varDataVal(dst)));
// } else if (jsonInnerType == TSDB_DATA_TYPE_JSON) {
// int32_t length =
// taosUcs4ToMbs((TdUcs4*)varDataVal(jsonInnerData), varDataLen(jsonInnerData), varDataVal(dst));
//
// if (length <= 0) {
// tscError("charset:%s to %s. val:%s convert failed.", DEFAULT_UNICODE_ENCODEC, tsCharset,
// varDataVal(jsonInnerData));
// length = 0;
// }
// varDataSetLen(dst, length);
// } else if (jsonInnerType == TSDB_DATA_TYPE_NCHAR) { // value -> "value"
// *(char*)varDataVal(dst) = '\"';
// int32_t length = taosUcs4ToMbs((TdUcs4*)varDataVal(jsonInnerData), varDataLen(jsonInnerData),
// varDataVal(dst) + CHAR_BYTES);
// if (length <= 0) {
// tscError("charset:%s to %s. val:%s convert failed.", DEFAULT_UNICODE_ENCODEC, tsCharset,
// varDataVal(jsonInnerData));
// length = 0;
// }
// varDataSetLen(dst, length + CHAR_BYTES * 2);
// *(char*)(varDataVal(dst), length + CHAR_BYTES) = '\"';
// } else if (jsonInnerType == TSDB_DATA_TYPE_DOUBLE) {
// double jsonVd = *(double*)(jsonInnerData);
// sprintf(varDataVal(dst), "%.9lf", jsonVd);
// varDataSetLen(dst, strlen(varDataVal(dst)));
// } else if (jsonInnerType == TSDB_DATA_TYPE_BIGINT) {
// int64_t jsonVd = *(int64_t*)(jsonInnerData);
// sprintf(varDataVal(dst), "%" PRId64, jsonVd);
// varDataSetLen(dst, strlen(varDataVal(dst)));
// } else if (jsonInnerType == TSDB_DATA_TYPE_BOOL) {
// sprintf(varDataVal(dst), "%s", (*((char*)jsonInnerData) == 1) ? "true" : "false");
// varDataSetLen(dst, strlen(varDataVal(dst)));
// } else {
// ASSERT(0);
// }
int32_t
jsonInnerType
=
*
pStart
;
char
*
jsonInnerData
=
pStart
+
CHAR_BYTES
;
char
dst
[
TSDB_MAX_JSON_TAG_LEN
]
=
{
0
};
if
(
jsonInnerType
==
TSDB_DATA_TYPE_NULL
)
{
sprintf
(
varDataVal
(
dst
),
"%s"
,
TSDB_DATA_NULL_STR_L
);
varDataSetLen
(
dst
,
strlen
(
varDataVal
(
dst
)));
}
else
if
(
jsonInnerType
==
TSDB_DATA_TYPE_JSON
)
{
char
*
jsonString
=
parseTagDatatoJson
(
jsonInnerData
);
STR_TO_VARSTR
(
dst
,
jsonString
);
taosMemoryFree
(
jsonString
);
}
else
if
(
jsonInnerType
==
TSDB_DATA_TYPE_NCHAR
)
{
// value -> "value"
*
(
char
*
)
varDataVal
(
dst
)
=
'\"'
;
int32_t
length
=
taosUcs4ToMbs
((
TdUcs4
*
)
varDataVal
(
jsonInnerData
),
varDataLen
(
jsonInnerData
),
varDataVal
(
dst
)
+
CHAR_BYTES
);
if
(
length
<=
0
)
{
tscError
(
"charset:%s to %s. val:%s convert failed."
,
DEFAULT_UNICODE_ENCODEC
,
tsCharset
,
varDataVal
(
jsonInnerData
));
length
=
0
;
}
varDataSetLen
(
dst
,
length
+
CHAR_BYTES
*
2
);
*
(
char
*
)(
varDataVal
(
dst
),
length
+
CHAR_BYTES
)
=
'\"'
;
}
else
if
(
jsonInnerType
==
TSDB_DATA_TYPE_DOUBLE
)
{
double
jsonVd
=
*
(
double
*
)(
jsonInnerData
);
sprintf
(
varDataVal
(
dst
),
"%.9lf"
,
jsonVd
);
varDataSetLen
(
dst
,
strlen
(
varDataVal
(
dst
)));
}
else
if
(
jsonInnerType
==
TSDB_DATA_TYPE_BIGINT
)
{
int64_t
jsonVd
=
*
(
int64_t
*
)(
jsonInnerData
);
sprintf
(
varDataVal
(
dst
),
"%"
PRId64
,
jsonVd
);
varDataSetLen
(
dst
,
strlen
(
varDataVal
(
dst
)));
}
else
if
(
jsonInnerType
==
TSDB_DATA_TYPE_BOOL
)
{
sprintf
(
varDataVal
(
dst
),
"%s"
,
(
*
((
char
*
)
jsonInnerData
)
==
1
)
?
"true"
:
"false"
);
varDataSetLen
(
dst
,
strlen
(
varDataVal
(
dst
)));
}
else
{
ASSERT
(
0
);
}
if
(
len
+
varDataTLen
(
dst
)
>
colLength
[
i
])
{
p
=
taosMemoryRealloc
(
pResultInfo
->
convertBuf
[
i
],
len
+
varDataTLen
(
dst
));
...
...
source/common/src/tdatablock.c
浏览文件 @
91dc9e90
...
...
@@ -116,21 +116,22 @@ int32_t colDataAppend(SColumnInfoData* pColumnInfoData, uint32_t currentRow, con
int32_t
type
=
pColumnInfoData
->
info
.
type
;
if
(
IS_VAR_DATA_TYPE
(
type
))
{
int32_t
dataLen
=
0
;
int32_t
dataLen
=
varDataTLen
(
pData
)
;
if
(
type
==
TSDB_DATA_TYPE_JSON
)
{
// if (*pData == TSDB_DATA_TYPE_NULL) {
// dataLen = 0;
// } else if (*pData == TSDB_DATA_TYPE_NCHAR) {
// dataLen = varDataTLen(pData + CHAR_BYTES);
// } else if (*pData == TSDB_DATA_TYPE_BIGINT || *pData == TSDB_DATA_TYPE_DOUBLE) {
// dataLen = LONG_BYTES;
// } else if (*pData == TSDB_DATA_TYPE_BOOL) {
// dataLen = CHAR_BYTES;
// }
// dataLen += CHAR_BYTES;
dataLen
=
kvRowLen
(
pData
);
}
else
{
dataLen
=
varDataTLen
(
pData
);
if
(
*
pData
==
TSDB_DATA_TYPE_NULL
)
{
dataLen
=
0
;
}
else
if
(
*
pData
==
TSDB_DATA_TYPE_NCHAR
)
{
dataLen
=
varDataTLen
(
pData
+
CHAR_BYTES
);
}
else
if
(
*
pData
==
TSDB_DATA_TYPE_DOUBLE
)
{
dataLen
=
DOUBLE_BYTES
;
}
else
if
(
*
pData
==
TSDB_DATA_TYPE_BOOL
)
{
dataLen
=
CHAR_BYTES
;
}
else
if
(
*
pData
==
TSDB_DATA_TYPE_JSON
)
{
dataLen
=
kvRowLen
(
pData
+
CHAR_BYTES
);
}
else
{
ASSERT
(
0
);
}
dataLen
+=
CHAR_BYTES
;
}
SVarColAttr
*
pAttr
=
&
pColumnInfoData
->
varmeta
;
...
...
source/libs/executor/src/scanoperator.c
浏览文件 @
91dc9e90
...
...
@@ -1469,7 +1469,15 @@ static SSDataBlock* doTagScan(SOperatorInfo* pOperator) {
}
else
{
// it is a tag value
const
char
*
p
=
NULL
;
if
(
pDst
->
info
.
type
==
TSDB_DATA_TYPE_JSON
){
p
=
mr
.
me
.
ctbEntry
.
pTags
;
const
uint8_t
*
tmp
=
mr
.
me
.
ctbEntry
.
pTags
;
char
*
data
=
taosMemoryCalloc
(
kvRowLen
(
tmp
)
+
1
,
1
);
if
(
data
==
NULL
){
qError
(
"doTagScan calloc error:%d"
,
kvRowLen
(
tmp
)
+
1
);
return
NULL
;
}
*
data
=
TSDB_DATA_TYPE_JSON
;
memcpy
(
data
+
1
,
tmp
,
kvRowLen
(
tmp
));
p
=
data
;
}
else
{
p
=
metaGetTableTagVal
(
&
mr
.
me
,
pExprInfo
[
j
].
base
.
pParam
[
0
].
pCol
->
colId
);
}
...
...
source/libs/parser/src/parUtil.c
浏览文件 @
91dc9e90
...
...
@@ -356,8 +356,8 @@ int parseJsontoTagData(const char* json, SKVRowBuilder* kvRowBuilder, SMsgBuf* p
if
(
keyLen
==
0
||
taosHashGet
(
keyHash
,
jsonKey
,
keyLen
)
!=
NULL
)
{
continue
;
}
// key: keyLen + VARSTR_HEADER_SIZE, value type: CHAR_BYTES, value reserved:
LONG
_BYTES
tagKV
=
taosMemoryCalloc
(
keyLen
+
VARSTR_HEADER_SIZE
+
CHAR_BYTES
+
LONG
_BYTES
,
1
);
// key: keyLen + VARSTR_HEADER_SIZE, value type: CHAR_BYTES, value reserved:
DOUBLE
_BYTES
tagKV
=
taosMemoryCalloc
(
keyLen
+
VARSTR_HEADER_SIZE
+
CHAR_BYTES
+
DOUBLE
_BYTES
,
1
);
if
(
!
tagKV
)
{
retCode
=
TSDB_CODE_TSC_OUT_OF_MEMORY
;
goto
end
;
...
...
@@ -402,13 +402,9 @@ int parseJsontoTagData(const char* json, SKVRowBuilder* kvRowBuilder, SMsgBuf* p
}
char
*
valueType
=
POINTER_SHIFT
(
tagKV
,
keyLen
+
VARSTR_HEADER_SIZE
);
char
*
valueData
=
POINTER_SHIFT
(
tagKV
,
keyLen
+
VARSTR_HEADER_SIZE
+
CHAR_BYTES
);
*
valueType
=
(
item
->
valuedouble
-
(
int64_t
)(
item
->
valuedouble
)
==
0
)
?
TSDB_DATA_TYPE_BIGINT
:
TSDB_DATA_TYPE_DOUBLE
;
if
(
*
valueType
==
TSDB_DATA_TYPE_DOUBLE
)
*
((
double
*
)
valueData
)
=
item
->
valuedouble
;
else
if
(
*
valueType
==
TSDB_DATA_TYPE_BIGINT
)
*
((
int64_t
*
)
valueData
)
=
item
->
valueint
;
tdAddColToKVRow
(
kvRowBuilder
,
jsonIndex
++
,
tagKV
,
keyLen
+
VARSTR_HEADER_SIZE
+
CHAR_BYTES
+
LONG_BYTES
);
*
valueType
=
TSDB_DATA_TYPE_DOUBLE
;
*
((
double
*
)
valueData
)
=
item
->
valuedouble
;
tdAddColToKVRow
(
kvRowBuilder
,
jsonIndex
++
,
tagKV
,
keyLen
+
VARSTR_HEADER_SIZE
+
CHAR_BYTES
+
DOUBLE_BYTES
);
}
else
if
(
item
->
type
==
cJSON_True
||
item
->
type
==
cJSON_False
)
{
char
*
valueType
=
POINTER_SHIFT
(
tagKV
,
keyLen
+
VARSTR_HEADER_SIZE
);
char
*
valueData
=
POINTER_SHIFT
(
tagKV
,
keyLen
+
VARSTR_HEADER_SIZE
+
CHAR_BYTES
);
...
...
source/libs/scalar/src/sclvector.c
浏览文件 @
91dc9e90
...
...
@@ -922,7 +922,7 @@ static void doReleaseVec(SColumnInfoData* pCol, int32_t type) {
}
}
char
*
getJsonValue
(
char
*
json
,
char
*
key
){
//todo
char
*
getJsonValue
(
char
*
json
,
char
*
key
){
int16_t
cols
=
kvRowNCols
(
json
);
for
(
int
i
=
0
;
i
<
cols
;
++
i
)
{
SColIdx
*
pColIdx
=
kvRowColIdxAt
(
json
,
i
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录