col_arithmetic_query.sim 14.3 KB
Newer Older
H
Haojun Liao 已提交
1 2 3
# ======================================= query test cases ========================================
# select from table

H
Haojun Liao 已提交
4 5 6 7 8 9 10 11 12
$dbPrefix = ca_db
$tbPrefix = ca_tb
$stbPrefix = ca_stb
$rowNum = 10000

$i = 0
$db = $dbPrefix . $i
sql use $db

H
Haojun Liao 已提交
13
$tb = $tbPrefix . 0
H
Haojun Liao 已提交
14 15
$stb = $stbPrefix . $i

H
Haojun Liao 已提交
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
## TBASE-344
sql select c1*2 from $tb
if $rows != $rowNum then
  return -1
endi
if $data00 != 0.000000000 then
  return -1
endi
if $data10 != 2.000000000 then
  return -1
endi
if $data20 != 4.000000000 then
  return -1
endi
if $data90 != 18.000000000 then
  return -1
endi

H
Haojun Liao 已提交
34
# asc/desc order [d.2] ======================================================
H
Haojun Liao 已提交
35
sql select c1 *( 2 / 3 ), c1/c1 from $tb order by ts asc;
H
Haojun Liao 已提交
36 37 38 39 40 41 42 43
if $rows != 10000 then
  return -1
endi

if $data00 != 0.000000000 then
  return -1
endi

S
Shengliang Guan 已提交
44 45 46 47
#if $data01 != -nan then
#  print expect -nan, actual: $data01
#  return -1
#endi
H
Haojun Liao 已提交
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64

if $data10 != 0.666666667 then
  return -1
endi

if $data11 != 1.000000000 then
  return -1
endi

if $data90 != 6.000000000 then
  return -1
endi

if $data91 != 1.000000000 then
  return -1
endi

65
sql select (c1 * 2) % 7.9, c1*1, c1*1*1, c1*c1, c1*c1*c1 from $tb order by ts desc;
H
Haojun Liao 已提交
66 67 68 69
if $rows != 10000 then
 return -1
endi

70 71
if $data00 != 2.200000000 then
  print expect 2.200000000, actual:$data00
H
Haojun Liao 已提交
72 73
  return -1
endi
H
Haojun Liao 已提交
74

75
if $data01 != 9.000000000 then
H
Haojun Liao 已提交
76 77
  return -1
endi
H
Haojun Liao 已提交
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
if $data02 != 9.000000000 then
  return -1
endi

if $data03 != 81.000000000 then
  return -1
endi

if $data04 != 729.000000000 then
  return -1
endi


if $data10 != 0.200000000 then
  return -1
endi

if $data11 != 8.000000000 then
  return -1
endi

if $data12 != 8.000000000 then
  return -1
endi

if $data13 != 64.000000000 then
  return -1
endi

if $data14 != 512.000000000 then
  return -1
endi

if $data90 != 0.000000000 then
H
Haojun Liao 已提交
113 114 115
 return -1
endi

116
if $data91 != 0.000000000 then
117 118 119
  return -1
endi

120
if $data92 != 0.000000000 then
121 122 123
  return -1
endi

124
if $data93 != 0.000000000 then
125 126 127
  return -1
endi

128
if $data94 != 0.000000000 then
129 130 131
  return -1
endi

H
Haojun Liao 已提交
132 133 134 135 136 137 138 139 140 141 142 143 144 145
# [d.3]
sql select c1 * c2 /4 from $tb where ts < 1537166000000 and ts > 1537156000000
if $rows != 17 then
  return -1
endi

if $data00 != 12.250000000 then
  return -1
endi

if $data10 != 16.000000000 then
  return -1
endi

H
Haojun Liao 已提交
146
if $data20 != 20.250000000 then
H
Haojun Liao 已提交
147
  print expect 20.250000000, actual:$data21
H
Haojun Liao 已提交
148 149 150
  return -1
endi

H
Haojun Liao 已提交
151
if $data30 != 0.000000000 then
H
Haojun Liao 已提交
152 153 154 155 156
  return -1
endi

# no result return [d.3] ==============================================================
sql select c1 * 91- 7 from $tb where ts < 1537146000000
H
Haojun Liao 已提交
157 158 159 160 161
if $rows != 0 then
  return -1
endi

