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

system sh/deploy.sh -n dnode1 -i 1
H
Haojun Liao 已提交
4
system sh/cfg.sh -n dnode1 -c walLevel -v 1
H
Haojun Liao 已提交
5
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
sql use $db

H
Haojun Liao 已提交
27 28 29
print =====================================> td-4481
sql create database $db

H
Haojun Liao 已提交
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 113 114 115
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 已提交
116
if $data00 != @15-08-18 00:06:00.000@ then
H
Haojun Liao 已提交
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
  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 已提交
224 225 226 227 228
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 已提交
229 230 231 232
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 已提交
233
#todo add test case while column filter exists for twa query
H
Haojun Liao 已提交
234

H
Haojun Liao 已提交
235
#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 已提交
236 237 238 239 240 241 242 243 244 245 246 247 248

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
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

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 已提交
279
sleep 100
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 313 314 315

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

S
shenglian zhou 已提交
316 317 318 319 320 321
print =============================> TD-6086
sql create stable td6086st(ts timestamp, d double) tags(t nchar(50));
sql create table td6086ct1 using td6086st tags("ct1");
sql create table td6086ct2 using td6086st tags("ct2");
sql SELECT LAST(d),t FROM td6086st WHERE tbname in ('td6086ct1', 'td6086ct2') and ts>="2019-07-30 00:00:00" and ts<="2021-08-31 00:00:00" interval(1800s) fill(prev) GROUP BY tbname;

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 363 364 365 366 367 368 369 370 371
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 已提交
372 373 374 375 376 377 378 379 380 381 382 383

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 已提交
384 385 386 387 388 389 390 391 392 393

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);
H
Haojun Liao 已提交
394 395 396
sql insert into car1 (ts, c) values (now,1) car2(ts, c) values(now, 2);

print ========================> TD-2700
H
Haojun Liao 已提交
397 398 399
sql create table tx(ts timestamp, k int);
sql insert into tx values(1500000001000, 0);
sql select sum(k) from tx interval(1d) sliding(1h);
H
Haojun Liao 已提交
400
if $rows != 24 then
H
Haojun Liao 已提交
401
  print expect 24, actual:$rows
H
Haojun Liao 已提交
402 403 404
  return -1
endi

405 406 407 408 409 410 411 412 413 414 415 416 417
print ========================> TD-3948
sql drop table if exists meters
sql create stable meters (ts timestamp, current float, voltage int, phase float) tags (location binary(64), groupId int);
sql_error insert into td3948Err1(phase) using meters tags ("Beijng.Chaoyang", 2) (ts, current) values (now, 10.2);
sql_error insert into td3948Err2(phase, voltage) using meters tags ("Beijng.Chaoyang", 2) (ts, current) values (now, 10.2);
sql_error insert into td3948Err3(phase, current) using meters tags ("Beijng.Chaoyang", 2) (ts, current) values (now, 10.2);
sql insert into td3948 using meters tags ("Beijng.Chaoyang", 2) (ts, current) values (now, 10.2);
sql select count(ts) from td3948;
if $rows != 1 then
  print expect 1, actual:$rows
  return -1
endi

H
Haojun Liao 已提交
418 419 420
print ========================> TD-2740
sql drop table if exists m1;
sql create table m1(ts timestamp, k int) tags(a int);
H
Haojun Liao 已提交
421 422 423 424 425 426 427 428 429
sql create table tm10 using m1 tags(0);
sql create table tm11 using m1 tags(1);
sql create table tm12 using m1 tags(2);
sql create table tm13 using m1 tags(3);
sql insert into tm10 values('2020-1-1 1:1:1', 0);
sql insert into tm11 values('2020-1-5 1:1:1', 0);
sql insert into tm12 values('2020-1-7 1:1:1', 0);
sql insert into tm13 values('2020-1-1 1:1:1', 0);
sql select count(*) from m1 where ts='2020-1-1 1:1:1' interval(1h) group by tbname;
H
Haojun Liao 已提交
430 431
if $rows != 2 then
  return -1
432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787
endi

