Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
04d4ee92
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
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看板
未验证
提交
04d4ee92
编写于
2月 23, 2023
作者:
H
Hui Li
提交者:
GitHub
2月 23, 2023
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #20105 from taosdata/test/TD-21965-3.0
test: add tag index basic function verify case
上级
c7c37e04
bc8b82ec
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
215 addition
and
0 deletion
+215
-0
tests/parallel_test/cases.task
tests/parallel_test/cases.task
+1
-0
tests/system-test/0-others/tag_index_basic.py
tests/system-test/0-others/tag_index_basic.py
+214
-0
未找到文件。
tests/parallel_test/cases.task
浏览文件 @
04d4ee92
...
...
@@ -429,6 +429,7 @@
,,y,system-test,./pytest.sh python3 ./test.py -f 0-others/user_manage.py
,,y,system-test,./pytest.sh python3 ./test.py -f 0-others/fsync.py
,,n,system-test,python3 ./test.py -f 0-others/compatibility.py
,,n,system-test,python3 ./test.py -f 0-others/tag_index_basic.py
,,y,system-test,./pytest.sh python3 ./test.py -f 1-insert/alter_database.py
,,y,system-test,./pytest.sh python3 ./test.py -f 1-insert/influxdb_line_taosc_insert.py
,,y,system-test,./pytest.sh python3 ./test.py -f 1-insert/opentsdb_telnet_line_taosc_insert.py
...
...
tests/system-test/0-others/tag_index_basic.py
0 → 100644
浏览文件 @
04d4ee92
###################################################################
# Copyright (c) 2016 by TAOS Technologies, Inc.
# All rights reserved.
#
# This file is proprietary and confidential to TAOS Technologies.
# No part of this file may be reproduced, stored, transmitted,
# disclosed or used in any form or by any means other than as
# expressly provided by the written permission from Jianhui Tao
#
###################################################################
# -*- coding: utf-8 -*-
from
util.log
import
*
from
util.cases
import
*
from
util.sql
import
*
from
util.common
import
*
from
util.sqlset
import
*
import
random
class
TDTestCase
:
def
init
(
self
,
conn
,
logSql
,
replicaVar
=
1
):
self
.
replicaVar
=
int
(
replicaVar
)
tdLog
.
debug
(
"start to execute %s"
%
__file__
)
tdSql
.
init
(
conn
.
cursor
())
self
.
setsql
=
TDSetSql
()
self
.
column_dict
=
{
'ts'
:
'timestamp'
,
'col1'
:
'tinyint'
,
'col2'
:
'smallint'
,
'col3'
:
'int'
,
'col4'
:
'bigint'
,
'col5'
:
'tinyint unsigned'
,
'col6'
:
'smallint unsigned'
,
'col7'
:
'int unsigned'
,
'col8'
:
'bigint unsigned'
,
'col9'
:
'float'
,
'col10'
:
'double'
,
'col11'
:
'bool'
,
'col12'
:
'varchar(20)'
,
'col13'
:
'nchar(20)'
}
self
.
tag_dict
=
{
't1'
:
'tinyint'
,
't2'
:
'smallint'
,
't3'
:
'int'
,
't4'
:
'bigint'
,
't5'
:
'tinyint unsigned'
,
't6'
:
'smallint unsigned'
,
't7'
:
'int unsigned'
,
't8'
:
'bigint unsigned'
,
't9'
:
'float'
,
't10'
:
'double'
,
't11'
:
'bool'
,
't12'
:
'varchar(20)'
,
't13'
:
'nchar(20)'
,
't14'
:
'timestamp'
}
def
set_stb_sql
(
self
,
stbname
,
column_dict
,
tag_dict
):
column_sql
=
''
tag_sql
=
''
for
k
,
v
in
column_dict
.
items
():
column_sql
+=
f
"
{
k
}
{
v
}
, "
for
k
,
v
in
tag_dict
.
items
():
tag_sql
+=
f
"
{
k
}
{
v
}
, "
create_stb_sql
=
f
'create stable
{
stbname
}
(
{
column_sql
[:
-
2
]
}
) tags (
{
tag_sql
[:
-
2
]
}
)'
return
create_stb_sql
# create stable and child tables
def
create_table
(
self
,
stbname
,
tbname
,
count
):
tdSql
.
prepare
()
tdSql
.
execute
(
'use db'
)
# create stable
create_table_sql
=
self
.
set_stb_sql
(
stbname
,
self
.
column_dict
,
self
.
tag_dict
)
tdSql
.
execute
(
create_table_sql
)
# create child table
for
i
in
range
(
count
):
ti
=
i
%
128
tags
=
f
'
{
ti
}
,
{
ti
}
,
{
i
}
,
{
i
}
,
{
ti
}
,
{
ti
}
,
{
i
}
,
{
i
}
,
{
i
}
.000
{
i
}
,
{
i
}
.000
{
i
}
,true,"var
{
i
}
","nch
{
i
}
",now'
sql
=
f
'create table
{
tbname
}{
i
}
using
{
stbname
}
tags(
{
tags
}
)'
tdSql
.
execute
(
sql
)
tdLog
.
info
(
f
" create
{
count
}
child tables ok."
)
# create stable and child tables
def
create_tagidx
(
self
,
stbname
):
cnt
=
-
1
for
key
in
self
.
tag_dict
.
keys
():
# first tag have default index, so skip
if
cnt
==
-
1
:
cnt
=
0
continue
;
sql
=
f
'create index idx_
{
key
}
on
{
stbname
}
(
{
key
}
)'
tdLog
.
info
(
f
" sql=
{
sql
}
"
)
tdSql
.
execute
(
sql
)
cnt
+=
1
tdLog
.
info
(
f
' create
{
cnt
}
tag indexs ok.'
)
# insert to child table d1 data
def
insert_data
(
self
,
tbname
):
# d1 insert 3 rows
for
i
in
range
(
3
):
sql
=
f
'insert into
{
tbname
}
1(ts,col1) values(now,
{
i
}
);'
tdSql
.
execute
(
sql
)
# d20 insert 4
for
i
in
range
(
4
):
sql
=
f
'insert into
{
tbname
}
20(ts,col1) values(now,
{
i
}
);'
tdSql
.
execute
(
sql
)
# check show indexs
def
show_tagidx
(
self
,
stbname
):
sql
=
f
'select index_name,column_name from information_schema.ins_indexes where db_name="db"'
tdSql
.
query
(
sql
)
rows
=
len
(
self
.
tag_dict
.
keys
())
-
1
tdSql
.
checkRows
(
rows
)
for
i
in
range
(
rows
):
col_name
=
tdSql
.
getData
(
i
,
1
)
idx_name
=
f
'idx_
{
col_name
}
'
tdSql
.
checkData
(
i
,
0
,
idx_name
)
tdLog
.
info
(
f
' show
{
rows
}
tag indexs ok.'
)
# query with tag idx
def
query_tagidx
(
self
,
stbname
):
sql
=
f
'select * from meters where t1=1'
tdSql
.
query
(
sql
)
tdSql
.
checkRows
(
3
)
sql
=
f
'select * from meters where t2<10'
tdSql
.
query
(
sql
)
tdSql
.
checkRows
(
3
)
sql
=
f
'select * from meters where t2>10'
tdSql
.
query
(
sql
)
tdSql
.
checkRows
(
4
)
sql
=
f
'select * from meters where t3<30'
tdSql
.
query
(
sql
)
tdSql
.
checkRows
(
7
)
sql
=
f
'select * from meters where t12="11"'
tdSql
.
query
(
sql
)
tdSql
.
checkRows
(
0
)
sql
=
f
'select * from meters where (t4 < 10 or t5 = 20) and t6= 30'
tdSql
.
query
(
sql
)
tdSql
.
checkRows
(
0
)
sql
=
f
'select * from meters where (t7 < 20 and t8 = 20) or t4 = 20'
tdSql
.
query
(
sql
)
tdSql
.
checkRows
(
4
)
# drop child table
def
drop_tables
(
self
,
tbname
,
count
):
# table d1 and d20 have verify data , so can not drop
start
=
random
.
randint
(
21
,
count
/
2
)
end
=
random
.
randint
(
count
/
2
+
1
,
count
-
1
)
for
i
in
range
(
start
,
end
):
sql
=
f
'drop table
{
tbname
}{
i
}
'
tdSql
.
execute
(
sql
)
cnt
=
end
-
start
+
1
tdLog
.
info
(
f
' drop table from
{
start
}
to
{
end
}
count=
{
cnt
}
'
)
# drop tag index
def
drop_tagidx
(
self
,
stbname
):
# drop index
cnt
=
-
1
for
key
in
self
.
tag_dict
.
keys
():
# first tag have default index, so skip
if
cnt
==
-
1
:
cnt
=
0
continue
;
sql
=
f
'drop index idx_
{
key
}
'
tdSql
.
execute
(
sql
)
cnt
+=
1
# check idx result is 0
sql
=
f
'select index_name,column_name from information_schema.ins_indexes where db_name="db"'
tdSql
.
query
(
sql
)
tdSql
.
checkRows
(
0
)
tdLog
.
info
(
f
' drop
{
cnt
}
tag indexs ok.'
)
# run
def
run
(
self
):
# var
stable
=
"meters"
tbname
=
"d"
count
=
1000
# do
self
.
create_table
(
stable
,
tbname
,
count
)
self
.
create_tagidx
(
stable
)
self
.
insert_data
(
tbname
)
self
.
show_tagidx
(
stable
)
self
.
query_tagidx
(
stable
)
self
.
drop_tables
(
tbname
,
count
)
self
.
drop_tagidx
(
stable
)
# query after delete , expect no crash
self
.
query_tagidx
(
stable
)
def
stop
(
self
):
tdSql
.
close
()
tdLog
.
success
(
"%s successfully executed"
%
__file__
)
tdCases
.
addWindows
(
__file__
,
TDTestCase
())
tdCases
.
addLinux
(
__file__
,
TDTestCase
())
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录