interval-offset.sim 8.8 KB
Newer Older
P
plum-lihui 已提交
1 2 3
system sh/stop_dnodes.sh
system sh/deploy.sh -n dnode1 -i 1
system sh/exec.sh -n dnode1 -s start
P
plum-lihui 已提交
4
sleep 500
P
plum-lihui 已提交
5 6 7
sql connect

print =============== create database
P
plum-lihui 已提交
8 9
sql drop database d0 -x step1
step1:
P
plum-lihui 已提交
10 11 12 13 14 15 16 17
sql create database d0
sql show databases
if $rows != 1 then 
  return -1
endi

sql use d0

P
plum-lihui 已提交
18 19
print =============== create super table and child table
sql create table stb (ts timestamp, tbcol int) tags (t1 int)
P
plum-lihui 已提交
20
sql show stables
P
plum-lihui 已提交
21
print $rows $data00 $data01 $data02
P
plum-lihui 已提交
22 23 24 25
if $rows != 1 then 
  return -1
endi

P
plum-lihui 已提交
26 27 28 29 30
sql create table ct1 using stb tags ( 1 )
sql create table ct2 using stb tags ( 2 )
sql show tables
print $rows $data00 $data10 $data20
if $rows != 2 then
P
plum-lihui 已提交
31 32 33
  return -1
endi 

P
plum-lihui 已提交
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
print =============== insert data into child table
sql insert into ct1 values ( '2022-01-01 01:01:01.000', 1 )
sql insert into ct1 values ( '2022-01-01 01:01:06.000', 1 )
sql insert into ct1 values ( '2022-01-01 01:01:10.000', 1 )
sql insert into ct1 values ( '2022-01-01 01:01:16.000', 1 )
sql insert into ct1 values ( '2022-01-01 01:01:20.000', 1 )
sql insert into ct1 values ( '2022-01-01 01:01:26.000', 1 )
sql insert into ct1 values ( '2022-01-01 01:01:30.000', 1 )
sql insert into ct1 values ( '2022-01-01 01:01:36.000', 1 )
sql insert into ct1 values ( '2022-01-01 01:01:40.000', 1 )
sql insert into ct1 values ( '2022-01-01 01:01:46.000', 1 )
sql insert into ct1 values ( '2022-01-01 01:01:50.000', 1 )
sql insert into ct1 values ( '2022-01-01 01:01:56.000', 1 )
sql insert into ct1 values ( '2022-01-01 01:02:00.000', 1 )
sql insert into ct1 values ( '2022-01-01 01:02:06.000', 1 )
sql insert into ct1 values ( '2022-01-01 01:02:10.000', 1 )
sql insert into ct1 values ( '2022-01-01 01:02:16.000', 1 )
sql insert into ct1 values ( '2022-01-01 01:02:20.000', 1 )
sql insert into ct1 values ( '2022-01-01 01:02:26.000', 1 )
sql insert into ct1 values ( '2022-01-01 01:02:30.000', 1 )
sql insert into ct1 values ( '2022-01-01 01:02:36.000', 1 )
P
plum-lihui 已提交
55

P
plum-lihui 已提交
56 57 58 59
sql select count(tbcol), sum(tbcol), max(tbcol), min(tbcol), count(*) from ct1 interval(10s, 2s)
print ===> select count(tbcol), sum(tbcol), max(tbcol), min(tbcol), count(*) from ct1 interval(10s, 2s)
print ===> $rows $data00 $data01 $data02 $data03 $data04
if $rows != 10 then
P
plum-lihui 已提交
60
  return -1
P
plum-lihui 已提交
61 62
endi 
if $data00 != 2 then
P
plum-lihui 已提交
63
  return -1
P
plum-lihui 已提交
64 65
endi 
if $data04 != 2 then
P
plum-lihui 已提交
66
  return -1
P
plum-lihui 已提交
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
endi 

sql insert into ct2 values ( '2022-01-01 01:00:01.000', 1 )
sql insert into ct2 values ( '2022-01-01 12:00:01.000', 2 )
sql insert into ct2 values ( '2022-01-01 23:00:01.000', 3 )
sql insert into ct2 values ( '2022-01-02 10:00:01.000', 1 )
sql insert into ct2 values ( '2022-01-03 10:00:01.000', 1 )
sql insert into ct2 values ( '2022-01-04 10:00:01.000', 1 )
sql insert into ct2 values ( '2022-01-05 10:00:01.000', 1 )
sql insert into ct2 values ( '2022-01-06 10:00:01.000', 1 )
sql insert into ct2 values ( '2022-01-07 10:00:01.000', 1 )
sql insert into ct2 values ( '2022-01-08 10:00:01.000', 1 )
sql insert into ct2 values ( '2022-01-09 10:00:01.000', 1 )
sql insert into ct2 values ( '2022-01-10 10:00:01.000', 1 )

