event.sim 7.9 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
system sh/stop_dnodes.sh
system sh/deploy.sh -n dnode1 -i 1
system sh/exec.sh -n dnode1 -s start
sql connect

print ======== prepare data 

sql drop database if exists db1;
sql create database db1 vgroups 5;
sql use db1;
sql create stable sta (ts timestamp, f1 int, f2 binary(10), f3 bool) tags(t1 int, t2 bool, t3 binary(10));
sql create table tba1 using sta tags(0, false, '0');
sql create table tba2 using sta tags(1, true, '1');
sql insert into tba1 values ('2022-09-26 15:15:01', 0, "a", false);
sql insert into tba1 values ('2022-09-26 15:15:02', 1, "0", true);
sql insert into tba1 values ('2022-09-26 15:15:03', 5, "5", false);
sql insert into tba1 values ('2022-09-26 15:15:04', 3, 'b', false);
sql insert into tba1 values ('2022-09-26 15:15:05', 0, '1', false);
sql insert into tba1 values ('2022-09-26 15:15:06', 2, 'd', true);
X
Xiaoyu Wang 已提交
20 21 22 23 24 25
sql insert into tba2 values ('2022-09-26 15:15:01', 0, "a", false);
sql insert into tba2 values ('2022-09-26 15:15:02', 1, "0", true);
sql insert into tba2 values ('2022-09-26 15:15:03', 5, "5", false);
sql insert into tba2 values ('2022-09-26 15:15:04', 3, 'b', false);
sql insert into tba2 values ('2022-09-26 15:15:05', 0, '1', false);
sql insert into tba2 values ('2022-09-26 15:15:06', 2, 'd', true);
26 27 28 29 30 31 32 33 34 35

# child table: no window
print ====> select count(*) from tba1 event_window start with f1 = 0 end with f2 = 'c';
sql select count(*) from tba1 event_window start with f1 = 0 end with f2 = 'c';
if $rows != 0 then
  return -1
endi

# child table: single row window
print ====> select count(*) from tba1 event_window start with f1 = 0 end with f3 = false;
X
Xiaoyu Wang 已提交
36
sql select count(*) from tba1 event_window start with f1 = 0 end with f3 = false;
H
Haojun Liao 已提交
37
if $rows != 2 then
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
  return -1
endi
if $data00 != 1 then
  return -1
endi

# child table: multi rows window
print ====> select count(*) from tba1 event_window start with f1 = 0 end with f2 = 'b';
sql select count(*) from tba1 event_window start with f1 = 0 end with f2 = 'b';
if $rows != 1 then
  return -1
endi
if $data00 != 4 then
  return -1
endi

# child table: multi windows
print ====> select count(*) from tba1 event_window start with f1 >= 0 end with f3 = true;
sql select count(*) from tba1 event_window start with f1 >= 0 end with f3 = true;
if $rows != 2 then
  return -1
endi
if $data00 != 2 then
  return -1
endi
H
Haojun Liao 已提交
63
if $data10 != 4 then
64 65 66
  return -1
endi

X
Xiaoyu Wang 已提交
67 68 69 70 71 72 73 74 75 76 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 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 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 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 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 230 231 232 233 234 235 236 237 238
# super table: no window
print ====> select count(*) from sta event_window start with f1 = 0 end with f2 = 'c';
sql select count(*) from sta event_window start with f1 = 0 end with f2 = 'c';
if $rows != 0 then
  return -1
endi

# super table: single row window
print ====> select count(*) from sta event_window start with f1 = 0 end with f3 = false;
sql select count(*) from sta event_window start with f1 = 0 end with f3 = false;
if $rows != 4 then
  return -1
endi
if $data00 != 1 then
  return -1
endi

# super table: multi rows window
print ====> select count(*) from sta event_window start with f1 = 0 end with f2 = 'b';
sql select count(*) from sta event_window start with f1 = 0 end with f2 = 'b';
if $rows != 1 then
  return -1
endi
if $data00 != 7 then
  return -1
endi

# super table: multi windows
print ====> select count(*) from sta event_window start with f1 >= 0 end with f3 = true;
sql select count(*) from sta event_window start with f1 >= 0 end with f3 = true;
if $rows != 4 then
  return -1
endi
if $data00 != 3 then
  return -1
endi
if $data10 != 1 then
  return -1
endi
if $data20 != 7 then
  return -1
endi
if $data30 != 1 then
  return -1
endi

# multi-child table: no window
print ====> select tbname, count(*) from sta partition by tbname event_window start with f1 = 0 end with f2 = 'c';
sql select tbname, count(*) from sta partition by tbname event_window start with f1 = 0 end with f2 = 'c';
if $rows != 0 then
  return -1
