Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
d95ec693
T
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1187
Star
22018
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看板
提交
d95ec693
编写于
5月 31, 2022
作者:
wmmhello
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat:add new logic for new tag format
上级
f89ce48e
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
31 addition
and
27 deletion
+31
-27
include/common/tdataformat.h
include/common/tdataformat.h
+2
-2
source/common/src/tdataformat.c
source/common/src/tdataformat.c
+3
-0
source/libs/parser/inc/parUtil.h
source/libs/parser/inc/parUtil.h
+1
-1
source/libs/parser/src/parInsert.c
source/libs/parser/src/parInsert.c
+7
-9
source/libs/parser/src/parTranslater.c
source/libs/parser/src/parTranslater.c
+5
-6
source/libs/parser/src/parUtil.c
source/libs/parser/src/parUtil.c
+11
-5
source/libs/scalar/test/scalar/scalarTests.cpp
source/libs/scalar/test/scalar/scalarTests.cpp
+2
-4
未找到文件。
include/common/tdataformat.h
浏览文件 @
d95ec693
...
...
@@ -136,8 +136,8 @@ struct STagVal {
};
#pragma pack(push, 1)
#define TD_TAG_JSON ((int8_t)0x
8
0) // distinguish JSON string and JSON value with the highest bit
#define TD_TAG_LARGE ((int8_t)0x
4
0)
#define TD_TAG_JSON ((int8_t)0x
4
0) // distinguish JSON string and JSON value with the highest bit
#define TD_TAG_LARGE ((int8_t)0x
2
0)
struct
STag
{
int8_t
flags
;
int16_t
len
;
...
...
source/common/src/tdataformat.c
浏览文件 @
d95ec693
...
...
@@ -567,6 +567,9 @@ static void debugPrintTagVal(int8_t type, const void *val, int32_t vlen, const c
case
TSDB_DATA_TYPE_UBIGINT
:
printf
(
"%s:%d type:%d vlen:%d, val:%"
PRIu64
"
\n
"
,
tag
,
ln
,
(
int32_t
)
type
,
vlen
,
*
(
uint64_t
*
)
val
);
break
;
case
TSDB_DATA_TYPE_NULL
:
printf
(
"%s:%d type:%d vlen:%d, val:%"
PRIi8
"
\n
"
,
tag
,
ln
,
(
int32_t
)
type
,
vlen
,
*
(
int8_t
*
)
val
);
break
;
default:
ASSERT
(
0
);
break
;
...
...
source/libs/parser/inc/parUtil.h
浏览文件 @
d95ec693
...
...
@@ -55,7 +55,7 @@ int32_t getNumOfColumns(const STableMeta* pTableMeta);
int32_t
getNumOfTags
(
const
STableMeta
*
pTableMeta
);
STableComInfo
getTableInfo
(
const
STableMeta
*
pTableMeta
);
STableMeta
*
tableMetaDup
(
const
STableMeta
*
pTableMeta
);
int32_t
parseJsontoTagData
(
const
char
*
json
,
SArray
*
pTagVals
,
S
MsgBuf
*
errMsg
);
int32_t
parseJsontoTagData
(
const
char
*
json
,
SArray
*
pTagVals
,
S
Tag
**
ppTag
,
SMsgBuf
*
pMsgBuf
);
int32_t
trimString
(
const
char
*
src
,
int32_t
len
,
char
*
dst
,
int32_t
dlen
);
...
...
source/libs/parser/src/parInsert.c
浏览文件 @
d95ec693
...
...
@@ -959,6 +959,7 @@ static int32_t parseTagsClause(SInsertParseContext* pCxt, SSchema* pSchema, uint
SToken
sToken
;
bool
isParseBindParam
=
false
;
bool
isJson
=
false
;
STag
*
pTag
=
NULL
;
for
(
int
i
=
0
;
i
<
pCxt
->
tags
.
numOfBound
;
++
i
)
{
NEXT_TOKEN_WITH_PREV
(
pCxt
->
pSql
,
sToken
);
...
...
@@ -990,7 +991,7 @@ static int32_t parseTagsClause(SInsertParseContext* pCxt, SSchema* pSchema, uint
taosMemoryFree
(
tmpTokenBuf
);
goto
end
;
}
code
=
parseJsontoTagData
(
sToken
.
z
,
pTagVals
,
&
pCxt
->
msg
);
code
=
parseJsontoTagData
(
sToken
.
z
,
pTagVals
,
&
p
Tag
,
&
p
Cxt
->
msg
);
taosMemoryFree
(
tmpTokenBuf
);
if
(
code
!=
TSDB_CODE_SUCCESS
){
goto
end
;
...
...
@@ -1015,9 +1016,7 @@ static int32_t parseTagsClause(SInsertParseContext* pCxt, SSchema* pSchema, uint
goto
end
;
}
STag
*
pTag
=
NULL
;
code
=
tTagNew
(
pTagVals
,
1
,
isJson
,
&
pTag
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
if
(
!
isJson
&&
(
code
=
tTagNew
(
pTagVals
,
1
,
false
,
&
pTag
))
!=
TSDB_CODE_SUCCESS
)
{
goto
end
;
}
...
...
@@ -1528,6 +1527,8 @@ int32_t qBindStmtTagsValue(void* pBlock, void* boundTags, int64_t suid, char* tN
SSchema
*
pSchema
=
pDataBlock
->
pTableMeta
->
schema
;
bool
isJson
=
false
;
STag
*
pTag
=
NULL
;
for
(
int
c
=
0
;
c
<
tags
->
numOfBound
;
++
c
)
{
if
(
bind
[
c
].
is_null
&&
bind
[
c
].
is_null
[
0
])
{
continue
;
...
...
@@ -1548,7 +1549,7 @@ int32_t qBindStmtTagsValue(void* pBlock, void* boundTags, int64_t suid, char* tN
isJson
=
true
;
char
*
tmp
=
taosMemoryCalloc
(
1
,
colLen
+
1
);
memcpy
(
tmp
,
bind
[
c
].
buffer
,
colLen
);
code
=
parseJsontoTagData
(
tmp
,
pTagArray
,
&
pBuf
);
code
=
parseJsontoTagData
(
tmp
,
pTagArray
,
&
p
Tag
,
&
p
Buf
);
taosMemoryFree
(
tmp
);
if
(
code
!=
TSDB_CODE_SUCCESS
){
goto
end
;
...
...
@@ -1586,10 +1587,7 @@ int32_t qBindStmtTagsValue(void* pBlock, void* boundTags, int64_t suid, char* tN
}
}
STag
*
pTag
=
NULL
;
if
(
0
!=
tTagNew
(
pTagArray
,
1
,
isJson
,
&
pTag
))
{
code
=
buildInvalidOperationMsg
(
&
pBuf
,
"out of memory"
);
if
(
!
isJson
&&
(
code
=
tTagNew
(
pTagArray
,
1
,
false
,
&
pTag
))
!=
TSDB_CODE_SUCCESS
)
{
goto
end
;
}
...
...
source/libs/parser/src/parTranslater.c
浏览文件 @
d95ec693
...
...
@@ -4218,7 +4218,7 @@ static int32_t buildKVRowForBindTags(STranslateContext* pCxt, SCreateSubTableCla
}
isJson
=
true
;
code
=
parseJsontoTagData
(
pVal
->
literal
,
pTagArray
,
&
pCxt
->
msgBuf
);
code
=
parseJsontoTagData
(
pVal
->
literal
,
pTagArray
,
ppTag
,
&
pCxt
->
msgBuf
);
if
(
code
!=
TSDB_CODE_SUCCESS
){
goto
end
;
}
...
...
@@ -4235,7 +4235,7 @@ static int32_t buildKVRowForBindTags(STranslateContext* pCxt, SCreateSubTableCla
}
}
code
=
tTagNew
(
pTagArray
,
1
,
isJson
,
ppTag
);
if
(
!
isJson
)
code
=
tTagNew
(
pTagArray
,
1
,
false
,
ppTag
);
end:
if
(
isJson
){
...
...
@@ -4285,7 +4285,7 @@ static int32_t buildKVRowForAllTags(STranslateContext* pCxt, SCreateSubTableClau
}
isJson
=
true
;
code
=
parseJsontoTagData
(
pVal
->
literal
,
pTagArray
,
&
pCxt
->
msgBuf
);
code
=
parseJsontoTagData
(
pVal
->
literal
,
pTagArray
,
ppTag
,
&
pCxt
->
msgBuf
);
if
(
code
!=
TSDB_CODE_SUCCESS
){
goto
end
;
}
...
...
@@ -4302,7 +4302,7 @@ static int32_t buildKVRowForAllTags(STranslateContext* pCxt, SCreateSubTableClau
}
++
index
;
}
code
=
tTagNew
(
pTagArray
,
1
,
isJson
,
ppTag
);
if
(
!
isJson
)
code
=
tTagNew
(
pTagArray
,
1
,
false
,
ppTag
);
end:
if
(
isJson
){
...
...
@@ -4580,11 +4580,10 @@ static int32_t buildUpdateTagValReq(STranslateContext* pCxt, SAlterTableStmt* pS
int32_t
code
=
TSDB_CODE_SUCCESS
;
STag
*
pTag
=
NULL
;
do
{
code
=
parseJsontoTagData
(
pStmt
->
pVal
->
literal
,
pTagVals
,
&
pCxt
->
msgBuf
);
code
=
parseJsontoTagData
(
pStmt
->
pVal
->
literal
,
pTagVals
,
&
p
Tag
,
&
p
Cxt
->
msgBuf
);
if
(
TSDB_CODE_SUCCESS
!=
code
)
{
break
;
}
code
=
tTagNew
(
pTagVals
,
1
,
true
,
&
pTag
);
}
while
(
0
);
for
(
int
i
=
0
;
i
<
taosArrayGetSize
(
pTagVals
);
++
i
)
{
STagVal
*
p
=
(
STagVal
*
)
taosArrayGet
(
pTagVals
,
i
);
...
...
source/libs/parser/src/parUtil.c
浏览文件 @
d95ec693
...
...
@@ -328,24 +328,27 @@ static bool isValidateTag(char* input) {
return
true
;
}
int32_t
parseJsontoTagData
(
const
char
*
json
,
SArray
*
pTagVals
,
SMsgBuf
*
pMsgBuf
)
{
int32_t
parseJsontoTagData
(
const
char
*
json
,
SArray
*
pTagVals
,
STag
**
ppTag
,
SMsgBuf
*
pMsgBuf
)
{
int32_t
retCode
=
TSDB_CODE_SUCCESS
;
// set json NULL data
if
(
!
json
||
strtrim
((
char
*
)
json
)
==
0
||
strcasecmp
(
json
,
TSDB_DATA_NULL_STR_L
)
==
0
)
{
return
TSDB_CODE_SUCCESS
;
retCode
=
TSDB_CODE_SUCCESS
;
goto
end
;
}
// set json real data
cJSON
*
root
=
cJSON_Parse
(
json
);
if
(
root
==
NULL
)
{
return
buildSyntaxErrMsg
(
pMsgBuf
,
"json parse error"
,
json
);
retCode
=
buildSyntaxErrMsg
(
pMsgBuf
,
"json parse error"
,
json
);
goto
end
;
}
int32_t
size
=
cJSON_GetArraySize
(
root
);
if
(
!
cJSON_IsObject
(
root
))
{
return
buildSyntaxErrMsg
(
pMsgBuf
,
"json error invalide value"
,
json
);
retCode
=
buildSyntaxErrMsg
(
pMsgBuf
,
"json error invalide value"
,
json
);
goto
end
;
}
int32_t
retCode
=
TSDB_CODE_SUCCESS
;
SHashObj
*
keyHash
=
taosHashInit
(
8
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_BINARY
),
false
,
false
);
for
(
int32_t
i
=
0
;
i
<
size
;
i
++
)
{
cJSON
*
item
=
cJSON_GetArrayItem
(
root
,
i
);
...
...
@@ -413,6 +416,9 @@ int32_t parseJsontoTagData(const char* json, SArray* pTagVals, SMsgBuf* pMsgBuf)
end:
taosHashCleanup
(
keyHash
);
if
(
retCode
==
TSDB_CODE_SUCCESS
){
tTagNew
(
pTagVals
,
1
,
true
,
ppTag
);
}
cJSON_Delete
(
root
);
return
retCode
;
}
...
...
source/libs/scalar/test/scalar/scalarTests.cpp
浏览文件 @
d95ec693
...
...
@@ -1112,9 +1112,8 @@ TEST(columnTest, json_column_arith_op) {
char
rightv
[
256
]
=
{
0
};
memcpy
(
rightv
,
rightvTmp
,
strlen
(
rightvTmp
));
SArray
*
tags
=
taosArrayInit
(
1
,
sizeof
(
STagVal
));
parseJsontoTagData
(
rightv
,
tags
,
NULL
);
STag
*
row
=
NULL
;
tTagNew
(
tags
,
1
,
true
,
&
row
);
parseJsontoTagData
(
rightv
,
tags
,
&
row
,
NULL
);
const
int32_t
len
=
8
;
EOperatorType
op
[
len
]
=
{
OP_TYPE_ADD
,
OP_TYPE_SUB
,
OP_TYPE_MULTI
,
OP_TYPE_DIV
,
...
...
@@ -1189,9 +1188,8 @@ TEST(columnTest, json_column_logic_op) {
char
rightv
[
256
]
=
{
0
};
memcpy
(
rightv
,
rightvTmp
,
strlen
(
rightvTmp
));
SArray
*
tags
=
taosArrayInit
(
1
,
sizeof
(
STagVal
));
parseJsontoTagData
(
rightv
,
tags
,
NULL
);
STag
*
row
=
NULL
;
tTagNew
(
tags
,
1
,
true
,
&
row
);
parseJsontoTagData
(
rightv
,
tags
,
&
row
,
NULL
);
const
int32_t
len
=
9
;
const
int32_t
len1
=
4
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录