tsmaCreateInsertQuery.sim 9.4 KB
Newer Older
1 2 3 4 5 6 7
system sh/stop_dnodes.sh
system sh/deploy.sh -n dnode1 -i 1
system sh/exec.sh -n dnode1 -s start
sleep 50
sql connect

print =============== create database
C
Cary Xu 已提交
8
sql create database d1 keep 36500d vgroups 1
9
sql use d1
K
kailixu 已提交
10
sql alter local 'querySmaOptimize' '1';
11 12

print =============== create super table, include column type for count/sum/min/max/first
K
kailixu 已提交
13
sql create table if not exists stb (ts timestamp, c1 int, c2 float, c3 double, c4 binary(10),c5 nchar(10)) tags (t1 int unsigned)
14 15

sql show stables
G
Ganlin Zhao 已提交
16
if $rows != 1 then
17 18 19 20 21 22 23
  return -1
endi

print =============== create child table
sql create table ct1 using stb tags(1000)

sql show tables
G
Ganlin Zhao 已提交
24
if $rows != 1 then
25 26 27 28
  return -1
endi

print =============== insert data, mode1: one row one table in sql
K
kailixu 已提交
29 30
sql insert into ct1 values('2022-10-19 09:55:45.682', 10, 2.0, 3.0, "a", "n0")
sql insert into ct1 values('2022-10-19 09:55:46.682', 11, 2.1, 3.1,"b","n1")('2022-10-19 09:55:47.682', -12, -2.2, -3.2,"c","n2")('2022-10-19 09:55:48.682', -13, -2.3, -3.3,"d","n3")
31 32 33


print =============== create sma index from super table
C
Cary Xu 已提交
34
sql create sma index sma_index_name1 on stb function(max(c1),max(c2),min(c1)) interval(5m,10s) sliding(5m) watermark 1s max_delay 1s
K
kailixu 已提交
35 36
sql create sma index sma_index_name2 on stb function(sum(c1),first(c1), last(c1), first(c4),last(c4),count(c4),first(c5),last(c5),count(c5),apercentile(c1,80,"t-digest"), avg(c2),count(c3), spread(c3), stddev(c2), hyperloglog(c2), hyperloglog(c4), hyperloglog(c5)) interval(5m,10s) sliding(5m);
# for varchar/binary
K
kailixu 已提交
37 38 39 40 41 42 43
sql_error create sma index sma_index_name3 on stb function(sum(c4)) interval(5m,10s) sliding(5m);
sql_error create sma index sma_index_name3 on stb function(min(c4)) interval(5m,10s) sliding(5m);
sql_error create sma index sma_index_name3 on stb function(max(c4)) interval(5m,10s) sliding(5m);
sql_error create sma index sma_index_name3 on stb function(avg(c4)) interval(5m,10s) sliding(5m);
sql_error create sma index sma_index_name3 on stb function(apercentile(c4)) interval(5m,10s) sliding(5m);
sql_error create sma index sma_index_name3 on stb function(spread(c4)) interval(5m,10s) sliding(5m);
sql_error create sma index sma_index_name3 on stb function(stddev(c4)) interval(5m,10s) sliding(5m);
K
kailixu 已提交
44
# for nchar
K
kailixu 已提交
45 46 47
sql_error create sma index sma_index_name3 on stb function(sum(c5)) interval(5m,10s) sliding(5m);
sql_error create sma index sma_index_name3 on stb function(min(c5)) interval(5m,10s) sliding(5m);
sql_error create sma index sma_index_name3 on stb function(max(c5)) interval(5m,10s) sliding(5m);
K
kailixu 已提交
48 49 50 51
sql_error create sma index sma_index_name3 on stb function(avg(c5)) interval(5m,10s) sliding(5m);
sql_error create sma index sma_index_name3 on stb function(apercentile(c5)) interval(5m,10s) sliding(5m);
sql_error create sma index sma_index_name3 on stb function(spread(c5)) interval(5m,10s) sliding(5m);
sql_error create sma index sma_index_name3 on stb function(stddev(c5)) interval(5m,10s) sliding(5m);
52 53

