auto_create_tb.sim 7.3 KB
Newer Older
1 2 3 4
system sh/stop_dnodes.sh
system sh/deploy.sh -n dnode1 -i 1
system sh/exec.sh -n dnode1 -s start
sql connect
S
Shengliang Guan 已提交
5

6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 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 64 65 66 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
print ======================== dnode1 start

$dbPrefix = ac_db
$tbPrefix = ac_tb
$stbPrefix = ac_stb
$tbNum = 10
$rowNum = 20
$totalNum = 200
$ts0 = 1537146000000

print excuting test script auto_create_tb.sim
print =============== set up
$i = 0
$db = $dbPrefix
$stb = $stbPrefix
$tb = $tbPrefix . $i

sql create database $db
sql use $db

print =========== auto_create_tb.sim case1: test
sql CREATE TABLE $stb (TS TIMESTAMP, C1 INT, C2 BIGINT, C3 FLOAT, C4 DOUBLE, C5 BINARY(10), C6 BOOL, C7 SMALLINT, C8 TINYINT, C9 NCHAR(10)) TAGS (T1 INT)
sql show stables

if $rows != 1 then
  return -1
endi
if $data00 != $stb then 
  return -1
endi

### create table on the fly
sql insert into tb1 using $stb tags (1) values ( $ts0 , 1,1,1,1,'bin',1,1,1,'涛思数据') 
sql select * from tb1
if $rows != 1 then
  return -1
endi
if $data01 != 1 then
  return -1
endi
if $data09 != 涛思数据 then
  return -1
endi
if $data02 != 1 then
  return -1
endi
if $data03 != 1.00000 then
  return -1
endi
if $data04 != 1.000000000 then
  return -1
endi
if $data05 != bin then
  return -1
endi

### insert into an existing table
$ts1 = $ts0 + 1000
$ts2 = $ts0 + 2000
sql insert into tb1 using $stb tags (1) values ( $ts1 , 1,1,1,1,'bin',1,1,1,'涛思数据') ( $ts2 , 2,2,2,2,'binar', 1,1,1,'nchar')
sql select * from $stb
if $rows != 3 then
  return -1
endi
if $data19 != 涛思数据 then
  return -1
endi
if $data11 != 1 then
  return -1
endi
if $data22 != 2 then
  return -2
endi
if $data23 != 2.00000 then
  return -1
endi
if $data25 != binar then
  return -1
endi
if $data29 != nchar then
  return -1
endi

### [TBASE-410] auto create table with a negative tag value
$ts1 = $ts0 + 1000
$ts2 = $ts0 + 2000
sql insert into tb_1 using $stb tags (-1) values ( $ts1 , 1,1,1,1,'bin',1,1,1,'涛思数据') ( $ts2 , 2,2,2,2,'binar', 1,1,1,'nchar')
sql select * from $stb
if $rows != 5 then
  return -1
endi
if $data09 != 涛思数据 then
  return -1
endi
if $data01 != 1 then
  return -1
endi
if $data42 != 2 then
  return -2
endi
if $data43 != 2.00000 then
  return -1
endi
if $data45 != binar then
  return -1
endi
if $data49 != nchar then
  return -1
endi
sql drop table tb_1

#### insert into an existing table with wrong tags
$ts3 = $ts0 + 3000
$ts4 = $ts0 + 4000
sql insert into tb1 using $stb tags (2) values ( $ts3 , 1,1,1,1,'bin',1,1,1,'涛思数据') ( $ts4 , 2,2,2,2,'binar', 1,1,1,'nchar')
sql select * from $stb
if $rows != 5 then
  return -1
endi
if $data09 != 涛思数据 then
  return -1
endi
if $data01 != 1 then
  return -1
endi
if $data42 != 2 then
  return -2
endi
if $data43 != 2.00000 then
  return -1
endi
if $data45 != binar then
  return -1
endi
if $data49 != nchar then
  return -1
endi

sql drop table tb1

#### auto create multiple tables
sql insert into tb1 using $stb tags(1) values ( $ts0 , 1, 1, 1, 1, 'bin1', 1, 1, 1, '涛思数据1') tb2 using $stb tags(2) values ( $ts0 , 2, 2, 2, 2, 'bin2', 2, 2, 2, '涛思数据2') tb3 using $stb tags(3) values ( $ts0 , 3, 3, 3, 3, 'bin3', 3, 3, 3, '涛思数据3')
sql show tables
print $rows $data00 $data10 $data20
if $rows != 3 then
  return -1
endi
S
Shengliang Guan 已提交
153
if $data(tb1)[0] != tb1 then
154 155
  return -1
endi
S
Shengliang Guan 已提交
156
if $data(tb2)[0] != tb2 then
157 158
  return -1
endi
S
Shengliang Guan 已提交
159
if $data(tb3)[0] != tb3 then
160 161 162
  return -1
endi

S
Shengliang Guan 已提交
163 164 165 166 167
sql select c1,c1,c2,c3,c4,c5,c7,c8,c9 from $stb
print ===> $data00 $data01 $data02 $data03 $data04 $data05 $data06 $data07 $data08 $data09
print ===> $data10 $data11 $data12 $data13 $data14 $data15 $data16 $data17 $data18 $data19
print ===> $data20 $data21 $data22 $data23 $data24 $data25 $data26 $data27 $data28 $data29

168 169 170
if $rows != 3 then
  return -1
endi
S
Shengliang Guan 已提交
171
if $data(1)[1] != 1 then
172 173
  return -1
endi
S
Shengliang Guan 已提交
174
if $data(1)[8] != 涛思数据1 then
175 176
  return -1
endi
S
Shengliang Guan 已提交
177
if $data(2)[4] != 2.000000000 then
178 179
  return -1