# no result return [d.3]
H
Haojun Liao 已提交
162
sql select c2 - c2 from $tb where ts > '2018-09-17 12:50:00.000' and ts<'2018-09-17 13:00:00.000'
H
Haojun Liao 已提交
163 164 165 166
if $rows != 0 then
  return -1
endi

H
Haojun Liao 已提交
167
# single row result aggregation [d.4] =================================================
H
Haojun Liao 已提交
168 169 170
# not available

# error cases
H
Haojun Liao 已提交
171
# not available
H
Haojun Liao 已提交
172 173

# multi row result aggregation [d.4]
H
Haojun Liao 已提交
174 175 176
sql_error select top(c1, 1) - bottom(c1, 1) from $tb
sql_error select top(c1, 99) - bottom(c1, 99) from $tb
sql_error select top(c1,1) - 88 from $tb
177 178 179
sql_error select sample(c1, 1) - bottom(c1, 1) from $tb
sql_error select sample(c1, 99) - bottom(c1, 99) from $tb
sql_error select sample(c1,1) - 88 from $tb
H
Haojun Liao 已提交
180

H
Haojun Liao 已提交
181
# all data types [d.6] ================================================================
H
Haojun Liao 已提交
182 183 184 185 186 187 188 189 190
sql select c2-c1*1.1, c3/c2, c4*c3, c5%c4, (c6+c4)%22, c2-c2 from $tb
if $rows != 10000 then
 return -1
endi

if $data00 != 0.000000000 then
  return -1
endi

S
Shengliang Guan 已提交
191 192 193
#if $data01 != -nan then
#  return -1
#endi
H
Haojun Liao 已提交
194 195 196 197 198

if $data02 != 0.000000000 then
  return -1
endi

Y
yihaoDeng 已提交
199
if $data03 != NULL then
H
Haojun Liao 已提交
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
  return -1
endi

if $data04 != 0.000000000 then
  return -1
endi

if $data05 != 0.000000000 then
  return -1
endi

if $data90 != -0.900000000 then
  return -1
endi

if $data91 != 1.000000000 then
  return -1
endi

if $data92 != 81.000000000 then
  return -1
endi

if $data93 != 0.000000000 then
  return -1
endi

if $data94 != 18.000000000 then
  return -1
endi
H
Haojun Liao 已提交
230 231 232 233 234 235 236 237 238 239 240

# error case, ts/bool/binary/nchar not support arithmetic expression
sql_error select ts+ts from $tb
sql_error select ts+22 from $tb
sql_error select c7*12 from $tb
sql_error select c8/55 from $tb
sql_error select c9+c8 from $tb
sql_error select c7-c8, c9-c8 from $tb
sql_error select ts-c9 from $tb
sql_error select c8+c7, c9+c9+c8+c7/c6 from $tb

H
Haojun Liao 已提交
241
# arithmetic expression in join [d.7]==================================================
H
Haojun Liao 已提交
242 243


H
Haojun Liao 已提交
244
# arithmetic expression in union [d.8]=================================================
H
Haojun Liao 已提交
245 246


H
Haojun Liao 已提交
247 248
# arithmetic expression in group by [d.9]==============================================
# in group by tag, not support for normal table
H
Haojun Liao 已提交
249 250 251 252 253 254
sql_error select c5*99 from $tb group by t1

# in group by column
sql_error select c6-(c6+c3)*12 from $tb group by c3;


H
Haojun Liao 已提交
255 256 257 258 259 260 261 262 263 264
# limit offset [d.10]==================================================================
sql select c6 * c1 + 12 from $tb limit 12 offset 99;
if $rows != 12 then
 return -1
endi

if $data00 != 93.000000000 then
  return -1
endi

H
Haojun Liao 已提交
265
if $data90 != 76.000000000 then
H
Haojun Liao 已提交
266 267 268 269 270 271 272 273
  return -1
endi

sql select c4 / 99.123 from $tb limit 10 offset 9999;
if $rows != 1 then
  return -1
endi

H
Haojun Liao 已提交
274 275 276
if $data00 != 0.090796283 then
  return -1
endi
H
Haojun Liao 已提交
277

H
Haojun Liao 已提交
278
# slimit/soffset not support for normal table query. [d.11]============================
H
Haojun Liao 已提交
279 280
sql_error select sum(c1) from $tb slimit 1 soffset 19;

H
Haojun Liao 已提交
281
# fill [d.12]==========================================================================
H
Haojun Liao 已提交
282
sql_error select c2-c2, c3-c4, c5%c3 from $tb fill(value, 12);
H
Haojun Liao 已提交
283

