function.sim 8.5 KB
Newer Older
H
Haojun Liao 已提交
1 2 3 4 5
system sh/stop_dnodes.sh

system sh/deploy.sh -n dnode1 -i 1
system sh/cfg.sh -n dnode1 -c walLevel -v 0
system sh/exec.sh -n dnode1 -s start
H
Haojun Liao 已提交
6
sleep 100
H
Haojun Liao 已提交
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
sql connect

$dbPrefix = m_func_db
$tbPrefix = m_func_tb
$mtPrefix = m_func_mt

$tbNum = 10
$rowNum = 5
$totalNum = $tbNum * $rowNum
$ts0 = 1537146000000
$delta = 600000
print ========== alter.sim
$i = 0
$db = $dbPrefix . $i
$mt = $mtPrefix . $i

sql drop database if exists $db
H
Haojun Liao 已提交
24
sql create database $db keep 36500
H
Haojun Liao 已提交
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
sql use $db

print =====================================> test case for twa in single block

sql create table t1 (ts timestamp, k float);
sql insert into t1 values('2015-08-18 00:00:00', 2.064);
sql insert into t1 values('2015-08-18 00:06:00', 2.116);
sql insert into t1 values('2015-08-18 00:12:00', 2.028);
sql insert into t1 values('2015-08-18 00:18:00', 2.126);
sql insert into t1 values('2015-08-18 00:24:00', 2.041);
sql insert into t1 values('2015-08-18 00:30:00', 2.051);

sql select twa(k),avg(k),count(1) from t1 where ts>='2015-8-18 00:00:00' and ts<='2015-8-18 00:05:00'
if $rows != 1 then
  return -1
endi

if $data00 != 2.063999891 then
  return -1
endi

if $data01 != 2.063999891 then
  return -1
endi

if $data02 != 1 then
  return -1
endi

sql select twa(k),avg(k),count(1) from t1 where ts>='2015-8-18 00:00:00' and ts<='2015-8-18 00:07:00'
if $rows != 1 then
  return -1
endi

if $data00 != 2.089999914 then
  return -1
endi

if $data01 != 2.089999914 then
  return -1
endi

if $data02 != 2 then
  return -1
endi

sql select twa(k),avg(k),count(1) from t1 where ts>='2015-8-18 00:00:00' and ts<='2015-8-18 00:07:00' interval(1m) order by ts asc
if $rows != 2 then
  return -1
endi

if $data00 != @15-08-18 00:00:00.000@ then
  return -1
endi

if $data01 != 2.068333156 then
  return -1
endi

if $data02 != 2.063999891 then
  return -1
endi

if $data03 != 1 then
  return -1
endi

if $data10 != @15-08-18 00:06:00.000@ then
  return -1
endi

if $data11 != 2.115999937 then
  return -1
endi

if $data12 != 2.115999937 then
  return -1
endi

if $data13 != 1 then
  return -1
endi

sql select twa(k),avg(k),count(1) from t1 where ts>='2015-8-18 00:00:00' and ts<='2015-8-18 00:07:00' interval(1m) order by ts desc;
if $rows != 2 then
 return -1
endi

H
Haojun Liao 已提交
113
if $data00 != @15-08-18 00:06:00.000@ then
H
Haojun Liao 已提交
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
  return -1
endi

if $data01 != 2.115999937 then
  return -1
endi

if $data02 != 2.115999937 then
  return -1
endi

if $data03 != 1 then
  return -1
endi

if $data11 != 2.068333156 then
  return -1
endi

sql select twa(k),avg(k),count(1) from t1 where ts>='2015-8-18 00:00:00' and ts<='2015-8-18 00:27:00' interval(10m) order by ts asc
if $rows != 3 then
 return -1
endi

if $data01 != 2.088666666 then
 return -1
endi

if $data02 != 2.089999914 then
 return -1
endi

if $data03 != 2 then
  return -1
endi