sql drop table m1;
sql drop table if exists tm1;
sql drop table if exists tm2;
sql create table m1(ts timestamp, k double, b double, c int, d smallint, e int unsigned) tags(a int);
sql create table tm1 using m1 tags(1);
sql create table tm2 using m1 tags(2);
sql insert into tm1 values('2021-01-27 22:22:39.294', 1, 10, NULL, 110, 123) ('2021-01-27 22:22:40.294', 2, 20, NULL, 120, 124) ('2021-01-27 22:22:41.294', 3, 30, NULL, 130, 125)('2021-01-27 22:22:43.294', 4, 40, NULL, 140, 126)('2021-01-27 22:22:44.294', 5, 50, NULL, 150, 127);
sql insert into tm2 values('2021-01-27 22:22:40.688', 5, 101, NULL, 210, 321) ('2021-01-27 22:22:41.688', 5, 102, NULL, 220, 322) ('2021-01-27 22:22:42.688', 5, 103, NULL, 230, 323)('2021-01-27 22:22:43.688', 5, 104, NULL, 240, 324)('2021-01-27 22:22:44.688', 5, 105, NULL, 250, 325)('2021-01-27 22:22:45.688', 5, 106, NULL, 260, 326);
sql select stddev(k) from m1
if $rows != 1 then
  return -1
endi

if $data00 != 1.378704626 then
  return -1
endi

sql select stddev(c) from m1
if $rows != 0 then
  return -1
endi

sql select stddev(k), stddev(c) from m1
if $rows != 1 then
  return -1
endi

if $data00 != 1.378704626 then
  return -1
endi

if $data01 != NULL then
  return -1;
endi

sql select stddev(b),stddev(b),stddev(k) from m1;
if $rows != 1 then
  return -1
endi

if $data00 != 37.840465463 then
  return -1
endi

if $data01 != 37.840465463 then
  return -1
endi

if $data02 != 1.378704626 then
  return -1
endi

sql select stddev(k), stddev(b) from m1 group by a
if $rows != 2 then
  return -1
endi

if $data00 != 1.414213562 then
  return -1
endi

if $data01 != 14.142135624 then
  return -1
endi

if $data02 != 1 then
  return -1
endi

if $data10 != 0.000000000 then
  return -1
endi

if $data11 != 1.707825128 then
  return -1
endi

if $data12 != 2 then
  return -1
endi

sql select stddev(k), stddev(b) from m1 where a= 1 group by a
if $rows != 1 then
  return -1
endi

if $data00 != 1.414213562 then
 return -1
endi

if $data01 != 14.142135624 then
  return -1
endi

if $data02 != 1 then
 return -1
endi

sql select stddev(k), stddev(b) from m1 group by tbname
if $rows != 2 then
  return -1
endi

if $data00 != 1.414213562 then
  return -1
endi

if $data01 != 14.142135624 then
  return -1
endi

if $data02 != @tm1@ then
  return -1
endi

if $data10 != 0.000000000 then
  return -1
endi

if $data11 != 1.707825128 then
  return -1
endi

if $data12 != @tm2@ then
  return -1
endi

sql select stddev(k), stddev(b) from m1 group by tbname,a
if $rows != 2 then
  return -1
endi

sql select stddev(k), stddev(b), stddev(c) from m1  group by tbname,a
if $rows != 2 then
  return -1
endi

if $data00 != 1.414213562 then
  return -1
endi

if $data01 != 14.142135624 then
  return -1
endi

if $data02 != NULL then
  return -1
endi

if $data03 != @tm1@ then
  return -1
endi

if $data04 != 1 then
  return -1
endi

if $data10 != 0.000000000 then
  return -1
endi

if $data11 != 1.707825128 then
  return -1
endi

if $data12 != NULL then
  return -1
endi

if $data13 != @tm2@ then
  return -1
endi

if $data14 != 2 then
  return -1
endi

sql select stddev(k), stddev(b), stddev(c) from m1 interval(10s) group by tbname,a
if $rows != 3 then
  return -1
endi

if $data01 != 0.000000000 then
  return -1
endi

if $data02 != 0.000000000 then
  return -1
endi

if $data03 != NULL then
  return -1
endi

if $data04 != @tm1@ then
  return -1
