col_arithmetic_query.sim 7.9 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 13 14
$dbPrefix = ca_db
$tbPrefix = ca_tb
$stbPrefix = ca_stb
$rowNum = 10000

$i = 0
$db = $dbPrefix . $i

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

H
Haojun Liao 已提交
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
$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

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 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
if $rows != 10000 then
  return -1
endi

if $data00 != 0.000000000 then
  return -1
endi

if $data01 != NaN then
  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 已提交
64
sql select (c1 * 2) % 7.9 from $tb order by ts desc;
H
Haojun Liao 已提交
65 66 67 68 69 70 71
if $rows != 10000 then
 return -1
endi

if $data00 != 0.100000000 then
  return -1
endi
H
Haojun Liao 已提交
72

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

H
Haojun Liao 已提交
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
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

if $data21 != 20.250000000 then
  return -1
endi

if $data31 != 0.000000000 then
  return -1
endi


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

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

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

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

# 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

H
Haojun Liao 已提交
126 127
# all data types [d.6] ================================================================
sql select c2-c1, c3/c2, c4*c3, c5%c4, c6+99%22, c2-c2 from $tb
H
Haojun Liao 已提交
128 129 130 131 132 133 134 135 136 137 138 139 140

# 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

H
Haojun Liao 已提交
141
# arithmetic expression in join [d.7]==================================================
H
Haojun Liao 已提交
142 143


H
Haojun Liao 已提交
144
# arithmetic expression in union [d.8]=================================================
H
Haojun Liao 已提交
145 146


H
Haojun Liao 已提交
147 148
# arithmetic expression in group by [d.9]==============================================
# in group by tag, not support for normal table
H
Haojun Liao 已提交
149 150 151 152 153 154
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 已提交
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174
# 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

if $data90 != 12.000000000 then
  return -1
endi

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

if $data00 !=
H
Haojun Liao 已提交
175

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

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

H
Haojun Liao 已提交
182
# constant column. [d.13]==============================================================
H
Haojun Liao 已提交
183 184


H
Haojun Liao 已提交
185
# column value filter [d.14]===========================================================
H
Haojun Liao 已提交
186 187


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

H
Haojun Liao 已提交
191
# multi-field output [d.16]============================================================
H
Haojun Liao 已提交
192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207
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 已提交
208
# interval query [d.17]==================================================================
H
Haojun Liao 已提交
209 210 211
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 已提交
212
# aggregation query [d.18]===============================================================
H
Haojun Liao 已提交
213 214
# see test cases below

H
Haojun Liao 已提交
215
# first/last query  [d.19]===============================================================
H
Haojun Liao 已提交
216 217
# see test cases below

H
Haojun Liao 已提交
218
# multiple retrieve [d.20]===============================================================
H
Haojun Liao 已提交
219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 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 276 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 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329
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