stream.sim 6.3 KB
Newer Older
S
slguan 已提交
1
system sh/stop_dnodes.sh
S
slguan 已提交
2 3

system sh/deploy.sh -n dnode1 -i 1
H
hjxilinx 已提交
4
system sh/cfg.sh -n dnode1 -c walLevel -v 0
H
hjxilinx 已提交
5
system sh/cfg.sh -n dnode1 -c tableMetaKeepTimer -v 5
S
slguan 已提交
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
system sh/exec.sh -n dnode1 -s start
sleep 3000
sql connect
print ======================== stream.sim
sleep 2000
$db = strm_db
$tb = tb
$mt = mt
$strm = strm
$tbNum = 10
$rowNum = 20
$totalNum = 200

print =============== set up DB
$i = 0

sql drop database if exists $db
sql create database $db
sql use $db


## [TBASE300]
print ====== TBASE-300
sql create table mt (ts timestamp, c1 int, c2 int) tags(t1 int)
sql create table tb1 using mt tags(1)
sql create table tb2 using mt tags(2)
sql create table strm as select count(*), avg(c1), sum(c2), max(c1), min(c2),first(c1), last(c2) from mt interval(4s) sliding(2s)
sleep 10000
sql insert into tb2 values(now,1,1)
sql insert into tb1 values(now,1,1)
sleep 4000
sql select * from mt
sql select * from strm
sql drop table tb1
40
sleep 100000
S
slguan 已提交
41 42 43 44 45 46 47 48 49 50 51 52 53
sql select * from strm
if $rows != 2 then
  if $rows != 1 then
    return -1
  endi
endi
sql drop table tb2
sql drop table mt
sql drop table strm

## [TBASE304]
print ====== TBASE-304
sleep 10000
B
Bomin Zhang 已提交
54 55 56 57
# we cannot reset query cache in server side, as a workaround,
# set super table name to mt304, need to change back to mt later
print create mt304
sql create table mt304 (ts timestamp, c1 int) tags(t1 int, t2 int)
S
slguan 已提交
58
print create tb1
B
Bomin Zhang 已提交
59
sql create table tb1 using mt304 tags(1, 1)
S
slguan 已提交
60
print create tb2
B
Bomin Zhang 已提交
61
sql create table tb2 using mt304 tags(1, -1)
S
slguan 已提交
62
print create strm
B
Bomin Zhang 已提交
63
sql create table strm as select count(*), avg(c1) from mt304 where t2 >= 0 interval(4s) sliding(2s)
S
slguan 已提交
64 65
sql insert into tb1 values (now,1)
sql insert into tb2 values (now,2)
B
Bomin Zhang 已提交
66
sleep 100000
S
slguan 已提交
67 68 69 70 71 72 73 74 75 76 77 78
sql select * from strm;
if $rows != 2 then
  print ==== expect rows = 2, actually returned rows = $rows
  return -1
endi
if $data01 != 1 then
  return -1
endi
print data02 = $data02
if $data02 != 1.000000000 then
  return -1
endi
B
Bomin Zhang 已提交
79
sql alter table mt304 drop tag t2;
S
slguan 已提交
80 81 82
sql insert into tb2 values (now,2);
sql insert into tb1 values (now,1);
sql select * from strm;
B
Bomin Zhang 已提交
83
sql alter table mt304 add tag t2 int;
S
slguan 已提交
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
sleep 10000
sql select * from strm

print ================= create a stream with a wildcard filter on tags of a STable
sql drop database $db
sql create database $db
sql use $db
sql create table stb (ts timestamp, c1 int, c2 binary(10)) tags(t1 binary(10))
sql create table tb1 using stb tags('a1')
sql create table tb2 using stb tags('b2')
sql create table tb3 using stb tags('a3')
sql create table strm as select count(*), avg(c1), first(c2) from stb where t1 like 'a%' interval(4s) sliding(2s)
sleep 11000
sql insert into tb1 values (now, 0, 'tb1')
sleep 4000
sql insert into tb2 values (now, 2, 'tb2')
sleep 4000
sql insert into tb3 values (now, 0, 'tb3')
B
Bomin Zhang 已提交
102
sleep 60000
S
slguan 已提交
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138

sql describe strm
if $rows == 0 then
  return -1
endi

sql select * from strm
sleep 1000
print ======== data0: $data00 $data01 $data02 $data03 
print ======== data1: $data10 $data11 $data12 $data13 
print ======== data2: $data20 $data21 $data22 $data23 
print ======== data3: $data30 $data31 $data32 $data33 
if $rows != 4 then
  print ==== expect rows = 4, actually returned rows = $rows
  return -1
