Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
bae49baa
T
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22017
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看板
提交
bae49baa
编写于
6月 06, 2022
作者:
wmmhello
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix: fix error in json and add test cases for json
上级
2dc7df4c
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
50 addition
and
44 deletion
+50
-44
source/libs/parser/src/parInsert.c
source/libs/parser/src/parInsert.c
+6
-2
tests/system-test/2-query/json_tag.py
tests/system-test/2-query/json_tag.py
+43
-42
tests/system-test/fulltest.sh
tests/system-test/fulltest.sh
+1
-0
未找到文件。
source/libs/parser/src/parInsert.c
浏览文件 @
bae49baa
...
...
@@ -1006,7 +1006,7 @@ static int32_t parseTagsClause(SInsertParseContext* pCxt, SSchema* pSchema, uint
}
SSchema
*
pTagSchema
=
&
pSchema
[
pCxt
->
tags
.
boundColumns
[
i
]];
char
*
tmpTokenBuf
=
taosMemoryCalloc
(
1
,
sToken
.
n
);
// this can be optimize with parse column
char
*
tmpTokenBuf
=
taosMemoryCalloc
(
1
,
sToken
.
n
);
//
todo
this can be optimize with parse column
code
=
checkAndTrimValue
(
&
sToken
,
tmpTokenBuf
,
&
pCxt
->
msg
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
taosMemoryFree
(
tmpTokenBuf
);
...
...
@@ -1018,7 +1018,11 @@ static int32_t parseTagsClause(SInsertParseContext* pCxt, SSchema* pSchema, uint
taosMemoryFree
(
tmpTokenBuf
);
goto
end
;
}
code
=
parseJsontoTagData
(
sToken
.
z
,
pTagVals
,
&
pTag
,
&
pCxt
->
msg
);
if
(
isNullStr
(
&
sToken
))
{
code
=
tTagNew
(
pTagVals
,
1
,
true
,
&
pTag
);
}
else
{
code
=
parseJsontoTagData
(
sToken
.
z
,
pTagVals
,
&
pTag
,
&
pCxt
->
msg
);
}
taosMemoryFree
(
tmpTokenBuf
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
goto
end
;
...
...
tests/system-test/2-query/json_tag.py
浏览文件 @
bae49baa
...
...
@@ -61,6 +61,8 @@ class TDTestCase:
# 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(76)"
)
tdSql
.
error
(
"CREATE TABLE if not exists jsons1_14 using jsons1 tags(hell)"
)
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]')"
)
...
...
@@ -128,7 +130,7 @@ class TDTestCase:
tdSql
.
error
(
"select ceil(jtag) from jsons1"
)
#
# # test select normal column
tdSql
.
query
(
"select dataint from jsons1"
)
tdSql
.
query
(
"select dataint from jsons1
order by dataint
"
)
tdSql
.
checkRows
(
9
)
tdSql
.
checkData
(
1
,
0
,
1
)
...
...
@@ -137,9 +139,9 @@ class TDTestCase:
tdSql
.
checkRows
(
9
)
tdSql
.
query
(
"select jtag from jsons1"
)
tdSql
.
checkRows
(
13
)
tdSql
.
query
(
"select jtag from jsons1 where jtag is null"
)
#
tdSql.query("select jtag from jsons1 where jtag is null")
# tdSql.checkRows(5)
tdSql
.
query
(
"select jtag from jsons1 where jtag is not null"
)
#
tdSql.query("select jtag from jsons1 where jtag is not null")
# tdSql.checkRows(8)
# test jtag is NULL
...
...
@@ -259,12 +261,6 @@ class TDTestCase:
# tdSql.query("select * from jsons1 where jtag->'tag1'=null") # only json suport =null. This synatx will change later.
# tdSql.checkRows(1)
#
# # where json is null
tdSql
.
query
(
"select * from jsons1 where jtag is null"
)
# tdSql.checkRows(1)
tdSql
.
query
(
"select * from jsons1 where jtag is not null"
)
# tdSql.checkRows(8)
#
# # where json key is null
# tdSql.query("select * from jsons1 where jtag->'tag_no_exist'=3")
# tdSql.checkRows(0)
...
...
@@ -358,25 +354,28 @@ class TDTestCase:
# tdSql.checkRows(0)
#
# # test join
#
tdSql.execute("create table if not exists jsons2(ts timestamp, dataInt int, dataBool bool, dataStr nchar(50), dataStrBin binary(150)) tags(jtag json)")
#
tdSql.execute("insert into jsons2_1 using jsons2 tags('{\"tag1\":\"fff\",\"tag2\":5, \"tag3\":true}') values(1591060618000, 2, false, 'json2', '你是2')")
#
tdSql.execute("insert into jsons2_2 using jsons2 tags('{\"tag1\":5,\"tag2\":null}') values (1591060628000, 2, true, 'json2', 'sss')")
#
#
tdSql.execute("create table if not exists jsons3(ts timestamp, dataInt int, dataBool bool, dataStr nchar(50), dataStrBin binary(150)) tags(jtag json)")
#
tdSql.execute("insert into jsons3_1 using jsons3 tags('{\"tag1\":\"fff\",\"tag2\":5, \"tag3\":true}') values(1591060618000, 3, false, 'json3', '你是3')")
#
tdSql.execute("insert into jsons3_2 using jsons3 tags('{\"tag1\":5,\"tag2\":\"beijing\"}') values (1591060638000, 2, true, 'json3', 'sss')")
#
tdSql.query("select 'sss',33,a.jtag->'tag3' from jsons2 a,jsons3 b where a.ts=b.ts and a.jtag->'tag1'=b.jtag->'tag1'")
#
tdSql.checkData(0, 0, "sss")
#
tdSql.checkData(0, 2, "true")
#
#
res = tdSql.getColNameList("select 'sss',33,a.jtag->'tag3' from jsons2 a,jsons3 b where a.ts=b.ts and a.jtag->'tag1'=b.jtag->'tag1'")
#
cname_list = []
# cname_list.append("sss
")
#
cname_list.append("33")
#
cname_list.append("a.jtag->'tag3'")
#
tdSql.checkColNameList(res, cname_list)
tdSql
.
execute
(
"create table if not exists jsons2(ts timestamp, dataInt int, dataBool bool, dataStr nchar(50), dataStrBin binary(150)) tags(jtag json)"
)
tdSql
.
execute
(
"insert into jsons2_1 using jsons2 tags('{
\"
tag1
\"
:
\"
fff
\"
,
\"
tag2
\"
:5,
\"
tag3
\"
:true}') values(1591060618000, 2, false, 'json2', '你是2')"
)
tdSql
.
execute
(
"insert into jsons2_2 using jsons2 tags('{
\"
tag1
\"
:5,
\"
tag2
\"
:null}') values (1591060628000, 2, true, 'json2', 'sss')"
)
tdSql
.
execute
(
"create table if not exists jsons3(ts timestamp, dataInt int, dataBool bool, dataStr nchar(50), dataStrBin binary(150)) tags(jtag json)"
)
tdSql
.
execute
(
"insert into jsons3_1 using jsons3 tags('{
\"
tag1
\"
:
\"
fff
\"
,
\"
tag2
\"
:5,
\"
tag3
\"
:true}') values(1591060618000, 3, false, 'json3', '你是3')"
)
tdSql
.
execute
(
"insert into jsons3_2 using jsons3 tags('{
\"
tag1
\"
:5,
\"
tag2
\"
:
\"
beijing
\"
}') values (1591060638000, 2, true, 'json3', 'sss')"
)
tdSql
.
query
(
"select 'sss',33,a.jtag->'tag3' from jsons2 a,jsons3 b where a.ts=b.ts and a.jtag->'tag1'=b.jtag->'tag1'"
)
tdSql
.
checkData
(
0
,
0
,
"sss"
)
tdSql
.
checkData
(
0
,
2
,
"true"
)
res
=
tdSql
.
getColNameList
(
"select 'sss',33,a.jtag->'tag3' from jsons2 a,jsons3 b where a.ts=b.ts and a.jtag->'tag1'=b.jtag->'tag1'"
)
cname_list
=
[]
cname_list
.
append
(
"'sss'
"
)
cname_list
.
append
(
"33"
)
cname_list
.
append
(
"a.jtag->'tag3'"
)
tdSql
.
checkColNameList
(
res
,
cname_list
)
#
# test group by & order by json tag
# tdSql.error("select count(*) from jsons1 group by jtag")
# tdSql.error("select count(*) from jsons1 partition by jtag")
# tdSql.error("select count(*) from jsons1 group by jtag order by jtag")
tdSql
.
error
(
"select count(*) from jsons1 group by jtag->'tag1' order by jtag->'tag2'"
)
tdSql
.
error
(
"select count(*) from jsons1 group by jtag->'tag1' order by jtag"
)
tdSql
.
query
(
"select count(*),jtag->'tag1' from jsons1 group by jtag->'tag1' order by jtag->'tag1' desc"
)
...
...
@@ -432,14 +431,14 @@ class TDTestCase:
tdSql
.
checkData
(
10
,
1
,
'"femail"'
)
# test having
# tdSql.query("select stddev(dataint) from jsons1 group by jtag->'tag1' having stddev(dataint) > 0
")
# tdSql.checkRows(2
)
tdSql
.
query
(
"select count(*),jtag->'tag1' from jsons1 group by jtag->'tag1' having count(*) > 1
"
)
tdSql
.
checkRows
(
3
)
# subquery with json tag
tdSql
.
query
(
"select * from (select jtag, dataint from jsons1) order by dataint"
)
tdSql
.
checkRows
(
11
)
tdSql
.
checkData
(
1
,
1
,
1
)
tdSql
.
checkData
(
2
,
0
,
'{"tag1":5
,"tag2":"beijing"}'
)
tdSql
.
checkData
(
5
,
0
,
'{"tag1":false
,"tag2":"beijing"}'
)
# tdSql.query("select jtag->'tag1' from (select jtag->'tag1', dataint from jsons1)")
# tdSql.checkRows(11)
...
...
@@ -457,16 +456,18 @@ class TDTestCase:
# tdSql.checkData(1, 2, '"femail"')
#
# # union all
# tdSql.error("select jtag->'tag1' from jsons1 union all select jtag->'tag2' from jsons2")
# tdSql.error("select jtag->'tag1' from jsons1_1 union all select jtag->'tag2' from jsons2_1")
#
# tdSql.query("select jtag->'tag1' from jsons1_1 union all select jtag->'tag1' from jsons2_1")
# tdSql.checkRows(2)
# tdSql.query("select dataint,jtag->'tag1',tbname from jsons1 union all select dataint,jtag->'tag1',tbname from jsons2")
# tdSql.checkRows(13)
# tdSql.query("select dataint,jtag,tbname from jsons1 union all select dataint,jtag,tbname from jsons2")
# tdSql.checkRows(13)
#
tdSql
.
query
(
"select jtag->'tag1' from jsons1 union all select jtag->'tag2' from jsons2"
)
tdSql
.
checkRows
(
17
)
tdSql
.
query
(
"select jtag->'tag1' from jsons1_1 union all select jtag->'tag2' from jsons2_1"
)
tdSql
.
checkRows
(
2
)
tdSql
.
query
(
"select jtag->'tag1' from jsons1_1 union all select jtag->'tag1' from jsons2_1"
)
tdSql
.
checkRows
(
2
)
tdSql
.
query
(
"select dataint,jtag->'tag1',tbname from jsons1 union all select dataint,jtag->'tag1',tbname from jsons2"
)
tdSql
.
checkRows
(
13
)
tdSql
.
query
(
"select dataint,jtag,tbname from jsons1 union all select dataint,jtag,tbname from jsons2"
)
tdSql
.
checkRows
(
13
)
# #show create table
# tdSql.query("show create table jsons1")
# tdSql.checkData(0, 1, 'CREATE TABLE `jsons1` (`ts` TIMESTAMP,`dataint` INT,`databool` BOOL,`datastr` NCHAR(50),`datastrbin` BINARY(150)) TAGS (`jtag` JSON)')
...
...
@@ -528,9 +529,9 @@ class TDTestCase:
tdSql
.
execute
(
"CREATE TABLE if not exists jsons1_20 using jsons1 tags(NULL)"
)
tdSql
.
query
(
"select jtag from jsons1_20"
)
tdSql
.
checkData
(
0
,
0
,
None
)
#
tdSql.execute("insert into jsons1_21 using jsons1 tags(NULL) values(1591061628000, 11, false, '你就会','')")
#
tdSql.query("select jtag from jsons1_21")
#
tdSql.checkData(0, 0, None)
tdSql
.
execute
(
"insert into jsons1_21 using jsons1 tags(NULL) values(1591061628000, 11, false, '你就会','')"
)
tdSql
.
query
(
"select jtag from jsons1_21"
)
tdSql
.
checkData
(
0
,
0
,
None
)
#
# #test TD-12389
tdSql
.
query
(
"describe jsons1"
)
...
...
tests/system-test/fulltest.sh
浏览文件 @
bae49baa
...
...
@@ -57,6 +57,7 @@ python3 ./test.py -f 2-query/To_unixtimestamp.py
python3 ./test.py
-f
2-query/timetruncate.py
python3 ./test.py
-f
2-query/diff.py
python3 ./test.py
-f
2-query/Timediff.py
python3 ./test.py
-f
2-query/json_tag.py
python3 ./test.py
-f
2-query/top.py
python3 ./test.py
-f
2-query/bottom.py
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录