interval.sim 5.6 KB
Newer Older
P
plum-lihui 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
system sh/stop_dnodes.sh
system sh/deploy.sh -n dnode1 -i 1
system sh/exec.sh -n dnode1 -s start
sql connect

$dbPrefix = m_in_db
$tbPrefix = m_in_tb
$mtPrefix = m_in_mt
$tbNum = 10
$rowNum = 20
$totalNum = 200

print =============== step1
$i = 0
$db = $dbPrefix . $i
$mt = $mtPrefix . $i

sql drop database $db -x step1
step1:
sql create database $db
sql use $db
sql create table $mt (ts timestamp, tbcol int) TAGS(tgcol int)

print ====== start create child tables and insert data
$i = 0
while $i < $tbNum
  $tb = $tbPrefix . $i
  sql create table $tb using $mt tags( $i )
C
cpwu 已提交
29

P
plum-lihui 已提交
30 31 32 33 34
  $x = 0
  while $x < $rowNum
    $cc = $x * 60000
    $ms = 1601481600000 + $cc

C
cpwu 已提交
35
    sql insert into $tb values ($ms , $x )
P
plum-lihui 已提交
36
    $x = $x + 1
C
cpwu 已提交
37 38
  endw

P
plum-lihui 已提交
39
  $i = $i + 1
C
cpwu 已提交
40
endw
P
plum-lihui 已提交
41 42 43 44 45 46

print =============== step2
$i = 1
$tb = $tbPrefix . $i

sql select count(tbcol), sum(tbcol), max(tbcol), min(tbcol), count(tbcol) from $tb interval(1m)
P
plum-lihui 已提交
47 48
print ===> select count(tbcol), sum(tbcol), max(tbcol), min(tbcol), count(tbcol) from $tb interval(1m)
print ===> $rows $data01 $data05
C
cpwu 已提交
49
if $rows != $rowNum then
P
plum-lihui 已提交
50 51
  return -1
endi
C
cpwu 已提交
52
if $data00 != 1 then
P
plum-lihui 已提交
53 54
  return -1
endi
C
cpwu 已提交
55
if $data04 != 1 then
P
plum-lihui 已提交
56 57 58
  return -1
endi

C
cpwu 已提交
59
print =============== step3
P
plum-lihui 已提交
60 61 62 63 64
#$cc = 4 * 60000
#$ms = 1601481600000 + $cc
#sql select count(tbcol), sum(tbcol), max(tbcol), min(tbcol), count(tbcol) from $tb  where ts <= $ms interval(1m)
#print ===> select count(tbcol), sum(tbcol), max(tbcol), min(tbcol), count(tbcol) from $tb  where ts <= $ms interval(1m)
#print ===> $rows $data01 $data05
C
cpwu 已提交
65
#if $rows != 5 then
P
plum-lihui 已提交
66 67
#  return -1
#endi
C
cpwu 已提交
68
#if $data00 != 1 then
P
plum-lihui 已提交
69 70
#  return -1
#endi
C
cpwu 已提交
71
#if $data04 != 1 then
P
plum-lihui 已提交
72 73 74
#  return -1
#endi

C
cpwu 已提交
75
print =============== step4
P
plum-lihui 已提交
76 77 78 79 80 81
#$cc = 40 * 60000
#$ms = 1601481600000 + $cc

#$cc = 1 * 60000
#$ms2 = 1601481600000 - $cc

82 83
sql select _wstart, _wend, _wduration, _qstart, _qend, count(tbcol) from $tb  interval(1m)
print ===> select _wstart, _wend, _wduration, _qstart, _qend, count(tbcol) from $tb  interval(1m)
C
cpwu 已提交
84 85 86 87 88 89 90 91 92 93
print ===> $rows $data01 $data05
if $rows != $rowNum then
  return -1
endi
if $data05 != 1 then
  return -1
endi
if $data02 != 60000 then
  return -1
endi
P
plum-lihui 已提交
94 95 96 97 98 99 100 101 102 103 104

#print =============== step5
#$cc = 40 * 60000
#$ms = 1601481600000 + $cc

#$cc = 1 * 60000
#$ms2 = 1601481600000 - $cc

#sql select count(tbcol), sum(tbcol), max(tbcol), min(tbcol), count(tbcol) from $tb  where ts <= $ms and ts > $ms2 interval(1m) fill(value,0)
#print ===> select count(tbcol), sum(tbcol), max(tbcol), min(tbcol), count(tbcol) from $tb  where ts <= $ms and ts > $ms2 interval(1m) fill(value,0)
#print ===> $rows $data21 $data25
C
cpwu 已提交
105
#if $rows != 42 then
P
plum-lihui 已提交
106 107
#  return -1
#endi
C
cpwu 已提交
108
#if $data20 != 1 then
P
plum-lihui 已提交
109 110
#  return -1
#endi
C
cpwu 已提交
111
#if $data24 != 1 then
P
plum-lihui 已提交
112 113 114 115 116 117 118
#  return -1
#endi