endi
if $data02 != 0.000000000 then
  return -1
endi
if $data03 == tb2 then
  return -1
endi
if $data13 == tb2 then
  return -1
endi
if $data23 == tb2 then
  return -1
endi
if $data33 == tb2 then
  return -1
endi

## The vnode client needs to refresh metadata cache to allow strm calculate tb4's data. But the current refreshing frequency is every 10 min
## commented out the case below to save running time
sql create table tb4 using stb tags('a4')
sql insert into tb4 values(now, 4, 'tb4')
B
Bomin Zhang 已提交
139
sleep 60000
S
slguan 已提交
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161
sql select * from strm order by ts desc
print ======== data0: $data00 $data01 $data02 $data03 
#print ======== data1: $data10 $data11 $data12 $data13 
#print ======== data2: $data20 $data21 $data22 $data23 
#print ======== data3: $data30 $data31 $data32 $data33 
if $rows != 6 then
  print ==== expect rows = 6, actually returned rows = $rows
  return -1
endi
if $data02 != 4.000000000 then
  return -1
endi
if $data03 != tb4 then
  return -1
endi

print =============== change tag values to see if stream still works correctly
sql alter table tb4 set tag t1='b4'
sleep 3000   # waiting for new tag valid
sql insert into tb1 values (now, 1, 'tb1_a1')
sleep 4000
sql insert into tb4 values (now, -4, 'tb4_b4')
B
Bomin Zhang 已提交
162
sleep 100000
S
slguan 已提交
163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192
sql select * from strm order by ts desc
sleep 1000
print ======== data0: $data00 $data01 $data02 $data03 
#print ======== data1: $data10 $data11 $data12 $data13 
#print ======== data2: $data20 $data21 $data22 $data23 
#print ======== data3: $data30 $data31 $data32 $data33 
if $rows != 8 then
  print ==== expect rows = 8, actually returned rows = $rows
  return -1
endi
if $data02 != 1.000000000 then
  return -1
endi
if $data03 != tb1_a1 then
  return -1
endi

sql drop database if exists $db
sql drop database if exists strm_db_0
sql create database strm_db_0
sql use strm_db_0

sql create table stb (ts timestamp, c1 int, c2 bigint, c3 float, c4 double, c5 binary(15), c6 nchar(15), c7 bool) tags(t1 int, t2 binary(15))
sql create table tb0 using stb tags(0, 'tb0')
sql create table tb1 using stb tags(1, 'tb1')
sql create table tb2 using stb tags(2, 'tb2')
sql create table tb3 using stb tags(3, 'tb3')
sql create table tb4 using stb tags(4, 'tb4')

sql create table strm0 as select count(ts), count(c1), max(c2), min(c4), first(c5), last(c6) from stb where ts < now + 30s interval(4s) sliding(2s)
B
Bomin Zhang 已提交
193
sleep 1000
S
slguan 已提交
194
sql insert into tb0 values (now, 0, 0, 0, 0, 'binary0', '涛思0', true) tb1 values (now, 1, 1, 1, 1, 'binary1', '涛思1', false) tb2 values (now, 2, 2, 2, 2, 'binary2', '涛思2', true) tb3 values (now, 3, 3, 3, 3, 'binary3', '涛思3', false) tb4 values (now, 4, 4, 4, 4, 'binary4', '涛思4', true) 
B
Bomin Zhang 已提交
195
sleep 20000
S
slguan 已提交
196 197 198 199 200 201 202 203
sql select * from strm0 order by ts desc
sleep 1000
if $rows != 2 then
  print ==== expect rows = 2, actually returned rows = $rows
  return -1
endi

sql insert into tb0 values (now, 10, 10, 10, 10, 'binary0', '涛思0', true) tb1 values (now, 11, 11, 11, 11, 'binary1', '涛思1', false) tb2 values (now, 12, 12, 12, 12, 'binary2', '涛思2', true) tb3 values (now, 13, 13, 13, 13, 'binary3', '涛思3', false) tb4 values (now, 14, 14, 14, 14, 'binary4', '涛思4', true) 
B
Bomin Zhang 已提交
204
sleep 30000
S
slguan 已提交
205 206 207 208 209 210 211
sql select * from strm0 order by ts desc
sleep 1000
if $rows != 4 then
  print ==== expect rows = 4, actually returned rows = $rows
  return -1
endi

212
system sh/exec.sh -n dnode1 -s stop -x SIGINT