Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
82a659c3
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看板
提交
82a659c3
编写于
5月 23, 2022
作者:
wmmhello
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix:add json test case
上级
cf00cc38
变更
5
显示空白变更内容
内联
并排
Showing
5 changed file
with
116 addition
and
60 deletion
+116
-60
include/util/taoserror.h
include/util/taoserror.h
+1
-0
include/util/tdef.h
include/util/tdef.h
+1
-0
source/libs/parser/src/parTranslater.c
source/libs/parser/src/parTranslater.c
+54
-6
source/libs/parser/src/parUtil.c
source/libs/parser/src/parUtil.c
+7
-5
tests/system-test/2-query/json_tag.py
tests/system-test/2-query/json_tag.py
+53
-49
未找到文件。
include/util/taoserror.h
浏览文件 @
82a659c3
...
...
@@ -638,6 +638,7 @@ int32_t* taosGetErrno();
#define TSDB_CODE_PAR_NOT_ALLOWED_FUNC TAOS_DEF_ERROR_CODE(0, 0x264F)
#define TSDB_CODE_PAR_NOT_ALLOWED_WIN_QUERY TAOS_DEF_ERROR_CODE(0, 0x2650)
#define TSDB_CODE_PAR_INVALID_DROP_COL TAOS_DEF_ERROR_CODE(0, 0x2651)
#define TSDB_CODE_PAR_INVALID_COL_JSON TAOS_DEF_ERROR_CODE(0, 0x2652)
//planner
#define TSDB_CODE_PLAN_INTERNAL_ERROR TAOS_DEF_ERROR_CODE(0, 0x2700)
...
...
include/util/tdef.h
浏览文件 @
82a659c3
...
...
@@ -233,6 +233,7 @@ typedef enum ELogicConditionType {
#define TSDB_MAX_TAG_CONDITIONS 1024
#define TSDB_MAX_JSON_TAG_LEN 16384
#define TSDB_MAX_JSON_KEY_LEN 256
#define TSDB_AUTH_LEN 16
#define TSDB_PASSWORD_LEN 32
...
...
source/libs/parser/src/parTranslater.c
浏览文件 @
82a659c3
...
...
@@ -677,7 +677,6 @@ static EDealRes translateValueImpl(STranslateContext* pCxt, SValueNode* pVal, SD
varDataSetLen
(
pVal
->
datum
.
p
,
output
);
break
;
}
case
TSDB_DATA_TYPE_JSON
:
case
TSDB_DATA_TYPE_DECIMAL
:
case
TSDB_DATA_TYPE_BLOB
:
return
generateDealNodeErrMsg
(
pCxt
,
TSDB_CODE_PAR_WRONG_VALUE_TYPE
,
pVal
->
literal
);
...
...
@@ -2477,6 +2476,9 @@ static int32_t checkTableColsSchema(STranslateContext* pCxt, SHashObj* pHash, SN
code
=
generateSyntaxErrMsg
(
&
pCxt
->
msgBuf
,
TSDB_CODE_PAR_INVALID_FIRST_COLUMN
);
}
}
if
(
TSDB_CODE_SUCCESS
==
code
&&
pCol
->
dataType
.
type
==
TSDB_DATA_TYPE_JSON
)
{
code
=
generateSyntaxErrMsg
(
&
pCxt
->
msgBuf
,
TSDB_CODE_PAR_INVALID_COL_JSON
);
}
int32_t
len
=
strlen
(
pCol
->
colName
);
if
(
TSDB_CODE_SUCCESS
==
code
&&
NULL
!=
taosHashGet
(
pHash
,
pCol
->
colName
,
len
))
{
code
=
generateSyntaxErrMsg
(
&
pCxt
->
msgBuf
,
TSDB_CODE_PAR_DUPLICATED_COLUMN
);
...
...
@@ -2484,7 +2486,7 @@ static int32_t checkTableColsSchema(STranslateContext* pCxt, SHashObj* pHash, SN
if
(
TSDB_CODE_SUCCESS
==
code
)
{
if
((
TSDB_DATA_TYPE_VARCHAR
==
pCol
->
dataType
.
type
&&
calcTypeBytes
(
pCol
->
dataType
)
>
TSDB_MAX_BINARY_LEN
)
||
(
TSDB_DATA_TYPE_NCHAR
==
pCol
->
dataType
.
type
&&
calcTypeBytes
(
pCol
->
dataType
)
>
TSDB_MAX_NCHAR_LEN
))
{
code
=
code
=
generateSyntaxErrMsg
(
&
pCxt
->
msgBuf
,
TSDB_CODE_PAR_INVALID_VAR_COLUMN_LEN
);
code
=
generateSyntaxErrMsg
(
&
pCxt
->
msgBuf
,
TSDB_CODE_PAR_INVALID_VAR_COLUMN_LEN
);
}
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
...
...
@@ -4452,11 +4454,38 @@ static int32_t buildUpdateTagValReq(STranslateContext* pCxt, SAlterTableStmt* pS
}
pReq
->
isNull
=
(
TSDB_DATA_TYPE_NULL
==
pStmt
->
pVal
->
node
.
resType
.
type
);
if
(
pStmt
->
pVal
->
node
.
resType
.
type
==
TSDB_DATA_TYPE_JSON
){
SKVRowBuilder
kvRowBuilder
=
{
0
};
int32_t
code
=
tdInitKVRowBuilder
(
&
kvRowBuilder
);
if
(
TSDB_CODE_SUCCESS
!=
code
)
{
return
TSDB_CODE_OUT_OF_MEMORY
;
}
if
(
pStmt
->
pVal
->
literal
&&
strlen
(
pStmt
->
pVal
->
literal
)
>
(
TSDB_MAX_JSON_TAG_LEN
-
VARSTR_HEADER_SIZE
)
/
TSDB_NCHAR_SIZE
)
{
return
buildSyntaxErrMsg
(
&
pCxt
->
msgBuf
,
"json string too long than 4095"
,
pStmt
->
pVal
->
literal
);
}
code
=
parseJsontoTagData
(
pStmt
->
pVal
->
literal
,
&
kvRowBuilder
,
&
pCxt
->
msgBuf
,
pSchema
->
colId
);
if
(
TSDB_CODE_SUCCESS
!=
code
)
{
return
code
;
}
SKVRow
row
=
tdGetKVRowFromBuilder
(
&
kvRowBuilder
);
if
(
NULL
==
row
)
{
tdDestroyKVRowBuilder
(
&
kvRowBuilder
);
return
TSDB_CODE_OUT_OF_MEMORY
;
}
pReq
->
nTagVal
=
kvRowLen
(
row
);
pReq
->
pTagVal
=
row
;
pStmt
->
pVal
->
datum
.
p
=
row
;
// for free
tdDestroyKVRowBuilder
(
&
kvRowBuilder
);
}
else
{
pReq
->
nTagVal
=
pStmt
->
pVal
->
node
.
resType
.
bytes
;
if
(
TSDB_DATA_TYPE_NCHAR
==
pStmt
->
pVal
->
node
.
resType
.
type
)
{
pReq
->
nTagVal
=
pReq
->
nTagVal
*
TSDB_NCHAR_SIZE
;
}
pReq
->
pTagVal
=
nodesGetValueFromNode
(
pStmt
->
pVal
);
}
return
TSDB_CODE_SUCCESS
;
}
...
...
@@ -4653,6 +4682,25 @@ static int32_t rewriteAlterTable(STranslateContext* pCxt, SQuery* pQuery) {
return
code
;
}
SSchema
*
pTagsSchema
=
getTableTagSchema
(
pTableMeta
);
if
(
getNumOfTags
(
pTableMeta
)
==
1
&&
pTagsSchema
->
type
==
TSDB_DATA_TYPE_JSON
&&
(
pStmt
->
alterType
==
TSDB_ALTER_TABLE_ADD_TAG
||
pStmt
->
alterType
==
TSDB_ALTER_TABLE_DROP_TAG
||
pStmt
->
alterType
==
TSDB_ALTER_TABLE_UPDATE_TAG_BYTES
))
{
return
generateSyntaxErrMsg
(
&
pCxt
->
msgBuf
,
TSDB_CODE_PAR_ONLY_ONE_JSON_TAG
);
}
if
(
pStmt
->
dataType
.
type
==
TSDB_DATA_TYPE_JSON
&&
pStmt
->
alterType
==
TSDB_ALTER_TABLE_ADD_TAG
)
{
return
generateSyntaxErrMsg
(
&
pCxt
->
msgBuf
,
TSDB_CODE_PAR_ONLY_ONE_JSON_TAG
);
}
if
(
pStmt
->
dataType
.
type
==
TSDB_DATA_TYPE_JSON
&&
pStmt
->
alterType
==
TSDB_ALTER_TABLE_ADD_COLUMN
)
{
return
generateSyntaxErrMsg
(
&
pCxt
->
msgBuf
,
TSDB_CODE_PAR_INVALID_COL_JSON
);
}
if
(
getNumOfTags
(
pTableMeta
)
==
1
&&
pStmt
->
alterType
==
TSDB_ALTER_TABLE_DROP_TAG
)
{
return
generateSyntaxErrMsg
(
&
pCxt
->
msgBuf
,
TSDB_CODE_PAR_INVALID_ALTER_TABLE
,
"can not drop tag if there is only one tag"
);
}
if
(
TSDB_SUPER_TABLE
==
pTableMeta
->
tableType
)
{
return
TSDB_CODE_SUCCESS
;
}
else
if
(
TSDB_CHILD_TABLE
!=
pTableMeta
->
tableType
&&
TSDB_NORMAL_TABLE
!=
pTableMeta
->
tableType
)
{
...
...
source/libs/parser/src/parUtil.c
浏览文件 @
82a659c3
...
...
@@ -171,6 +171,8 @@ static char* getSyntaxErrFormat(int32_t errCode) {
return
"Window query not supported, since the result of subquery not include valid timestamp column"
;
case
TSDB_CODE_PAR_INVALID_DROP_COL
:
return
"No columns can be dropped"
;
case
TSDB_CODE_PAR_INVALID_COL_JSON
:
return
"Only tag can be json type"
;
case
TSDB_CODE_OUT_OF_MEMORY
:
return
"Out of memory"
;
default:
...
...
@@ -360,12 +362,12 @@ int parseJsontoTagData(const char* json, SKVRowBuilder* kvRowBuilder, SMsgBuf* p
retCode
=
buildSyntaxErrMsg
(
pMsgBuf
,
"json key not validate"
,
jsonKey
);
goto
end
;
}
// if(strlen(jsonKey) > TSDB_MAX_JSON_KEY_LEN){
// tscError("json key too long error");
// retCode = tscSQLSyntaxErrMsg(errMsg, "json key too long, more than 256", NULL);
// goto end;
// }
size_t
keyLen
=
strlen
(
jsonKey
);
if
(
keyLen
>
TSDB_MAX_JSON_KEY_LEN
){
qError
(
"json key too long error"
);
retCode
=
buildSyntaxErrMsg
(
pMsgBuf
,
"json key too long, more than 256"
,
jsonKey
);
goto
end
;
}
if
(
keyLen
==
0
||
taosHashGet
(
keyHash
,
jsonKey
,
keyLen
)
!=
NULL
)
{
continue
;
}
...
...
tests/system-test/2-query/json_tag.py
浏览文件 @
82a659c3
...
...
@@ -35,8 +35,8 @@ class TDTestCase:
def
run
(
self
):
tdSql
.
prepare
()
print
(
"============== STEP 1 ===== prepare data & validate json string"
)
#
tdSql.error("create table if not exists jsons1(ts timestamp, dataInt int, dataBool bool, dataStr nchar(50), dataStrBin binary(150)) tags(jtag json, tagint int)")
#
tdSql.error("create table if not exists jsons1(ts timestamp, data json) tags(tagint int)")
tdSql
.
error
(
"create table if not exists jsons1(ts timestamp, dataInt int, dataBool bool, dataStr nchar(50), dataStrBin binary(150)) tags(jtag json, tagint int)"
)
tdSql
.
error
(
"create table if not exists jsons1(ts timestamp, data json) tags(tagint int)"
)
tdSql
.
execute
(
"create table if not exists jsons1(ts timestamp, dataInt int, dataBool bool, dataStr nchar(50), dataStrBin binary(150)) tags(jtag json)"
)
tdSql
.
execute
(
"insert into jsons1_1 using jsons1 tags('{
\"
tag1
\"
:
\"
fff
\"
,
\"
tag2
\"
:5,
\"
tag3
\"
:true}') values(1591060618000, 1, false, 'json1', '你是') (1591060608000, 23, true, '等等', 'json')"
)
tdSql
.
execute
(
"insert into jsons1_2 using jsons1 tags('{
\"
tag1
\"
:5,
\"
tag2
\"
:
\"
beijing
\"
}') values (1591060628000, 2, true, 'json2', 'sss')"
)
...
...
@@ -47,58 +47,62 @@ class TDTestCase:
tdSql
.
execute
(
"insert into jsons1_7 using jsons1 tags('{
\"
tag1
\"
:
\"
收到货
\"
,
\"
tag2
\"
:
\"\"
,
\"
tag3
\"
:null}') values(1591062628000, 2, NULL, '你就会', 'dws')"
)
# test duplicate key using the first one. elimate empty key
#
tdSql.execute("CREATE TABLE if not exists jsons1_8 using jsons1 tags('{\"tag1\":null, \"tag1\":true, \"tag1\":45, \"1tag$\":2, \" \":90, \"\":32}')")
tdSql
.
execute
(
"CREATE TABLE if not exists jsons1_8 using jsons1 tags('{
\"
tag1
\"
:null,
\"
tag1
\"
:true,
\"
tag1
\"
:45,
\"
1tag$
\"
:2,
\"
\"
:90,
\"\"
:32}')"
)
#tdSql.query("select jtag from jsons1_8")
#tdSql.checkData(0, 0, '{"tag1":null,"1tag$":2," ":90}')
#
#
test empty json string, save as jtag is NULL
#
tdSql.execute("insert into jsons1_9 using jsons1 tags('\t') values (1591062328000, 24, NULL, '你就会', '2sdw')")
#
tdSql.execute("CREATE TABLE if not exists jsons1_10 using jsons1 tags('')")
#
tdSql.execute("CREATE TABLE if not exists jsons1_11 using jsons1 tags(' ')")
#
tdSql.execute("CREATE TABLE if not exists jsons1_12 using jsons1 tags('{}')")
#
tdSql.execute("CREATE TABLE if not exists jsons1_13 using jsons1 tags('null')")
#
#
#
test invalidate json
#
tdSql.error("CREATE TABLE if not exists jsons1_14 using jsons1 tags('\"efwewf\"')")
#
tdSql.error("CREATE TABLE if not exists jsons1_14 using jsons1 tags('3333')")
#
tdSql.error("CREATE TABLE if not exists jsons1_14 using jsons1 tags('33.33')")
#
tdSql.error("CREATE TABLE if not exists jsons1_14 using jsons1 tags('false')")
#
tdSql.error("CREATE TABLE if not exists jsons1_14 using jsons1 tags('[1,true]')")
#
tdSql.error("CREATE TABLE if not exists jsons1_14 using jsons1 tags('{222}')")
#
tdSql.error("CREATE TABLE if not exists jsons1_14 using jsons1 tags('{\"fe\"}')")
#
#
#
test invalidate json key, key must can be printed assic char
#
tdSql.error("CREATE TABLE if not exists jsons1_14 using jsons1 tags('{\"tag1\":[1,true]}')")
#
tdSql.error("CREATE TABLE if not exists jsons1_14 using jsons1 tags('{\"tag1\":{}}')")
#
tdSql.error("CREATE TABLE if not exists jsons1_14 using jsons1 tags('{\"。loc\":\"fff\"}')")
#
tdSql.error("CREATE TABLE if not exists jsons1_14 using jsons1 tags('{\"\t\":\"fff\"}')")
#
tdSql.error("CREATE TABLE if not exists jsons1_14 using jsons1 tags('{\"试试\":\"fff\"}')")
#
#
#
test invalidate json value, value number can not be inf,nan TD-12166
#
tdSql.error("CREATE TABLE if not exists jsons1_14 using jsons1 tags('{\"k\":1.8e308}')")
#
tdSql.error("CREATE TABLE if not exists jsons1_14 using jsons1 tags('{\"k\":-1.8e308}')")
#
#
#
test length limit
#
char1= ''.join(['abcd']*64)
# char3= ''.join(['abcd']*1022
)
# print(len(char3)) # 4088
#
tdSql.error("CREATE TABLE if not exists jsons1_15 using jsons1 tags('{\"%s1\":5}')" % char1) # len(key)=257
#
tdSql.execute("CREATE TABLE if not exists jsons1_15 using jsons1 tags('{\"%s\":5}')" % char1) # len(key)=256
# tdSql.error("CREATE TABLE if not exists jsons1_16 using jsons1 tags('{\"TS\":\"%s\"}')" % char3) # len(object)=4097
# tdSql.execute("CREATE TABLE if not exists jsons1_16 using jsons1 tags('{\"T\":\"%s\"}')" % char3) # len(object)=4096
#
tdSql.execute("drop table if exists jsons1_15")
#
tdSql.execute("drop table if exists jsons1_16")
#
#
print("============== STEP 2 ===== alter table json tag")
#
tdSql.error("ALTER STABLE jsons1 add tag tag2 nchar(20)")
#
tdSql.error("ALTER STABLE jsons1 drop tag jtag")
#
tdSql.error("ALTER TABLE jsons1 MODIFY TAG jtag nchar(128)")
#
#
tdSql.execute("ALTER TABLE jsons1_1 SET TAG jtag='{\"tag1\":\"femail\",\"tag2\":35,\"tag3\":true}'")
# test empty json string, save as jtag is NULL
tdSql
.
execute
(
"insert into jsons1_9 using jsons1 tags('
\t
') values (1591062328000, 24, NULL, '你就会', '2sdw')"
)
tdSql
.
execute
(
"CREATE TABLE if not exists jsons1_10 using jsons1 tags('')"
)
tdSql
.
execute
(
"CREATE TABLE if not exists jsons1_11 using jsons1 tags(' ')"
)
tdSql
.
execute
(
"CREATE TABLE if not exists jsons1_12 using jsons1 tags('{}')"
)
tdSql
.
execute
(
"CREATE TABLE if not exists jsons1_13 using jsons1 tags('null')"
)
# test invalidate json
tdSql
.
error
(
"CREATE TABLE if not exists jsons1_14 using jsons1 tags('
\"
efwewf
\"
')"
)
tdSql
.
error
(
"CREATE TABLE if not exists jsons1_14 using jsons1 tags('3333')"
)
tdSql
.
error
(
"CREATE TABLE if not exists jsons1_14 using jsons1 tags('33.33')"
)
tdSql
.
error
(
"CREATE TABLE if not exists jsons1_14 using jsons1 tags('false')"
)
tdSql
.
error
(
"CREATE TABLE if not exists jsons1_14 using jsons1 tags('[1,true]')"
)
tdSql
.
error
(
"CREATE TABLE if not exists jsons1_14 using jsons1 tags('{222}')"
)
tdSql
.
error
(
"CREATE TABLE if not exists jsons1_14 using jsons1 tags('{
\"
fe
\"
}')"
)
#
# test invalidate json key, key must can be printed assic char
tdSql
.
error
(
"CREATE TABLE if not exists jsons1_14 using jsons1 tags('{
\"
tag1
\"
:[1,true]}')"
)
tdSql
.
error
(
"CREATE TABLE if not exists jsons1_14 using jsons1 tags('{
\"
tag1
\"
:{}}')"
)
tdSql
.
error
(
"CREATE TABLE if not exists jsons1_14 using jsons1 tags('{
\"
。loc
\"
:
\"
fff
\"
}')"
)
tdSql
.
error
(
"CREATE TABLE if not exists jsons1_14 using jsons1 tags('{
\"\t\"
:
\"
fff
\"
}')"
)
tdSql
.
error
(
"CREATE TABLE if not exists jsons1_14 using jsons1 tags('{
\"
试试
\"
:
\"
fff
\"
}')"
)
# test invalidate json value, value number can not be inf,nan TD-12166
tdSql
.
error
(
"CREATE TABLE if not exists jsons1_14 using jsons1 tags('{
\"
k
\"
:1.8e308}')"
)
tdSql
.
error
(
"CREATE TABLE if not exists jsons1_14 using jsons1 tags('{
\"
k
\"
:-1.8e308}')"
)
#
#test length limit
char1
=
''
.
join
([
'abcd'
]
*
64
)
char3
=
''
.
join
([
'abcd'
]
*
1021
)
print
(
len
(
char3
))
# 4084
tdSql
.
error
(
"CREATE TABLE if not exists jsons1_15 using jsons1 tags('{
\"
%s1
\"
:5}')"
%
char1
)
# len(key)=257
tdSql
.
execute
(
"CREATE TABLE if not exists jsons1_15 using jsons1 tags('{
\"
%s
\"
:5}')"
%
char1
)
# len(key)=256
tdSql
.
error
(
"CREATE TABLE if not exists jsons1_16 using jsons1 tags('{
\"
TSSSS
\"
:
\"
%s
\"
}')"
%
char3
)
# len(object)=4096
tdSql
.
execute
(
"CREATE TABLE if not exists jsons1_16 using jsons1 tags('{
\"
TSSS
\"
:
\"
%s
\"
}')"
%
char3
)
# len(object)=4095
tdSql
.
execute
(
"drop table if exists jsons1_15"
)
tdSql
.
execute
(
"drop table if exists jsons1_16"
)
#
print
(
"============== STEP 2 ===== alter table json tag"
)
tdSql
.
error
(
"ALTER STABLE jsons1 add tag tag2 nchar(20)"
)
tdSql
.
error
(
"ALTER STABLE jsons1 drop tag jtag"
)
tdSql
.
error
(
"ALTER TABLE jsons1 MODIFY TAG jtag nchar(128)"
)
#
tdSql
.
execute
(
"ALTER TABLE jsons1_1 SET TAG jtag='{
\"
tag1
\"
:
\"
femail
\"
,
\"
tag2
\"
:35,
\"
tag3
\"
:true}'"
)
# tdSql.query("select jtag from jsons1_1")
# tdSql.checkData(0, 0, '{"tag1":"femail","tag2":35,"tag3":true}')
# tdSql.execute("ALTER TABLE jsons1 CHANGE TAG jtag jtag_new")
# tdSql.execute("ALTER TABLE jsons1 CHANGE TAG jtag_new jtag")
tdSql
.
execute
(
"ALTER TABLE jsons1 rename TAG jtag jtag_new"
)
tdSql
.
execute
(
"ALTER TABLE jsons1 rename TAG jtag_new jtag"
)
tdSql
.
execute
(
"create table st(ts timestamp, i int) tags(t int)"
)
tdSql
.
error
(
"ALTER STABLE st add tag jtag json"
)
tdSql
.
error
(
"ALTER STABLE st add column jtag json"
)
#
# print("============== STEP 3 ===== query table")
# # test error syntax
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录