print =============== trigger stream to execute sma aggr task and insert sma data into sma store
K
kailixu 已提交
54
sql insert into ct1 values('2022-10-19 09:55:50.682', 20, 20.0, 30.0,"e","n5")
C
Cary Xu 已提交
55 56
#==================== sleep 2s to wait for tsma result
sleep 2000
57 58 59 60 61

print =============== show streams ================================
sql show streams;
print $data00 $data01 $data02

K
kailixu 已提交
62 63 64 65 66
if $data00 != sma_index_name1  then
  if $data00 != sma_index_name2 then
    print $data00
    return -1
  endi
67 68 69 70 71 72 73 74 75 76 77 78 79 80
endi

print =============== select * from ct1 from memory
sql select * from ct1;
print $data00 $data01 $data02 $data03
print $data10 $data11 $data12 $data13
print $data20 $data21 $data22 $data23
print $data30 $data31 $data32 $data33
print $data40 $data41 $data42 $data43
if $rows != 5 then
  print rows $rows != 5
  return -1
endi

81
print =============== select with _wstart from stb from memory in designated vgroup
82
sql select _wstart, _wend, min(c1),max(c2),max(c1) from stb interval(5m,10s) sliding(5m);
83
print $data00 $data01 $data02 $data03 $data04
C
Cary Xu 已提交
84
print $data10 $data11 $data12 $data13 $data14
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
if $rows != 1 then
  print rows $rows != 1
  return -1
endi

if $data02 != -13 then
  print data02 $data02 != -13
  return -1
endi

if $data03 != 20.00000 then
  print data03 $data03 != 20.00000
  return -1
endi

if $data04 != 20 then
  print data04 $data04 != 20
  return -1
endi

105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
print =============== select without _wstart from stb from memory in designated vgroup
sql select min(c1),max(c2),max(c1) from stb interval(5m,10s) sliding(5m);
print $data00 $data01 $data02
print $data10 $data11 $data12
if $rows != 1 then
  print rows $rows != 1
  return -1
endi

if $data00 != -13 then
  print data00 $data00 != -13
  return -1
endi

if $data01 != 20.00000 then
  print data01 $data01 != 20.00000
  return -1
endi

if $data02 != 20 then
  print data02 $data02 != 20
  return -1
endi

129
print =============== select * from stb from memory in common vgroups
130
sql select _wstart, _wend, min(c1),max(c2),max(c1),max(c3) from stb interval(5m,10s) sliding(5m);
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
print $data00 $data01 $data02 $data03 $data04 $data05
if $rows != 1 then
  print rows $rows != 1
  return -1
endi

if $data02 != -13 then
  print data02 $data02 != -13
  return -1
endi

if $data03 != 20.00000 then
  print data03 $data03 != 20.00000
  return -1
endi

if $data04 != 20 then
  print data04 $data04 != 20
  return -1
endi

if $data05 != 30.000000000 then
  print data05 $data05 != 30.000000000
  return -1
endi



system sh/exec.sh -n dnode1 -s stop -x SIGINT
system sh/exec.sh -n dnode1 -s start
sleep 50

163 164 165 166 167 168 169 170 171 172 173 174
print =============== select * from ct1 from memory after reboot
sql select * from ct1;
print $data00 $data01 $data02 $data03
print $data10 $data11 $data12 $data13
print $data20 $data21 $data22 $data23
print $data30 $data31 $data32 $data33
print $data40 $data41 $data42 $data43
if $rows != 5 then
  print rows $rows != 5
  return -1
endi

175
print =============== select with _wstart from stb from memory in designated vgroup after reboot
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198
sql select _wstart, _wend, min(c1),max(c2),max(c1) from stb interval(5m,10s) sliding(5m);
print $data00 $data01 $data02 $data03 $data04
print $data10 $data11 $data12 $data13 $data14
if $rows != 1 then
  print rows $rows != 1
  return -1
endi

if $data02 != -13 then
  print data02 $data02 != -13
  return -1