if $data11 != 2.077099980 then
  return -1
endi

if $data12 != 2.077000022 then
  return -1
endi

if $data13 != 2 then
  return -1
endi

if $data21 != 2.069333235 then
  return -1
endi

if $data22 != 2.040999889 then
  return -1
endi

if $data23 != 1 then
  return -1
endi

sql select twa(k),avg(k),count(1) from t1 where ts>='2015-8-18 00:00:00' and ts<='2015-8-18 00:27:00' interval(10m) order by ts desc
if $rows != 3 then
  return -1
endi

if $data01 != 2.069333235 then
  return -1
endi

if $data11 != 2.077099980 then
  return -1
endi

if $data21 != 2.088666666 then
  return -1
endi

sql select twa(k),avg(k),count(1) from t1 where ts>='2015-8-18 00:00:00' and ts<='2015-8-18 00:30:00'  order by ts asc
if $data00 != 2.073699975 then
  return -1
endi

if $data01 != 2.070999980 then
  return -1
endi

if $data02 != 6 then
  return -1
endi

sql select twa(k),avg(k),count(1) from t1 where ts>='2015-8-18 00:00:00' and ts<='2015-8-18 00:30:00'  order by ts desc
if $rows != 1 then
  return -1
endi

if $data00 != 2.073699975 then
  return -1
endi

if $data01 != 2.070999980 then
  return -1
endi

if $data02 != 6 then
  return -1
endi

H
Haojun Liao 已提交
221 222 223 224 225
sql select twa(k) from t1 where ts>'2015-8-18 00:00:00' and ts<'2015-8-18 00:00:1'
if $rows != 0 then
  return -1
endi

H
Haojun Liao 已提交
226 227 228 229
sql select twa(k),avg(k),count(1) from t1 where ts>='2015-8-18 00:00:00' and ts<='2015-8-18 00:30:00' interval(10m) order by ts asc
sql select twa(k),avg(k),count(1) from t1 where ts>='2015-8-18 00:00:00' and ts<='2015-8-18 00:30:00' interval(10m) order by ts desc


H
Haojun Liao 已提交
230
#todo add test case while column filter exists for twa query
H
Haojun Liao 已提交
231

H
Haojun Liao 已提交
232
#sql select count(*),TWA(k) from tm0 where ts>='1970-1-1 13:43:00' and ts<='1970-1-1 13:44:10' interval(9s)
H
Haojun Liao 已提交
233 234 235 236 237 238 239 240 241 242 243 244 245

sql create table tm0 (ts timestamp, k float);
sql insert into tm0 values(100000000, 5);
sql insert into tm0 values(100003000, -9);
sql select twa(k) from tm0 where ts<now
if $rows != 1 then
  return -1
endi

if $data00 != -2.000000000 then
  print expect -2.000000000, actual: $data00
  return -1
endi
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

sql create table tm1 (ts timestamp,  k int);
sql insert into tm1 values('2020-10-30 18:11:56.680', -1000);
sql insert into tm1 values('2020-11-19 18:11:45.773', NULL);
sql insert into tm1 values('2020-12-09 18:11:17.098', NULL);
sql insert into tm1 values('2020-12-20 18:11:49.412', 1);
sql insert into tm1 values('2020-12-23 18:11:50.412', 2);
sql insert into tm1 values('2020-12-28 18:11:52.412', 3);

print =====================> td-2610
sql select twa(k)from tm1 where ts>='2020-11-19 18:11:45.773' and ts<='2020-12-9 18:11:17.098'
if $rows != 0 then
 return -1
endi

print =====================> td-2609
sql select apercentile(k, 50) from tm1 where ts>='2020-10-30 18:11:56.680' and ts<='2020-12-09 18:11:17.098'
if $rows != 1 then
  return -1
endi

if $data00 != -1000.000000000 then
  return -1
endi