H
Haojun Liao 已提交
284
# constant column. [d.13]==============================================================
H
Haojun Liao 已提交
285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300
sql select c1, c2+c6, 12.9876545678, 1, 1.1 from $tb
if $rows != 10000 then
  return -1
endi

if $data00 != 0 then
  return -1
endi

if $data01 != 0.000000000 then
  return -1
endi

if $data02 != 12.987654568 then
  return -1
endi
H
Haojun Liao 已提交
301

H
Haojun Liao 已提交
302 303 304 305 306 307 308 309 310 311 312
if $data03 != 1 then
  return -1
endi

if $data04 != 1.100000000 then
  return -1
endi

if $data10 != 1 then
  return -1
endi
H
Haojun Liao 已提交
313

H
Haojun Liao 已提交
314
# column value filter [d.14]===========================================================
H
Haojun Liao 已提交
315 316 317 318
sql select c1, c2+c6, 12.9876545678, 1, 1.1 from $tb where c1<2
if $rows != 2000 then
  return -1
endi
H
Haojun Liao 已提交
319

H
Haojun Liao 已提交
320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342
if $data00 != 0 then
  return -1
endi

if $data01 != 0.000000000 then
  return -1
endi

if $data02 != 12.987654568 then
  return -1
endi

if $data03 != 1 then
  return -1
endi

if $data10 != 1 then
  return -1
endi

if $data20 != 0 then
  return -1
endi
H
Haojun Liao 已提交
343

H
Haojun Liao 已提交
344
# tag filter(not support for normal table). [d.15]=====================================
H
Haojun Liao 已提交
345 346
sql_error select c2+99 from $tb where t1=12;

H
Haojun Liao 已提交
347
# multi-field output [d.16]============================================================
H
Haojun Liao 已提交
348
sql select c4*1+1/2,c4*1+1/2,c4*1+1/2,c4*1+1/2,c4*1+1/2 from $tb
H
Haojun Liao 已提交
349 350 351 352 353 354 355 356 357 358 359 360 361
if $rows != $rowNum then
  return -1
endi
if $data00 != 0.500000000 then
  return -1
endi
if $data10 != 1.500000000 then
  return -1
endi
if $data90 != 9.500000000 then
  return -1
endi

H
Haojun Liao 已提交
362
# interval query [d.17]==================================================================
H
Haojun Liao 已提交
363 364 365
sql_error select c2*c2, c3-c3, c4+9 from $tb interval(1s)
sql_error select c7-c9 from $tb interval(2y)

H
Haojun Liao 已提交
366
# aggregation query [d.18]===============================================================
H
Haojun Liao 已提交
367 368
# see test cases below

H
Haojun Liao 已提交
369
# first/last query  [d.19]===============================================================
H
Haojun Liao 已提交
370 371
# see test cases below

H
Haojun Liao 已提交
372
# multiple retrieve [d.20]===============================================================
H
Haojun Liao 已提交
373
sql select c2-c2, 911 from $tb
H
Haojun Liao 已提交
374

H
Haojun Liao 已提交
375 376 377
#======================================= aggregation function arithmetic query cases ===================================
# on $tb percentile()   spread(ts) bug

H
Haojun Liao 已提交
378 379
# asc/desc order [d.2]
sql select first(c1) * ( 2 / 3 ) from $stb order by ts asc;
380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405
if $rows != 1 then
  return -1
endi

if $data00 != 0.000000000 then
  return -1
endi

sql select first(c1) * (2/99) from $stb order by ts desc;
if $rows != 1 then
  return -1
endi

if $data00 != 0.000000000 then
  return -1
endi

sql select (count(c1) * 2) % 7.9, (count(c1) * 2), ( count(1)*2) from $stb order by ts desc;
if $rows != 1 then
  return -1
endi

if $data00 != 1.800000000 then
  return -1
endi

H
Haojun Liao 已提交
406
if $data01 != 100000.000000000 then
407 408 409
  return -1
endi

H
Haojun Liao 已提交
410
if $data02 != 200000.000000000 then
411 412 413 414 415 416 417 418 419
  return -1
endi

sql select spread( c1 )/44, spread(c1), 0.204545455 * 44 from $stb order by ts asc;
if $rows != 1 then
  return -1
endi

if $data00 != 0.204545455 then
H
Haojun Liao 已提交
420
  print expect 0.204545455, actual: $data00