sql select count(tbcol), sum(tbcol), max(tbcol), min(tbcol), count(*) from ct2 interval(1d, 2h)
print ===> select count(tbcol), sum(tbcol), max(tbcol), min(tbcol), count(*) from ct2 interval(1d, 2w)
print ===> rows0: $data00 $data01 $data02 $data03 $data04
print ===> rows1: $data10 $data11 $data12 $data13 $data14
print ===> rows2: $data20 $data21 $data22 $data23 $data24
if $rows != 11 then
P
plum-lihui 已提交
88
  return -1
P
plum-lihui 已提交
89 90
endi 
if $data00 != 1 then
P
plum-lihui 已提交
91
  return -1
P
plum-lihui 已提交
92 93
endi 
if $data10 != 2 then
P
plum-lihui 已提交
94 95 96 97 98 99 100 101 102 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 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 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 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305
  return -1
endi

return

sql select count(*) from car interval(1n, 10d) order by ts desc
#        tdSql.checkData(0, 1, 1)
#        tdSql.checkData(1, 1, 2)
#        tdSql.checkData(2, 1, 3)
#        tdSql.checkData(3, 1, 3)
#        tdSql.checkData(4, 1, 6)
#        tdSql.checkData(5, 1, 1)
#        tdSql.checkData(6, 1, 1)
#
sql select count(*) from car interval(2n, 5d)
#        tdSql.checkData(0, 1, 1)
#        tdSql.checkData(1, 1, 1)
#        tdSql.checkData(2, 1, 6)
#        tdSql.checkData(3, 1, 6)
#        tdSql.checkData(4, 1, 3)

sql select count(*) from car interval(2n) order by ts desc
#        tdSql.checkData(0, 1, 3)
#        tdSql.checkData(1, 1, 6)
#        tdSql.checkData(2, 1, 6)
#        tdSql.checkData(3, 1, 1)
#        tdSql.checkData(4, 1, 1)
#
sql select count(*) from car interval(1y, 1n)
#        tdSql.checkData(0, 1, 1)
#        tdSql.checkData(1, 1, 8)
#        tdSql.checkData(2, 1, 8)
#
sql select count(*) from car interval(1y, 2n)
#        tdSql.checkData(0, 1, 1)
#        tdSql.checkData(1, 1, 11)
#        tdSql.checkData(2, 1, 5)

sql select count(*) from car where ts > '2019-05-14 00:00:00' interval(1y, 5d)
#       tdSql.checkData(0, 1, 6)
#       tdSql.checkData(1, 1, 9)












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 )
  
  $x = 0
  while $x < $rowNum
    $cc = $x * 60000
    $ms = 1601481600000 + $cc

    sql insert into $tb values ($ms , $x ) 
    $x = $x + 1
  endw 
 
  $i = $i + 1
endw 

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

sql select count(tbcol), sum(tbcol), max(tbcol), min(tbcol), count(tbcol) from $tb interval(1m)
print ===> select count(tbcol), sum(tbcol), max(tbcol), min(tbcol), count(tbcol) from $tb interval(1m)
print ===> $rows $data01 $data05
if $rows != $rowNum then 
  return -1
endi
if $data00 != 1 then 
  return -1
endi
if $data04 != 1 then 
  return -1
endi

#print =============== step3
#$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
#if $rows != 5 then 
#  return -1
#endi
#if $data00 != 1 then 
#  return -1
#endi
#if $data04 != 1 then 
#  return -1
#endi

#print =============== step4
#$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)
#print ===> select count(tbcol), sum(tbcol), max(tbcol), min(tbcol), count(tbcol) from $tb  where ts <= $ms and ts > $ms2 interval(1m)
#print ===> $rows $data01 $data05
#if $rows != 20 then 
#  return -1
#endi
#if $data00 != 1 then 
#  return -1
#endi
#if $data04 != 1 then 
#  return -1
#endi

#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
#if $rows != 42 then 
#  return -1
#endi
#if $data20 != 1 then 
#  return -1
#endi
#if $data24 != 1 then 
#  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
#if $rows != 20 then 
#  return -1
#endi
#if $data11 != 10 then 
#  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
#if $rows != 5 then 
#  return -1
#endi
#if $data11 != 10 then 
#  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
#if $rows != 20 then 
#  return -1
#endi
#if $data11 != 10 then 
#  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
#if $rows != 42 then 
#  return -1
#endi
#if $data11 != 10 then 
#  return -1
#endi

print =============== clear
#sql drop database $db
#sql show databases
#if $rows != 0 then 
#  return -1
#endi

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