system sh/exec.sh -n dnode1 -s stop -x SIGINT
sleep 1000
system sh/exec.sh -n dnode1 -s start
print ================== server restart completed
sql connect
H
Haojun Liao 已提交
276
sleep 100
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 306 307 308 309 310 311 312

sql use m_func_db0

print =====================> td-2583
sql select min(k) from tm1 where ts>='2020-11-19 18:11:45.773' and ts<='2020-12-20 18:11:49.412'
if $rows != 1 then
  return -1
endi

if $data00 != 1 then
  print expect 1, actual: $data00
  return -1
endi

print =====================> td-2601
sql select count(*) from tm1 where ts<='2020-6-1 00:00:00' and ts>='2020-1-1 00:00:00' interval(1n) fill(NULL)
if $rows != 0 then
  return -1
endi

print =====================> td-2615
sql select last(ts) from tm1 interval(17a) limit 776 offset 3
if $rows != 3 then
  return -1
endi

sql select last(ts) from tm1 interval(17a) limit 1000 offset 4
if $rows != 2 then
  return -1
endi

sql select last(ts) from tm1 interval(17a) order by ts desc limit 1000 offset 0
if $rows != 6 then
  return -1
endi

313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362
print ==================> td-2624
sql create table tm2(ts timestamp, k int, b binary(12));
sql insert into tm2 values('2011-01-02 18:42:45.326',      -1,'abc');
sql insert into tm2 values('2020-07-30 17:44:06.283',       0, null);
sql insert into tm2 values('2020-07-30 17:44:19.578', 9999999, null);
sql insert into tm2 values('2020-07-30 17:46:06.417',    NULL, null);
sql insert into tm2 values('2020-11-09 18:42:25.538',       0, null);
sql insert into tm2 values('2020-12-29 17:43:11.641',       0, null);
sql insert into tm2 values('2020-12-29 18:43:17.129',       0, null);
sql insert into tm2 values('2020-12-29 18:46:19.109',    NULL, null);
sql insert into tm2 values('2021-01-03 18:40:40.065',       0, null);

sql select twa(k),first(ts) from tm2 where k <50 interval(17s);
if $rows != 6 then
  return -1
endi

if $data00 != @11-01-02 18:42:42.000@ then
  return -1
endi

if $data02 != @11-01-02 18:42:45.326@ then
  return -1
endi

if $data10 != @20-07-30 17:43:59.000@ then
  return -1
endi

if $data21 != 0.000000000 then
  return -1
endi

sql select twa(k),first(ts) from tm2 where k <50 interval(17s) order by ts desc;
if $rows != 6 then
  return -1
endi

sql select twa(k),first(ts),count(k),first(k) from tm2 interval(17s) limit 20 offset 0;
if $rows != 9 then
  return -1
endi

if $data00 != @11-01-02 18:42:42.000@ then
  return -1
endi

if $data10 != @20-07-30 17:43:59.000@ then
  return -1
endi
H
Haojun Liao 已提交
363 364 365 366 367 368 369 370 371 372 373 374

print =================>td-2610
sql select stddev(k) from tm2 where ts='2020-12-29 18:46:19.109'
if $rows != 0 then
  print expect 0, actual:$rows
  return -1
endi

sql select twa(k) from tm2 where ts='2020-12-29 18:46:19.109'
if $rows != 0 then
  return -1
endi
H
Haojun Liao 已提交
375 376 377 378 379 380 381 382 383 384 385

print ========================> TD-1787
sql create table cars(ts timestamp, c int) tags(id int);
sql create table car1 using cars tags(1);
sql create table car2 using cars tags(2);
sql insert into car1 (ts, c) values (now,1) car2(ts, c) values(now, 2);
sql drop table cars;
sql create table cars(ts timestamp, c int) tags(id int);
sql create table car1 using cars tags(1);
sql create table car2 using cars tags(2);
sql insert into car1 (ts, c) values (now,1) car2(ts, c) values(now, 2);