421 422
  return -1
endi
H
Haojun Liao 已提交
423

424 425 426 427 428 429 430
if $data01 != 9.000000000 then
  return -1
endi

if $data02 != 9.000000020 then
  return -1
endi
H
Haojun Liao 已提交
431

H
Haojun Liao 已提交
432
# all possible function in the arithmetic expression, add more
433
sql select min(c1) * max(c2) /4, sum(c1) * apercentile(c2, 20), apercentile(c4, 33) + 52/9, spread(c5)/min(c2), count(1)/sum(c1), avg(c2)*count(c2) from $stb where ts >= '2018-09-17 09:00:00.000' and ts <= '2018-11-25 19:30:01.000';
H
Haojun Liao 已提交
434 435 436
if $rows != 1 then
  return -1
endi
H
Haojun Liao 已提交
437

H
Haojun Liao 已提交
438 439 440 441 442 443 444 445 446 447 448 449
if $data00 != 0.000000000 then
  return -1
endi

if $data01 != 225000.000000000 then
  return -1
endi

if $data02 != 8.077777778 then
  return -1
endi

Y
yihaoDeng 已提交
450
if $data03 != NULL then
H
Haojun Liao 已提交
451 452 453 454 455 456 457 458 459 460 461 462
  return -1
endi

if $data04 != 0.444444444 then
  return -1
endi

if $data05 != 450000.000000000 then
  return -1
endi

# no result return [d.3]===============================================================
H
Haojun Liao 已提交
463 464 465 466 467 468
sql select first(c1) * 91 - 7, last(c3) from $stb where ts < 1537146000000
if $rows != 0 then
  return -1
endi

# no result return [d.3]
469
sql select sum(c2) - avg(c2) from $stb where ts > '2018-11-25 19:30:01.000'
H
Haojun Liao 已提交
470 471 472 473
if $rows != 0 then
  return -1
endi

H
Haojun Liao 已提交
474 475
# single row result aggregation [d.4]===================================================
# all those cases are aggregation test cases.
H
Haojun Liao 已提交
476 477

# error cases
H
Haojun Liao 已提交
478 479 480
sql_error select first(c1, c2) - last(c1, c2) from $stb
sql_error select top(c1, 5) - bottom(c1, 5) from $stb
sql_error select first(*) - 99 from $stb
481 482
sql_error select sample(c1, 5) - bottom(c1, 5) from $stb

H
Haojun Liao 已提交
483 484

# multi row result aggregation [d.4]
H
Haojun Liao 已提交
485 486
sql_error select top(c1, 1) - bottom(c1, 1) from $stb
sql_error select top(c1, 99) - bottom(c1, 99) from $stb
H
Haojun Liao 已提交
487

488 489 490
sql_error select sample(c1, 1) - top(c1, 1) from $stb
sql_error select sample(c1, 99) - top(c1, 99) from $stb

H
Haojun Liao 已提交
491 492 493 494 495
# query on super table [d.5]=============================================================
# all cases in this part are query on super table

# all data types [d.6]===================================================================
sql select c2-c1, c3/c2, c4*c3, c5%c4, c6+99%22 from $stb
H
Haojun Liao 已提交
496 497

# error case, ts/bool/binary/nchar not support arithmetic expression
H
Haojun Liao 已提交
498 499 500
sql_error select first(c7)*12 from $stb
sql_error select last(c8)/55 from $stb
sql_error select last_row(c9) + last_row(c8) from $stb
H
Haojun Liao 已提交
501

H
Haojun Liao 已提交
502
# arithmetic expression in join [d.7]===============================================================
H
Haojun Liao 已提交
503 504


H
Haojun Liao 已提交
505
# arithmetic expression in union [d.8]===============================================================
H
Haojun Liao 已提交
506 507


H
Haojun Liao 已提交
508
# arithmetic expression in group by [d.9]===============================================================
H
Haojun Liao 已提交
509
# in group by tag
H
Haojun Liao 已提交
510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529
sql select avg(c4)*99 from $stb group by t1
if $rows != 10 then
  return -1
endi

if $data00 != 445.500000000 then
  return -1
endi

if $data01 != 0 then
  return -1
endi

if $data90 != 445.500000000 then
  return -1
endi

if $data91 != 9 then
  return -1
endi
H
Haojun Liao 已提交
530 531

