first_last_query.sim 5.3 KB
Newer Older
H
Haojun Liao 已提交
1
sleep 100
S
slguan 已提交
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
sql connect

$dbPrefix = first_db
$tbPrefix = first_tb
$stbPrefix = first_stb
$tbNum = 10
$rowNum = 2000
$totalNum = $tbNum * $rowNum
$ts0 = 1537146000000
$delta = 60000
print ========== first_last_query.sim
$i = 0
$db = $dbPrefix . $i
$stb = $stbPrefix . $i

S
TD-1530  
Shengliang Guan 已提交
17
print use $db
S
slguan 已提交
18 19 20 21 22 23
sql use $db

##### select first/last from table
## TBASE-331
print ====== select first/last from table
$tb = $tbPrefix . 0
S
TD-1530  
Shengliang Guan 已提交
24
print select first(*) from $tb
S
slguan 已提交
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
sql select first(*) from $tb
if $rows != 1 then
  return -1
endi
if $data00 != @18-09-17 08:59:00.000@ then
  return -1
endi
if $data01 != 0 then
  return -1   
endi  
if $data02 != 0 then
  return -1  
endi 
print data03 = $data03
if $data03 != 0.00000 then
H
Haojun Liao 已提交
40
  print expect 0.00000, actual: $data03
S
slguan 已提交
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
  return -1  
endi    
if $data04 != 0.000000000 then
  return -1
endi
if $data05 != 0 then
  return -1
endi 
if $data06 != 0 then
  return -1
endi
if $data07 != 1 then
  return -1
endi
if $data08 != BINARY then
H
hjxilinx 已提交
56
  print expect BINARY, actual: $data08
S
slguan 已提交
57 58
  return -1
endi
59
#if $data09 != NULL then
S
slguan 已提交
60 61 62 63
if $data09 != NCHAR then
  return -1
endi

S
TD-1530  
Shengliang Guan 已提交
64
print select last(*) from $tb
S
slguan 已提交
65 66 67 68 69 70 71
sql select last(*) from $tb
if $rows != 1 then
  return -1
endi
if $data00 != @18-09-18 01:40:00.000@ then
  return -1   
endi  
H
Haojun Liao 已提交
72

S
slguan 已提交
73 74
if $data01 != 999 then
  return -1   
H
Haojun Liao 已提交
75 76
endi

S
slguan 已提交
77 78
if $data02 != 999 then
  return -1  
H
Haojun Liao 已提交
79 80
endi

S
slguan 已提交
81 82 83
if $data03 != 999.00000 then
  return -1  
endi    
H
Haojun Liao 已提交
84

S
slguan 已提交
85 86 87
if $data04 != 999.000000000 then
  return -1
endi
H
Haojun Liao 已提交
88

S
slguan 已提交
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
#if $data05 != NULL then
if $data05 != 999 then
  return -1
endi 
#if $data06 != NULL then
if $data06 != 103 then
  return -1
endi
#if $data07 != NULL then
if $data07 != 1 then
  return -1
endi
#if $data08 != NULL then
if $data08 != BINARY then
  return -1
endi
#if $data09 != NULL then
if $data09 != NCHAR then
  return -1
endi

### test if first works for committed data. An 'order by ts desc' clause should be present, and queried data should come from at least 2 file blocks
$tb = $tbPrefix . 9
sql select first(ts), first(c1) from $tb where ts < '2018-10-17 10:00:00.000' order by ts asc
if $rows != 1 then 
  return -1
endi
if $data00 != @18-09-17 09:00:00.000@ then
  return -1
endi
if $data01 != 0 then
  return -1
endi

$tb = $tbPrefix . 9
sql select first(ts), first(c1) from $tb where ts < '2018-10-17 10:00:00.000' order by ts desc 
if $rows != 1 then 
  return -1
endi
if $data00 != @18-09-17 09:00:00.000@ then
  return -1
endi
if $data01 != 0 then
  return -1
endi
134

H
Haojun Liao 已提交
135
print =============> add check for out of range first/last query
136 137 138 139 140 141 142 143
sql select first(ts),last(ts) from first_tb4 where ts>'2018-9-18 1:40:01';
if $row != 0 then
  return -1
endi

sql select first(ts),last(ts) from first_tb4 where ts<'2018-9-17 8:50:0';
if $row != 0 then
  return -1
H
Haojun Liao 已提交
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 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
endi

#first/last mix up query
#select first(size),last(size) from stest interval(1d) group by tbname;
print =====================>td-1477

sql create table stest(ts timestamp,size INT,filenum INT) tags (appname binary(500),tenant binary(500));
sql insert into test1 using stest tags('test1','aaa') values ('2020-09-04 16:53:54.003',210,3);
sql insert into test2 using stest tags('test1','aaa') values ('2020-09-04 16:53:56.003',210,3);
sql insert into test11 using stest tags('test11','bbb') values ('2020-09-04 16:53:57.003',210,3);
sql insert into test12 using stest tags('test11','bbb') values ('2020-09-04 16:53:58.003',210,3);
sql insert into test21 using stest tags('test21','ccc') values ('2020-09-04 16:53:59.003',210,3);
sql insert into test22 using stest tags('test21','ccc') values ('2020-09-04 16:54:54.003',210,3);
sql select sum(size) from stest group by appname;
if $rows != 3 then
  return -1
endi

if $data00 != 420 then
  return -1
endi
if $data10 != 420 then
  return -1
endi
if $data20 != 420 then
  return -1
endi

if $data01 != @test1@ then
return -1
endi
if $data11 != @test11@ then
return -1
endi
if $data21 != @test21@ then
return -1
endi

sql select sum(size) from stest interval(1d) group by appname;
if $rows != 3 then
 return -1
endi

#2020-09-04 00:00:00.000 |                   420 | test1                          |
#2020-09-04 00:00:00.000 |                   420 | test11                         |
#2020-09-04 00:00:00.000 |                   420 | test21                         |
if $data00 != @20-09-04 00:00:00.000@ then
 return -1
endi

if $data10 != @20-09-04 00:00:00.000@ then
 return -1
endi

if $data20 != @20-09-04 00:00:00.000@ then
 return -1
endi

if $data01 != 420 then
 print expect 420 , actual $data01
 return -1
endi

if $data11 != 420 then
 return -1
endi

if $data21 != 420 then
 return -1
endi

if $data02 != @test1@ then
return -1
endi
if $data12 != @test11@ then
return -1
endi
if $data22 != @test21@ then
return -1
endi

print ===================>td-1477, one table has only one block occurs this bug.
sql select first(size),count(*),LAST(SIZE) from stest where tbname in ('test1', 'test2') interval(1d) group by tbname;
if $rows != 2 then
 return -1
endi

if $data00 != @20-09-04 00:00:00.000@ then
  return -1
endi

if $data01 != 210 then
  return -1
endi

if $data02 != 1 then
  return -1
endi

if $data03 != 210 then
 return -1
endi

if $data04 != @test1@ then
  return -1
endi

if $data10 != @20-09-04 00:00:00.000@ then
  return -1
endi

if $data11 != 210 then
  return -1
endi

if $data12 != 1 then
  return -1
endi

if $data13 != 210 then
 return -1
endi

H
Haojun Liao 已提交
267 268
if $data14 != @test2@ then
  print expect test2 , actual: $data14
H
Haojun Liao 已提交
269
  return -1
H
Haojun Liao 已提交
270 271 272
endi

sql drop table stest