endi

# multi-child table: single row window
print ====> select tbname, count(*) from sta partition by tbname event_window start with f1 = 0 end with f3 = false;
sql select tbname, count(*) from sta partition by tbname event_window start with f1 = 0 end with f3 = false;
if $rows != 4 then
  return -1
endi
if $data01 != 1 then
  return -1
endi

# multi-child table: multi rows window
print ====> select tbname, count(*) from sta partition by tbname event_window start with f1 = 0 end with f2 = 'b';
sql select tbname, count(*) from sta partition by tbname event_window start with f1 = 0 end with f2 = 'b';
if $rows != 2 then
  return -1
endi
if $data01 != 4 then
  return -1
endi
if $data11 != 4 then
  return -1
endi

# multi-child table: multi windows
print ====> select tbname, count(*) from sta partition by tbname event_window start with f1 >= 0 end with f3 = true;
sql select tbname, count(*) from sta partition by tbname event_window start with f1 >= 0 end with f3 = true;
if $rows != 4 then
  return -1
endi
if $data01 != 2 then
  return -1
endi
if $data11 != 4 then
  return -1
endi

# where + partition by
print ====> select tbname, count(*) from sta where f3 = false partition by tbname event_window start with f1 >0 end with f2 > 0;
sql select tbname, count(*) from sta where f3 = false partition by tbname event_window start with f1 >0 end with f2 > 0;
if $rows != 4 then
  return -1
endi
if $data01 != 1 then
  return -1
endi
if $data11 != 2 then
  return -1
endi

# where + order by
print ====> select count(*) cnt from tba1 where f3 = false event_window start with f1 >0 end with f2 > 0 order by cnt desc;
sql select count(*) cnt from tba1 where f3 = false event_window start with f1 >0 end with f2 > 0 order by cnt desc;
if $rows != 2 then
  return -1
endi
if $data00 != 2 then
  return -1
endi
if $data10 != 1 then
  return -1
endi

# where + partition by + order by
print ====> select tbname, count(*) cnt from sta where f3 = false partition by tbname event_window start with f1 >0 end with f2 > 0 order by cnt;
sql select tbname, count(*) cnt from sta where f3 = false partition by tbname event_window start with f1 >0 end with f2 > 0 order by cnt;
if $rows != 4 then
  return -1
endi
if $data01 != 1 then
  return -1
endi
if $data11 != 1 then
  return -1
endi

# where + partition by + order by + limit
print ====> select tbname, count(*) cnt from sta where f3 = false partition by tbname event_window start with f1 >0 end with f2 > 0 order by cnt limit 2 offset 2;
sql select tbname, count(*) cnt from sta where f3 = false partition by tbname event_window start with f1 >0 end with f2 > 0 order by cnt limit 2 offset 2;
if $rows != 2 then
  return -1
endi
if $data01 != 2 then
  return -1
endi
if $data11 != 2 then
  return -1
endi

# subquery(where + partition by + order by + limit)
print ====> select * from (select tbname tname, count(*) cnt from sta where f3 = false partition by tbname event_window start with f1 >0 end with f2 > 0 order by cnt limit 2 offset 2);
sql select * from (select tbname tname, count(*) cnt from sta where f3 = false partition by tbname event_window start with f1 >0 end with f2 > 0 order by cnt limit 2 offset 2);
if $rows != 2 then
  return -1
endi
if $data01 != 2 then
  return -1
endi
if $data11 != 2 then
  return -1
endi

# subquery + where + partition by + order by + limit
print ====> select tname, count(*) cnt from (select tbname tname, * from sta) where f3 = false partition by tname event_window start with f1 >0 end with f2 > 0 order by cnt limit 2 offset 2;
sql select tname, count(*) cnt from (select tbname tname, * from sta) where f3 = false partition by tname event_window start with f1 >0 end with f2 > 0 order by cnt limit 2 offset 2;
if $rows != 2 then
  return -1
endi
if $data01 != 2 then
  return -1
endi
if $data11 != 2 then
  return -1
endi

sql_error select f1, f2 from sta event_window start with f1 >0 end with f2 > 0;
sql_error select count(*) from sta event_window start with f1 >0 end with f2 > 0 partition by tbname;
sql_error select count(*) from sta event_window start with f1 >0 end with f2 > 0 group by tbname;
sql_error select count(*) from sta event_window start with f1 >0 end with f2 > 0 fill(NULL);

239
system sh/exec.sh -n dnode1 -s stop -x SIGINT