# in group by column
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
#sql select apercentile(c6, 50)-first(c6)+last(c5)*12, last(c5)*12 from ca_stb0 group by c2;
#if $rows != 10 then
#  return -1
#endi
#
#if $data00 != 0.000000000 then
#  return -1
#endi
#
#if $data01 != 0.000000000 then
#  return -1
#endi
#
#if $data10 != 12.000000000 then
#  return -1
#endi
#
#if $data11 != 12.000000000 then
#  return -1
#endi
#
#if $data20 != 24.000000000 then
#  return -1
#endi
#
#if $data21 != 24.000000000 then
#  return -1
#endi
#
H
Haojun Liao 已提交
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
sql_error select first(c6) - last(c6) *12 / count(*) from $stb group by c3;

sql select first(c6) - last(c6) *12 / count(*) from $stb group by c5;
if $rows != 10 then
  return -1
endi

if $data00 != 0.000000000 then
  return -1
endi

if $data10 != 0.997600000 then
  return -1
endi

if $data90 != 8.978400000 then
  return -1
endi

# limit offset [d.10]===============================================================
sql select first(c6) - sum(c6) + 12 from $stb limit 12 offset 0;
if $rows != 1 then
  return -1
endi

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

sql select apercentile(c4, 21) / 99.123 from $stb limit 1 offset 1;
if $rows != 0 then
  return -1
endi

H
Haojun Liao 已提交
595 596 597 598 599 600 601 602 603 604
sql select apercentile(c4, 21) / sum(c4) from $stb interval(1s) limit 1 offset 1;
if $rows != 1 then
  return -1
endi

# slimit/soffset not support for normal table query. [d.11]===============================================================
sql select sum(c1) from $stb slimit 1 soffset 19;
if $rows != 0 then
  return -1
endi
H
Haojun Liao 已提交
605

H
Haojun Liao 已提交
606 607
sql select sum(c1) from $stb interval(1s) group by tbname slimit 1 soffset 1
sql select sum(c1) from ca_stb0 interval(1s) group by tbname slimit 2 soffset 4 limit 10 offset 1
H
Haojun Liao 已提交
608

H
Haojun Liao 已提交
609 610 611
# fill [d.12]===============================================================
sql_error select first(c1)-last(c1), sum(c3)*count(c3), spread(c5 ) % count(*) from $stb interval(1s) fill(prev);
sql_error select first(c1) from $stb fill(value, 20);
H
Haojun Liao 已提交
612

H
Haojun Liao 已提交
613
# constant column. [d.13]===============================================================
H
Haojun Liao 已提交
614 615


H
Haojun Liao 已提交
616
# column value filter [d.14]===============================================================
H
Haojun Liao 已提交
617

H
Haojun Liao 已提交
618 619 620 621 622

# tag filter. [d.15]===============================================================
sql select sum(c2)+99 from $stb where t1=12;

# multi-field output [d.16]===============================================================
H
Haojun Liao 已提交
623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638
sql select count(*), sum(c1)*avg(c2), avg(c3)*count(c3), sum(c3), sum(c4), first(c7), last(c8), first(c9), first(c7), last(c8) from $tb

sql select c4*1+1/2 from $tb
if $rows != $rowNum then
  return -1
endi
if $data00 != 0.500000000 then
  return -1
endi
if $data10 != 1.500000000 then
  return -1
endi
if $data90 != 9.500000000 then
  return -1
endi

H
Haojun Liao 已提交
639 640 641 642 643
# interval query [d.17]===============================================================
sql select avg(c2)*count(c2), sum(c3)-first(c3), last(c4)+9 from $stb interval(1s)
if $rows != 10000 then
  return -1
endi
H
Haojun Liao 已提交
644

H
Haojun Liao 已提交
645 646 647
if $data00 != @18-09-17 09:00:00.000@ then
  return -1
endi
H
Haojun Liao 已提交
648

649
sql_error select first(c7)- last(c1) from $tb interval(2y)
H
Haojun Liao 已提交
650

H
Haojun Liao 已提交
651 652 653 654 655 656 657
# aggregation query [d.18]===============================================================
# all cases in this part are aggregation query test.

# first/last query  [d.19]===============================================================


# multiple retrieve [d.20]===============================================================
658
sql select c2-c2 from $tb
H
Haojun Liao 已提交
659 660 661


sql select first(c1)-last(c1), spread(c2), max(c3) - min(c3), avg(c4)*count(c4) from $tb
H
Haojun Liao 已提交
662 663 664 665


#====================================================super table query==================================================