lastrow_query.sim 5.8 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 17 18
sql connect

$dbPrefix = lr_db
$tbPrefix = lr_tb
$stbPrefix = lr_stb
$tbNum = 8
$rowNum = 60 * 24
$totalNum = $tbNum * $rowNum
$ts0 = 1537146000000
$delta = 60000
print ========== lastrow_query.sim
$i = 0
$db = $dbPrefix . $i
$stb = $stbPrefix . $i

sql use $db

D
fix bug  
dapan1121 已提交
19 20 21
print ========>TD-3231 last_row with group by column error
sql_error select last_row(c1) from $stb group by c1;

S
slguan 已提交
22 23 24 25 26 27 28 29 30 31 32
##### select lastrow from STable with two vnodes, timestamp decreases from tables in vnode0 to tables in vnode1
sql select last_row(*) from $stb
if $rows != 1 then
  return -1
endi
if $data00 != @18-09-25 09:00:00.000@ then
  return -1
endi
if $data01 != 1439 then
  return -1   
endi  
33
if $data02 != NULL then
S
slguan 已提交
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
  return -1  
endi 
if $data03 != 1439.00000 then
  return -1  
endi    
if $data04 != 1439.000000000 then
  return -1
endi
if $data06 != 31 then
  return -1
endi 
if $data07 != 1 then
  return -1
endi
if $data08 != BINARY then
H
hjxilinx 已提交
49
  print expect BINARY actual: $data08
S
slguan 已提交
50 51 52
  return -1
endi
if $data09 != NCHAR then
H
hjxilinx 已提交
53
  print expect NCHAR actual: $data09
S
slguan 已提交
54 55 56
  return -1
endi

H
Haojun Liao 已提交
57
# regression test case 1
H
Haojun Liao 已提交
58 59 60 61
sql select count(*) from lr_tb1 where ts>'2018-09-18 08:45:00.1' and ts<'2018-09-18 08:45:00.2'
if $row != 0 then
  return -1
endi
H
Haojun Liao 已提交
62 63 64 65 66

# regression test case 2
sql select count(*) from lr_db0.lr_stb0 where ts>'2018-9-18 8:00:00' and ts<'2018-9-18 14:00:00' interval(1s) fill(NULL);
if $row != 21600 then
  return -1
H
Haojun Liao 已提交
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
endi

#regression test case 3
sql select t1,t1,count(*),t1,t1 from lr_stb0 where ts>'2018-09-24 00:00:00.000' and ts<'2018-09-25 00:00:00.000' interval(1h) fill(NULL) group by t1 limit 1
if $row != 2 then
  return -1
endi

if $data01 != 7 then
  return -1
endi

if $data02 != 7 then
  return -1
endi

if $data03 != 59 then
  print expect 59, actual: $data03
  return -1
endi

if $data04 != 7 then
  return -1
endi

if $data11 != 8 then
  return -1
endi

if $data12 != 8 then
  return -1
endi

if  $data13 != NULL then
  return -1
endi

sql select t1,t1,count(*),t1,t1 from lr_stb0 where ts>'2018-09-24 00:00:00.000' and ts<'2018-09-25 00:00:00.000' interval(1h) fill(NULL) group by t1 limit 9
if $rows != 18 then
  return -1
endi

sql select t1,t1,count(*),t1,t1 from lr_stb0 where ts>'2018-09-24 00:00:00.000' and ts<'2018-09-25 00:00:00.000' interval(1h) fill(NULL) group by t1 limit 12
if $rows != 24 then
  return -1
endi

sql select t1,t1,count(*),t1,t1 from lr_stb0 where ts>'2018-09-24 00:00:00.000' and ts<'2018-09-25 00:00:00.000' interval(1h) fill(NULL) group by t1 limit 25
if $rows != 48 then
  return -1
endi

sql select t1,t1,count(*),t1,t1 from lr_stb0 where ts>'2018-09-24 00:00:00.000' and ts<'2018-09-25 00:00:00.000' interval(1h) fill(NULL) group by t1 limit 25 offset 1
if $rows != 46 then
  return -1
endi

sql select t1,t1,count(*),tbname,t1,t1,tbname from lr_stb0 where ts>'2018-09-24 00:00:00.000' and ts<'2018-09-25 00:00:00.000' interval(1s) fill(NULL) group by tbname, t1 slimit 2 soffset 0 limit 250000 offset 1
if $rows != 172798 then
  return -1
endi