endi

if $data03 != 20.00000 then
  print data03 $data03 != 20.00000
  return -1
endi

if $data04 != 20 then
  print data04 $data04 != 20
  return -1
endi

199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222
print =============== select without _wstart from stb from memory in designated vgroup after reboot
sql select min(c1),max(c2),max(c1) from stb interval(5m,10s) sliding(5m);
print $data00 $data01 $data02
print $data10 $data11 $data12
if $rows != 1 then
  print rows $rows != 1
  return -1
endi

if $data00 != -13 then
  print data00 $data00 != -13
  return -1
endi

if $data01 != 20.00000 then
  print data01 $data01 != 20.00000
  return -1
endi

if $data02 != 20 then
  print data02 $data02 != 20
  return -1
endi

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
print =============== select * from stb from memory in common vgroups after reboot
sql select _wstart, _wend, min(c1),max(c2),max(c1),max(c3) from stb interval(5m,10s) sliding(5m);
print $data00 $data01 $data02 $data03 $data04 $data05
if $rows != 1 then
  print rows $rows != 1
  return -1
endi

if $data02 != -13 then
  print data02 $data02 != -13
  return -1
endi

if $data03 != 20.00000 then
  print data03 $data03 != 20.00000
  return -1
endi

if $data04 != 20 then
  print data04 $data04 != 20
  return -1
endi

if $data05 != 30.000000000 then
  print data05 $data05 != 30.000000000
  return -1
endi
250

251 252 253 254 255 256

#==================== flush database to trigger commit data to file
sql flush database d1;
system sh/exec.sh -n dnode1 -s stop -x SIGINT
system sh/exec.sh -n dnode1 -s start
sleep 50
257 258 259 260 261 262 263 264 265 266 267 268
print =============== select * from ct1 from file
sql select * from ct1;
print $data00 $data01 $data02 $data03
print $data10 $data11 $data12 $data13
print $data20 $data21 $data22 $data23
print $data30 $data31 $data32 $data33
print $data40 $data41 $data42 $data43
if $rows != 5 then
  print rows $rows != 5
  return -1
endi

269
print =============== select with _wstart from stb from file in designated vgroup
270
sql select _wstart, _wend, min(c1),max(c2),max(c1) from stb interval(5m,10s) sliding(5m);
271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291
print $data00 $data01 $data02 $data03 $data04
if $rows != 1 then
  print rows $rows != 1
  return -1
endi

if $data02 != -13 then
  print data02 $data02 != -13
  return -1
endi

if $data03 != 20.00000 then
  print data03 $data03 != 20.00000
  return -1
endi

if $data04 != 20 then
  print data04 $data04 != 20
  return -1
endi

292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314
print =============== select without _wstart from stb from file in designated vgroup
sql select _wend, min(c1),max(c2),max(c1) from stb interval(5m,10s) sliding(5m);
print $data00 $data01 $data02 $data03
if $rows != 1 then
  print rows $rows != 1
  return -1
endi

if $data01 != -13 then
  print data01 $data01 != -13
  return -1
endi

if $data02 != 20.00000 then
  print data02 $data02 != 20.00000
  return -1
endi

if $data03 != 20 then
  print data03 $data03 != 20
  return -1
endi

315
print =============== select * from stb from file in common vgroups
316
sql select _wstart, _wend, min(c1),max(c2),max(c1),max(c3) from stb interval(5m,10s) sliding(5m);
317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342
print $data00 $data01 $data02 $data03 $data04 $data05
if $rows != 1 then
  print rows $rows != 1
  return -1
endi

if $data02 != -13 then
  print data02 $data02 != -13
  return -1
endi

if $data03 != 20.00000 then
  print data03 $data03 != 20.00000
  return -1
endi

if $data04 != 20 then
  print data04 $data04 != 20
  return -1
endi

if $data05 != 30.000000000 then
  print data05 $data05 != 30.000000000
  return -1
endi

C
Cary Xu 已提交
343 344
system sh/exec.sh -n dnode1 -s stop -x SIGINT

345