#print =============== step6
#sql select count(tbcol), sum(tbcol), max(tbcol), min(tbcol), count(tbcol) from $mt interval(1m)
#print ===> select count(tbcol), sum(tbcol), max(tbcol), min(tbcol), count(tbcol) from $mt interval(1m)
#print ===> $rows $data11
C
cpwu 已提交
119
#if $rows != 20 then
P
plum-lihui 已提交
120 121
#  return -1
#endi
C
cpwu 已提交
122
#if $data11 != 10 then
P
plum-lihui 已提交
123 124 125 126 127 128 129 130 131
#  return -1
#endi

#print =============== step7
#$cc = 4 * 60000
#$ms = 1601481600000 + $cc
#sql select count(tbcol), sum(tbcol), max(tbcol), min(tbcol), count(tbcol) from $mt  where ts <= $ms interval(1m)
#print ===> select count(tbcol), sum(tbcol), max(tbcol), min(tbcol), count(tbcol) from $mt  where ts <= $ms interval(1m)
#print ===> $rows $data11
C
cpwu 已提交
132
#if $rows != 5 then
P
plum-lihui 已提交
133 134
#  return -1
#endi
C
cpwu 已提交
135
#if $data11 != 10 then
P
plum-lihui 已提交
136 137 138 139 140 141 142 143 144 145 146 147 148
#  return -1
#endi

#print =============== step8
#$cc = 40 * 60000
#$ms1 = 1601481600000 + $cc
#
#$cc = 1 * 60000
#$ms2 = 1601481600000 - $cc
#
#sql select count(tbcol), sum(tbcol), max(tbcol), min(tbcol), count(tbcol) from $mt  where ts <= $ms1 and ts > $ms2 interval(1m)
#print ===> select count(tbcol), sum(tbcol), max(tbcol), min(tbcol), count(tbcol) from $mt  where ts <= $ms1 and ts > $ms2 interval(1m)
#print ===> $rows $data11
C
cpwu 已提交
149
#if $rows != 20 then
P
plum-lihui 已提交
150 151
#  return -1
#endi
C
cpwu 已提交
152
#if $data11 != 10 then
P
plum-lihui 已提交
153 154 155 156 157 158 159 160 161 162 163 164 165
#  return -1
#endi
#
#print =============== step9
#$cc = 40 * 60000
#$ms1 = 1601481600000 + $cc
#
#$cc = 1 * 60000
#$ms2 = 1601481600000 - $cc
#
#sql select count(tbcol), sum(tbcol), max(tbcol), min(tbcol), count(tbcol) from $mt  where ts <= $ms1 and ts > $ms2 interval(1m) fill(value, 0)
#print ===> select count(tbcol), sum(tbcol), max(tbcol), min(tbcol), count(tbcol) from $mt  where ts <= $ms1 and ts > $ms2 interval(1m) fill(value, 0)
#print ===> $rows $data11
C
cpwu 已提交
166
#if $rows != 42 then
P
plum-lihui 已提交
167 168
#  return -1
#endi
C
cpwu 已提交
169
#if $data11 != 10 then
P
plum-lihui 已提交
170 171
#  return -1
#endi
P
plum-lihui 已提交
172

173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208
print ================ step10
print -------- create database and table
sql create database if not exists test
sql use test
sql create stable st (ts timestamp, c2 int) tags(tg int)
print -------- insert 300 rows data
$i = 0
while $i < 300
  $t = 1577807983000
  $cc = $i * 1000
  $t = $t + $cc
  sql select $i % 3
  if $data00 != 0.000000000 then
    goto continue_while
  endi
  sql select $i % 4
  if $data00 == 0.000000000 then
    goto continue_while
  endi
  sql insert into t1 using st tags(1) values ( $t , $i )
  continue_while:
    $i = $i + 1
endw

$ms1 = 1577808120000
$ms2 = 1577808000000
sql select * from (select _wstart, last(ts) as ts, avg(c2) as av from t1 where ts <= $ms1 and ts >= $ms2 interval(10s) sliding(1s) fill(NULL)) order by ts asc
print ----> select asc rows: $rows
$asc_rows = $rows
sql select * from (select _wstart, last(ts) as ts, avg(c2) as av from t1 where ts <= $ms1 and ts >= $ms2 interval(10s) sliding(1s) fill(NULL)) order by ts desc
print ----> select desc rows: $rows
$desc_rows = $rows
if $desc_rows != $asc_rows then
  return -1
endi

P
plum-lihui 已提交
209
print =============== clear
P
plum-lihui 已提交
210
#sql drop database $db
X
Xiaoyu Wang 已提交
211
#sql select * from information_schema.ins_databases
C
cpwu 已提交
212
#if $rows != 0 then
P
plum-lihui 已提交
213 214
#  return -1
#endi
P
plum-lihui 已提交
215

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