endi

if $data05 != 1 then
  return -1
endi

if $data11 != 1.118033989 then
  return -1
endi

if $data12 != 11.180339887 then
  return -1
endi

if $data13 != NULL then
  return -1
endi

if $data14 != @tm1@ then
  return -1
endi

if $data22 != 1.707825128 then
  return -1
endi

if $data23 != NULL then
  return -1
endi

if $data24 != @tm2@ then
  return -1
endi

if $data25 != 2 then
  return -1
endi

sql select count(*), first(b), stddev(b), stddev(c) from m1 interval(10s) group by a
if $rows != 3 then
  return -1
endi

if $data00 != @21-01-27 22:22:30.000@ then
  return -1
endi

if $data01 != 1 then
  return -1
endi

if $data02 != 10.000000000 then
  return -1
endi

if $data03 != 0.000000000 then
  return -1
endi

if $data04 != NULL then
  return -1
endi

if $data05 != 1 then
  return -1
endi

if $data12 != 20.000000000 then
  return -1
endi

if $data13 != 11.180339887 then
  return -1
endi

if $data14 != NULL then
  return -1
endi

if $data23 != 1.707825128 then
  return -1
endi

sql select count(*), first(b), stddev(b), stddev(c) from m1 interval(10s) group by tbname,a
if $rows != 3 then
  return -1
endi

if $data23 != 1.707825128 then
  return -1
endi

if $data25 != @tm2@ then
  return -1
endi

sql select count(*), stddev(b), stddev(b)+20, stddev(c) from m1 interval(10s) group by tbname,a
if $rows != 3 then
  return -1
endi

if $data02 != 0.000000000 then
  return -1
endi

if $data03 != 20.000000000 then
  return -1
endi

if $data13 != 31.180339887 then
  return -1
endi

if $data14 != NULL then
  return -1
endi

sql select count(*), first(b), stddev(b)+first(b), stddev(c) from m1 interval(10s) group by tbname,a
if $rows != 3 then
  return -1
endi

if $data02 != 10.000000000 then
  return -1
endi

if $data03 != 10.000000000 then
  return -1
endi

if $data12 != 20.000000000 then
  return -1
endi

if $data13 != 31.180339887 then
  return -1
endi

if $data22 != 101.000000000 then
  return -1
endi

if $data23 != 102.707825128 then
  return -1
endi

sql select stddev(e),stddev(k) from m1 where a=1
if $rows != 1 then
  return -1
endi

if $data00 != 1.414213562 then
  return -1
endi

if $data01 != 1.414213562 then
  return -1
endi
D
fix bug  
dapan1121 已提交
788 789 790 791

sql create stable st1 (ts timestamp, f1 int, f2 int) tags (id int);
sql create table tb1 using st1 tags(1);

792
sql insert into tb1 values ('2021-07-02 00:00:00', 1, 1);
D
fix bug  
dapan1121 已提交
793 794 795 796 797 798 799 800 801 802 803

sql select stddev(f1) from st1 group by f1;

if $rows != 1 then
  return -1
endi

if $data00 != 0.000000000 then
  return -1
endi

H
Haojun Liao 已提交
804 805 806 807 808
sql select count(tbname) from st1
if $rows != 1 then
  return -1
endi

H
Haojun Liao 已提交
809 810 811 812
if $data00 != 1 then
  return -1
endi

H
Haojun Liao 已提交
813 814 815
sql select count(id) from st1
if $rows != 1 then
  return -1
H
Haojun Liao 已提交
816 817 818 819 820
endi

if $data00 != 1 then
  return -1
endi
821 822

print ====================> TODO stddev + normal column filter
823 824 825


print ====================> irate
H
Haojun Liao 已提交
826 827 828
sql_error select irate(f1) from st1;
sql select irate(f1) from  st1 group by tbname;

829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943
sql select irate(k) from t1
if $rows != 1 then
  return -1
endi

if $data00 != 0.000027778 then
  return -1
endi

sql select irate(k) from t1 where ts>='2015-8-18 00:30:00.000'
if $rows != 1 then
  return -1
endi

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

