col_arithmetic_query.sim 9.8 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

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

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

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

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

H
Haojun Liao 已提交
75 76 77
if $data10 != 2.100000000 then
  return -1
endi
H
Haojun Liao 已提交
78

H
Haojun Liao 已提交
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
if $data90 != 6.000000000 then
 return -1
endi

# [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 已提交
97 98
if $data20 != 20.250000000 then
  print expect 20.250000000, acutal:$data21
H
Haojun Liao 已提交
99 100 101
  return -1
endi

H
Haojun Liao 已提交
102
if $data30 != 0.000000000 then
H
Haojun Liao 已提交
103 104 105 106 107
  return -1
endi

# no result return [d.3] ==============================================================
sql select c1 * 91- 7 from $tb where ts < 1537146000000
H
Haojun Liao 已提交
108 109 110 111 112
if $rows != 0 then
  return -1
endi

# no result return [d.3]
H
Haojun Liao 已提交
113
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 已提交
114 115 116 117
if $rows != 0 then
  return -1
endi

H
Haojun Liao 已提交
118
# single row result aggregation [d.4] =================================================
H
Haojun Liao 已提交
119 120 121
# not available

# error cases
H
Haojun Liao 已提交
122
# not available
H
Haojun Liao 已提交
123 124

# multi row result aggregation [d.4]
H
Haojun Liao 已提交
125 126 127
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
H
Haojun Liao 已提交
128

H
Haojun Liao 已提交
129
# all data types [d.6] ================================================================
H
Haojun Liao 已提交
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
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

if $data01 != -nan then
  return -1
endi

if $data02 != 0.000000000 then
  return -1
endi

if $data03 != 0.000000000 then
  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 已提交
178 179 180 181 182 183 184 185 186 187 188

# 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 已提交
189
# arithmetic expression in join [d.7]==================================================
H
Haojun Liao 已提交
190 191


H
Haojun Liao 已提交
192
# arithmetic expression in union [d.8]=================================================
H
Haojun Liao 已提交
193 194


H
Haojun Liao 已提交
195 196
# arithmetic expression in group by [d.9]==============================================
# in group by tag, not support for normal table
H
Haojun Liao 已提交
197 198 199 200 201 202
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 已提交
203 204 205 206 207 208 209 210 211 212
# 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 已提交
213
if $data90 != 76.000000000 then
H
Haojun Liao 已提交
214 215 216 217 218 219 220 221
  return -1
endi

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

H
Haojun Liao 已提交
222 223 224
if $data00 != 0.090796283 then
  return -1
endi
H
Haojun Liao 已提交
225

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

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

H
Haojun Liao 已提交
232
# constant column. [d.13]==============================================================
H
Haojun Liao 已提交
233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248
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 已提交
249

H
Haojun Liao 已提交
250 251 252 253 254 255 256 257 258 259 260
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 已提交
261

H
Haojun Liao 已提交
262
# column value filter [d.14]===========================================================
H
Haojun Liao 已提交
263 264 265 266
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 已提交
267

H
Haojun Liao 已提交
268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290
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 已提交
291

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

H
Haojun Liao 已提交
295
# multi-field output [d.16]============================================================
H
Haojun Liao 已提交
296
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 已提交
297 298 299 300 301 302 303 304 305 306 307 308 309
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 已提交
310
# interval query [d.17]==================================================================
H
Haojun Liao 已提交
311 312 313
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 已提交
314
# aggregation query [d.18]===============================================================
H
Haojun Liao 已提交
315 316
# see test cases below

H
Haojun Liao 已提交
317
# first/last query  [d.19]===============================================================
H
Haojun Liao 已提交
318 319
# see test cases below

H
Haojun Liao 已提交
320
# multiple retrieve [d.20]===============================================================
H
Haojun Liao 已提交
321
sql select c2-c2, 911 from $tb
H
Haojun Liao 已提交
322 323 324 325

#======================================= aggregation function arithmetic query cases ================
# asc/desc order [d.2]
sql select first(c1) * ( 2 / 3 ) from $stb order by ts asc;
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
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

if $data01 != 100000 then
  return -1
endi

if $data02 != 200000 then
  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
  return -1
endi
H
Haojun Liao 已提交
368

369 370 371 372 373 374 375
if $data01 != 9.000000000 then
  return -1
endi

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

H
Haojun Liao 已提交
377
# all possible function in the arithmetic expressioin
H
Haojun Liao 已提交
378
sql select min(c1) * max(c2) /4, sum(c1) * percentile(c2, 20), apercentile(c4, 33) + 52/9, spread(c5)/min(c2) from $stb where ts <  and ts >
H
Haojun Liao 已提交
379 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 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444

# no result return [d.3]
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]
sql select sum(c2) - avg(c2) from $tb where ts>xxx
if $rows != 0 then
  return -1
endi

# single row result aggregation [d.4]
sql select

# error cases
sql_error select first(c1, c2) - last(c1, c2) from $tb

# multi row result aggregation [d.4]
sql select top(c1, 1) - bottom(c1, 1) from $tb
sql select top(c1, 99) - bottom(c1, 99) from $tb

# all data types [d.6]
sql select c2-c1, c3/c2, c4*c3, c5%c4, c6+99%22 from $tb

# 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

# arithmetic expression in join [d.7]


# arithmetic expression in union [d.8]


# arithmetic expression in group by [d.9]
# in group by tag
# not support for normal table
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;

sql select first(c6) - last(c6) *12 / count(*) from $tb group by c3;

# limit offset [d.10]
sql select c6-c6+12 from $tb limit 12 offset 99;
sql select c4/99.123 from $tb limit 1 offset 9999;

# slimit/soffset not suport for normal table query. [d.11]
sql_error select sum(c1) from $tb slimit 1 soffset 19;

# fill [d.12]
sql_error select c2-c2, c3-c4, c5%c6 from $tb fill(value, 12);

# constant column. [d.13]


# column value filter [d.14]


# tag filter(not support for normal table). [d.15]
H
Haojun Liao 已提交
445
sql_error select sum(c2)+99 from $tb where t1=12;
H
Haojun Liao 已提交
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

# multi-field output [d.16]
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

# interval query [d.17]
sql_error select c2*c2, c3-c3, c4+9 from $tb interval(1s)
sql_error select c7-c9 from $tb interval(2y)

# aggregation query [d.18]
# see test cases below

# first/last query  [d.19]
# see test cases below

# multiple retrieve [d.20]
sql select c2-c2 from $tb;


sql select first(c1)-last(c1), spread(c2), max(c3) - min(c3), avg(c4)*count(c4) from $tb