TDengine/tests/script/general/parser/col_arithmetic_query.sim
2020-11-23 11:15:59 +08:00

240 lines
5.8 KiB
Text

# ======================================= query test cases ========================================
# select from table
$tb = $tbPrefix . 0
## 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
# asc/desc order [d.2]
sql select c1 *( 2 / 3 ), c1/c1 from $tb order by ts asc;
sql select (c1 * 2) % 7.9 from $tb order by ts desc;
sql select c1 * c2 /4 from $tb where ts < and ts >
# no result return [d.3]
sql select c1 * 91- 7 from $tb where ts<1537146000000
if $rows != 0 then
return -1
endi
# no result return [d.3]
sql select c2 - c2 from $tb where ts>xxx
if $rows != 0 then
return -1
endi
# single row result aggregation [d.4]
# not available
# 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
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
sql_error select c1/0, c2/0, c3/0.0 from $tb
sql_error select c1/0.00000000001 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;
# 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 support 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]
sql_error select c2+99 from $tb where t1=12;
# 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;
#======================================= aggregation function arithmetic query cases ================
# asc/desc order [d.2]
sql select first(c1) * ( 2 / 3 ) from $stb order by ts asc;
sql select (count(c1) * 2) % 7.9 from $stb order by ts desc;
# all possible function in the arithmetic expressioin
sql select min(c1) * max(c2) /4, sum(c1) * percentile(c2, 20), apercentile(c4, 33) + 52/9, spread(c5)/min(c2), xxxx, from $stb where ts < and ts >
# 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]
sql_error select c2+99 from $tb where t1=12;
# 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