system sh/stop_dnodes.sh

system sh/deploy.sh -n dnode1 -i 1
system sh/cfg.sh -n dnode1 -c walLevel -v 0
system sh/exec.sh -n dnode1 -s start

sleep 2000
sql connect

print =================== step1
sql create database db
sql use db
sql create table mt (ts timestamp, k int, h binary(20), t bigint, s float, f double, x smallint, y tinyint, z bool) tags (a int, b binary(20), c bigint)
sql create table tb using mt tags (0, '1', 2)

sql insert into tb values(now -200d, 200, '1', 2, 3, 4, 5, 6, true);
sql insert into tb values(now -100d, 100, '1', 2, 3, 4, 5, 6, true);
sql insert into tb values(now -30d,  30,  '1', 2, 3, 4, 5, 6, true);
sql insert into tb values(now -20d,  20,  '1', 2, 3, 4, 5, 6, true);
sql insert into tb values(now -10d,  10,  '1', 2, 3, 4, 5, 6, true);
sql insert into tb values(now -5d,   5,   '1', 2, 3, 4, 5, 6, true);
sql insert into tb values(now -1d,   1,   '1', 2, 3, 4, 5, 6, true);
sql insert into tb values(now,       0,   '1', 2, 3, 4, 5, 6, true);

sql select * from db.mt
if $rows != 8 then 
  return -1
endi

sql select * from db.tb
if $rows != 8 then 
  return -1
endi

sql select count(*) from db.mt
if $data00 != 8 then 
  return -1
endi

sql select count(*), last(ts), min(k), max(k), avg(k) from db.mt where a=0 and ts>="2016-4-29 8:0:0" and ts < "2018-7-18 8:9:0" interval(1d) fill(value, 1)
sql select count(*), last(ts), min(k), max(k), avg(k) from db.mt where a=0 and ts>="2016-4-29 8:0:0" and ts < "2018-7-18 8:9:0" interval(1d) fill(value, 1)

print =================== step2
system sh/exec.sh -n dnode1 -s stop -x SIGINT
sleep 3000
system sh/exec.sh -n dnode1 -s start
sleep 2000

print =================== step3
sql select * from db.mt
if $rows != 8 then 
  return -1
endi

sql select * from db.tb
if $rows != 8 then 
  return -1
endi

sql select count(*) from db.mt
if $data00 != 8 then 
  return -1
endi