sql select irate(k) from t1 where ts>='2015-8-18 00:06:00.000' and ts<='2015-8-18 00:12:000';
if $rows != 1 then
  return -1
endi

if $data00 != 0.005633334 then
  return -1
endi

sql select irate(k) from t1 interval(10a)
if $rows != 6 then
  return -1
endi

if $data01 != 0.000000000 then
  return -1
endi

if $data11 != 0.000000000 then
  return -1
endi

if $data51 != 0.000000000 then
  return -1
endi

sql select count(*),irate(k) from t1 interval(10m)
if $rows != 4 then
  return -1
endi

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

if $data01 != 2 then
  return -1
endi

if $data02 != 0.000144445 then
  return -1
endi

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

if $data11 != 2 then
  return -1
endi

if $data12 != 0.000272222 then
  return -1
endi

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

if $data21 != 1 then
  return -1
endi

if $data22 != 0.000000000 then
  return -1
endi

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

if $data31 != 1 then
  return -1
endi

if $data32 != 0.000000000 then
  return -1
endi

sql select count(*),irate(k) from t1 interval(10m) order by ts desc
if $rows != 4 then
  return -1
endi

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

if $data31 != 2 then
  return -1
endi

if $data32 != 0.000144445 then
  return -1
endi

H
Haojun Liao 已提交
944 945 946
print ===========================> derivative
sql drop table t1
sql drop table tx;
947
sql drop table if exists m1;
H
Haojun Liao 已提交
948 949
sql drop table if exists tm0;
sql drop table if exists tm1;
950

H
Haojun Liao 已提交
951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065
sql create table tm0(ts timestamp, k double)
sql insert into tm0 values('2015-08-18T00:00:00Z', 2.064) ('2015-08-18T00:06:00Z', 2.116) ('2015-08-18T00:12:00Z', 2.028)
sql insert into tm0 values('2015-08-18T00:18:00Z', 2.126) ('2015-08-18T00:24:00Z', 2.041) ('2015-08-18T00:30:00Z', 2.051)

sql_error select derivative(ts) from tm0;
sql_error select derivative(k) from tm0;
sql_error select derivative(k, 0, 0) from tm0;
sql_error select derivative(k, 1, 911) from tm0;
sql_error select derivative(kx, 1s, 1) from tm0;
sql_error select derivative(k, -20s, 1) from tm0;
sql_error select derivative(k, 20a, 0) from tm0;
sql_error select derivative(k, 200a, 0) from tm0;
sql_error select derivative(k, 999a, 0) from tm0;
sql_error select derivative(k, 20s, -12) from tm0;

sql select derivative(k, 1s, 0) from tm0
if $rows != 5 then
  return -1
endi

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

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

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

if $data11 != -0.000244444 then
  return -1
endi

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

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

if $data30 != @15-08-18 08:24:00.000@ then
  return -1
endi

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

sql select derivative(k, 6m, 0) from tm0;
if $rows != 5 then
  return -1
endi

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

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

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

if $data11 != -0.088000000 then
  return -1
endi

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

if $data21 != 0.098000000 then
  return -1
endi

if $data30 != @15-08-18 08:24:00.000@ then
  return -1
endi

if $data31 != -0.085000000 then
  return -1
endi

sql select derivative(k, 12m, 0) from tm0;
if $rows != 5 then
  return -1
endi

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

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

sql select derivative(k, 6m, 1) from tm0;
if $rows != 3 then
  return -1
endi

sql_error select derivative(k, 6m, 1) from tm0 interval(1s);
sql_error select derivative(k, 6m, 1) from tm0 session(ts, 1s);
sql_error select derivative(k, 6m, 1) from tm0 group by k;
1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084

sql drop table if exists tm0
sql drop table if exists m1

sql create table m1 (ts timestamp, k double ) tags(a int);
sql create table if not exists t0 using m1 tags(1);
sql create table if not exists t1 using m1 tags(2);