sql select t1,t1,count(*),tbname,t1,t1,tbname from lr_stb0 where ts>'2018-09-24 00:00:00.000' and ts<'2018-09-25 00:00:00.000' interval(1s) fill(NULL) group by tbname, t1 slimit 1 soffset 1 limit 250000 offset 1
if $rows != 86399 then
  return -1
endi

134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157
sql select t1,t1,count(*),t1,t1 from lr_stb0 where ts>'2018-09-24 00:00:00.000' and ts<'2018-09-25 00:00:00.000' interval(1h) fill(NULL) group by t1 order by ts DESC limit 30
if $rows != 48 then
  return -1
endi

sql select t1,t1,count(*),t1,t1 from lr_stb0 where ts>'2018-09-24 00:00:00.000' and ts<'2018-09-25 00:00:00.000' interval(1h) fill(NULL) group by t1 order by ts DESC limit 2
if $rows != 4 then
  return -1
endi

sql select t1,t1,count(*),tbname,t1,t1,tbname from lr_stb0 where ts>'2018-09-24 00:00:00.000' and ts<'2018-09-25 00:00:00.000' interval(1s) fill(NULL) group by tbname, t1 order by ts desc slimit 1 soffset 1 limit 250000 offset 1
if $rows != 86399 then
  return -1
endi

sql select t1,t1,count(*),t1,t1 from lr_stb0 where ts>'2018-09-24 00:00:00.000' and ts<'2018-09-25 00:00:00.000' interval(1h) fill(NULL) group by t1 order by ts desc limit 1
if $rows != 2 then
  return -1
endi

sql select t1,t1,count(*),t1,t1 from lr_stb0 where ts>'2018-09-24 00:00:00.000' and ts<'2018-09-25 00:00:00.000' interval(1h) fill(NULL) group by t1 order by ts desc limit 25 offset 1
if $rows != 46 then
  return -1
endi
H
Haojun Liao 已提交
158

H
Haojun Liao 已提交
159
print ========>td-1317, empty table last_row query crashed
H
Haojun Liao 已提交
160
sql drop table if exists m1;
H
Haojun Liao 已提交
161 162 163 164
sql create table m1(ts timestamp, k int) tags (a int);
sql create table t1 using m1 tags(1);
sql create table t2 using m1 tags(2);

H
Haojun Liao 已提交
165 166 167 168
sql select last_row(*) from t1
if $rows != 0 then
  return -1
endi
H
Haojun Liao 已提交
169 170 171 172 173 174 175 176 177 178

sql select last_row(*) from m1
if $rows != 0 then
  return -1
endi

sql select last_row(*) from m1 where tbname in ('t1')
if $rows != 0 then
  return -1
endi
H
Haojun Liao 已提交
179 180 181 182 183 184 185 186 187 188 189 190 191 192

sql insert into t1 values('2019-1-1 1:1:1', 1);
print ===================> last_row query against normal table along with ts/tbname
sql select last_row(*),ts,'k' from t1;
if $rows != 1 then
  return -1
endi

print ===================> last_row + user-defined column + normal tables
sql select last_row(ts), 'abc', 1234.9384, ts from t1
if $rows != 1 then
  return -1
endi

H
Haojun Liao 已提交
193 194
if $data01 != @abc@ then
  print expect abc, actual $data02
H
Haojun Liao 已提交
195 196 197
  return -1
endi

H
Haojun Liao 已提交
198
if $data02 !=  1234.938400000 then
H
Haojun Liao 已提交
199 200 201
  return -1
endi

H
Haojun Liao 已提交
202 203
if $data03 != @19-01-01 01:01:01.000@ then
  print expect 19-01-01 01:01:01.000, actual:$data03
H
Haojun Liao 已提交
204 205 206 207 208 209 210 211
  return -1
endi

print ===================> last_row + stable + ts/tag column + condition + udf
sql select last_row(*), ts, 'abc', 123.981, tbname from m1
if $rows != 1 then
  return -1
endi
H
Haojun Liao 已提交
212 213 214 215 216 217 218 219 220 221 222 223

if $data02 != @19-01-01 01:01:01.000@ then
    return -1
endi

if $data03 != @abc@ then
    return -1
endi

if $data04 != 123.981000000 then
    print expect 123.981000000, actual: $data04
    return -1
H
Haojun Liao 已提交
224 225 226 227 228 229
endi

sql create table tu(ts timestamp, k int)
sql select last_row(*) from tu
if $row != 0 then
  return -1
D
fix bug  
dapan1121 已提交
230
endi