endi
S
Shengliang Guan 已提交
180
if $data(2)[8] != 涛思数据2 then
181 182
  return -1
endi
S
Shengliang Guan 已提交
183
if $data(3)[8] != 涛思数据3 then
184 185 186
  return -1
endi

S
Shengliang Guan 已提交
187 188 189 190 191
sql select t1, count(*), first(c9) from $stb partition by t1 order by t1 asc slimit 3 
if $rows != 3 then
  return -1
endi
if $data(1)[1] != 1 then
192 193
  return -1
endi
S
Shengliang Guan 已提交
194
if $data(1)[2] != 涛思数据1 then
195 196
  return -1
endi
S
Shengliang Guan 已提交
197
if $data(2)[1] != 1 then
198 199
  return -1
endi
S
Shengliang Guan 已提交
200
if $data(2)[2] != 涛思数据2 then
201 202
  return -1
endi
S
Shengliang Guan 已提交
203
if $data(3)[1] != 1 then
204 205
  return -1
endi
S
Shengliang Guan 已提交
206
if $data(3)[2] != 涛思数据3 then
207 208 209 210 211 212 213 214 215 216 217 218 219
  return -1
endi

print ================== restart server to commit data into disk
system sh/exec.sh -n dnode1 -s stop -x SIGINT
system sh/exec.sh -n dnode1 -s start

#### auto create multiple tables
sql insert into tb1 using $stb tags(1) values ( $ts0 , 1, 1, 1, 1, 'bin1', 1, 1, 1, '涛思数据1') tb2 using $stb tags(2) values ( $ts0 , 2, 2, 2, 2, 'bin2', 2, 2, 2, '涛思数据2') tb3 using $stb tags(3) values ( $ts0 , 3, 3, 3, 3, 'bin3', 3, 3, 3, '涛思数据3')
sql show tables
if $rows != 3 then
  return -1
endi
S
Shengliang Guan 已提交
220
if $data(tb1)[0] != tb1 then
221 222
  return -1
endi
S
Shengliang Guan 已提交
223
if $data(tb2)[0] != tb2 then
224 225
  return -1
endi
S
Shengliang Guan 已提交
226
if $data(tb3)[0] != tb3 then
227 228 229
  return -1
endi

S
Shengliang Guan 已提交
230 231 232 233 234
sql select c1,c1,c2,c3,c4,c5,c7,c8,c9 from $stb
print ===> $data00 $data01 $data02 $data03 $data04 $data05 $data06 $data07 $data08 $data09
print ===> $data10 $data11 $data12 $data13 $data14 $data15 $data16 $data17 $data18 $data19
print ===> $data20 $data21 $data22 $data23 $data24 $data25 $data26 $data27 $data28 $data29

235 236 237
if $rows != 3 then
  return -1
endi
S
Shengliang Guan 已提交
238
if $data(1)[1] != 1 then
239 240
  return -1
endi
S
Shengliang Guan 已提交
241
if $data(1)[8] != 涛思数据1 then
242 243
  return -1
endi
S
Shengliang Guan 已提交
244
if $data(2)[4] != 2.000000000 then
245 246
  return -1
endi
S
Shengliang Guan 已提交
247
if $data(2)[8] != 涛思数据2 then
248 249
  return -1
endi
S
Shengliang Guan 已提交
250
if $data(3)[8] != 涛思数据3 then
251 252 253
  return -1
endi

S
Shengliang Guan 已提交
254 255 256 257 258
sql select t1, count(*), first(c9) from $stb partition by t1 order by t1 asc slimit 3 
if $rows != 3 then
  return -1
endi
if $data(1)[1] != 1 then
259 260
  return -1
endi
S
Shengliang Guan 已提交
261
if $data(1)[2] != 涛思数据1 then
262 263
  return -1
endi
S
Shengliang Guan 已提交
264
if $data(2)[1] != 1 then
265 266
  return -1
endi
S
Shengliang Guan 已提交
267
if $data(2)[2] != 涛思数据2 then
268 269
  return -1
endi
S
Shengliang Guan 已提交
270
if $data(3)[1] != 1 then
271 272
  return -1
endi
S
Shengliang Guan 已提交
273
if $data(3)[2] != 涛思数据3 then
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
  return -1
endi

print ======= too many columns in auto create tables
sql create table tick (ts timestamp , last_prc double , volume int, amount double, oi int , bid_prc1 double, ask_prc1 double, bid_vol1 int, ask_vol1 int , bid_prc2 double, ask_prc2 double, bid_vol2 int, ask_vol2 int , bid_prc3 double, ask_prc3 double, bid_vol3 int, ask_vol3 int , bid_prc4 double, ask_prc4 double, bid_vol4 int, ask_vol4 int , bid_prc5 double, ask_prc5 double, bid_vol5 int, ask_vol5 int , open_prc double, highest_prc double, low_prc double, close_prc double , upper_limit double, lower_limit double) TAGS (ticker BINARY(32), product BINARY(8));
sql show stables

if $rows != 2 then
  return -1
endi

sql insert into tick_000001 ('ts', 'last_prc', 'volume', 'amount', 'oi', 'bid_prc1', 'ask_prc1') using tick tags (000001, Stocks) VALUES (1546391700000, 0.000000, 0, 0.000000, 0, 0.000000, 10.320000);
sql select tbname from tick
if $rows != 1 then
   return -1
endi

#sql drop database $db
#sql show databases
#if $rows != 0 then 
#  return -1
#endi

#[tbase-673]
sql create table tu(ts timestamp, k int);
sql_error create table txu using tu tags(0) values(now, 1);

print =================> [TBASE-675]
sql insert into tu values(1565971200000, 1) (1565971200000,2) (1565971200001, 3)(1565971200001, 4)
sql select * from tu
if $rows != 2 then
    return -1
endi

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