sql insert into t0 values('2020-1-1 1:1:1', 1);
sql insert into t0 values('2020-1-1 1:1:3', 3);
sql insert into t0 values('2020-1-1 1:2:4', 4);
sql insert into t0 values('2020-1-1 1:2:5', 5);
sql insert into t0 values('2020-1-1 1:2:6', 6);
sql insert into t0 values('2020-1-1 1:3:7', 7);
sql insert into t0 values('2020-1-1 1:3:8', 8);
sql insert into t0 values('2020-1-1 1:3:9', 9);
sql insert into t0 values('2020-1-1 1:4:10', 10);

sql insert into t1 values('2020-1-1 1:1:2', 2);
1085
print ===========================>td-4739
H
Haojun Liao 已提交
1086
sql select diff(val) from (select derivative(k, 1s, 0) val from t1);
1087 1088 1089
if $rows != 0 then
  return -1
endi
S
shenglian zhou 已提交
1090 1091 1092 1093
sql select csum(val) from (select derivative(k, 1s, 0) val from t1);
if $rows != 0 then
  return -1
endi
1094

1095 1096 1097 1098 1099 1100 1101
sql insert into t1 values('2020-1-1 1:1:4', 20);
sql insert into t1 values('2020-1-1 1:1:6', 200);
sql insert into t1 values('2020-1-1 1:1:8', 2000);
sql insert into t1 values('2020-1-1 1:1:10', 20000);

sql_error select derivative(k, 1s, 0) from m1;
sql_error select derivative(k, 1s, 0) from m1 group by a;
1102 1103
sql_error select derivative(f1, 1s, 0) from (select k from t1);

1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142
sql select derivative(k, 1s, 0) from m1 group by tbname
if $rows != 12 then
  return -1
endi

if $data00 != @20-01-01 01:01:03.000@ then
  return -1
endi

if $data01 != 1.000000000 then
  return -1
endi

if $data02 != @t0@ then
  return -1
endi

if $data10 != @20-01-01 01:02:04.000@ then
  return -1
endi

if $data11 != 0.016393443 then
  return -1
endi

if $data12 != t0 then
  return -1
endi

if $data90 != @20-01-01 01:01:06.000@ then
  return -1
endi

if $data91 != 90.000000000 then
  return -1
endi

if $data92 != t1 then
  return -1
1143 1144
endi

H
Haojun Liao 已提交
1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159
print =========================>TD-5190
sql select stddev(f1) from st1 where ts>'2021-07-01 1:1:1' and ts<'2021-07-30 00:00:00' interval(1d) fill(NULL);
if $rows != 29 then
  return -1
endi

if $data00 != @21-07-01 00:00:00.000@ then
  return -1
endi

if $data01 != NULL then
  return -1
endi


1160
sql select derivative(test_column_alias_name, 1s, 0) from (select avg(k) test_column_alias_name from t1 interval(1s));
W
wpan 已提交
1161

1162 1163 1164 1165 1166
sql create table smeters (ts timestamp, current float, voltage int) tags (t1 int);
sql create table smeter1 using smeters tags (1);
sql insert into smeter1 values ('2021-08-08 10:10:10', 10, 2);
sql insert into smeter1 values ('2021-08-08 10:10:12', 10, 2);
sql insert into smeter1 values ('2021-08-08 10:10:14', 20, 1);
W
wpan 已提交
1167 1168 1169 1170 1171 1172 1173 1174

sql select stddev(voltage) from smeters where ts>='2021-08-08 10:10:10.000' and ts < '2021-08-08 10:10:20.000'  and current=10 interval(1000a);
if $rows != 2 then
  return -1
endi
if $data00 != @21-08-08 10:10:10.000@ then
  return -1
endi
1175 1176 1177
if $data01 != 0.000000000 then
  return -1
endi
W
wpan 已提交
1178 1179 1180
if $data10 != @21-08-08 10:10:12.000@ then
  return -1
endi
1181 1182 1183
if $data11 != 0.000000000 then
  return -1
endi
W
wpan 已提交
1184

1185 1186 1187 1188 1189 1190 1191
sql select stddev(voltage) from smeters where ts>='2021-08-08 10:10:10.000' and ts < '2021-08-08 10:10:20.000'  and current=10;
if $rows != 1 then
  return -1
endi
if $data00 != 0.000000000 then
  return -1
endi
W
wpan 已提交
1192