Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
2ea5bdc6
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22017
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
2ea5bdc6
编写于
12月 10, 2021
作者:
wmmhello
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
optimize code
上级
ef01cd87
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
18 addition
and
13 deletion
+18
-13
tests/develop-test/0-management/3-tag/json_tag.py
tests/develop-test/0-management/3-tag/json_tag.py
+18
-13
未找到文件。
tests/develop-test/0-management/3-tag/json_tag.py
浏览文件 @
2ea5bdc6
...
...
@@ -35,6 +35,8 @@ class TDTestCase:
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
.
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')"
)
...
...
@@ -46,6 +48,8 @@ class TDTestCase:
# 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
.
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')"
)
...
...
@@ -84,9 +88,13 @@ class TDTestCase:
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
_1 SET TAG jtag=4
"
)
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"
)
print
(
"============== STEP 3 ===== query table"
)
# test error syntax
...
...
@@ -125,18 +133,11 @@ class TDTestCase:
tdSql
.
checkRows
(
5
)
tdSql
.
query
(
"select jtag from jsons1 where jtag is not null"
)
tdSql
.
checkRows
(
8
)
# test #line 41
tdSql
.
query
(
"select jtag from jsons1_8"
)
tdSql
.
checkData
(
0
,
0
,
'{"tag1":null,"1tag$":2," ":90}'
)
# test #line 72
tdSql
.
query
(
"select jtag from jsons1_1"
)
tdSql
.
checkData
(
0
,
0
,
'{"tag1":"femail","tag2":35,"tag3":true}'
)
# test jtag is NULL
tdSql
.
query
(
"select jtag from jsons1_9"
)
tdSql
.
checkData
(
0
,
0
,
None
)
# test select json tag->'key', value is string
tdSql
.
query
(
"select jtag->'tag1' from jsons1_1"
)
tdSql
.
checkData
(
0
,
0
,
'"femail"'
)
...
...
@@ -404,10 +405,6 @@ class TDTestCase:
tdSql
.
checkData
(
7
,
0
,
11
)
tdSql
.
checkData
(
7
,
1
,
'"femail"'
)
# test having
tdSql
.
query
(
"select stddev(dataint) from jsons1 group by jtag->'tag1' having stddev(dataint) > 0"
)
tdSql
.
checkRows
(
2
)
res
=
tdSql
.
getColNameList
(
"select stddev(dataint) from jsons1 group by jsons1.jtag->'tag1'"
)
cname_list
=
[]
cname_list
.
append
(
"stddev(dataint)"
)
...
...
@@ -423,6 +420,9 @@ class TDTestCase:
tdSql
.
checkData
(
10
,
1
,
1
)
tdSql
.
checkData
(
10
,
2
,
'"femail"'
)
# test having
tdSql
.
query
(
"select stddev(dataint) from jsons1 group by jtag->'tag1' having stddev(dataint) > 0"
)
tdSql
.
checkRows
(
2
)
# subquery with json tag
tdSql
.
query
(
"select * from (select jtag, dataint from jsons1)"
)
...
...
@@ -453,7 +453,12 @@ class TDTestCase:
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)'
)
def
stop
(
self
):
tdSql
.
close
()
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录