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/cfg.sh -n dnode1 -c numOfTotalVnodes -v 8
system sh/cfg.sh -n dnode1 -c maxtablesPerVnode -v 4
system sh/exec.sh -n dnode1 -s start

sleep 3000
sql connect

print ======================== dnode1 start

$dbPrefix = m1v_db
$tbPrefix = m1v_tb
$mtPrefix = m1v_mt
$stPrefix = m1v_st
$tbNum = 10
$rowNum = 20
$totalNum = 200

print =============== step1
$i = 0
$db = $dbPrefix . $i
$mt = $mtPrefix . $i
$st = $stPrefix . $i

sql drop databae $db -x step1
step1:
sql create database $db
sql use $db
sql create table $mt (ts timestamp, tbcol int, tbcol2 float) TAGS(tgcol int)

$i = 0
while $i < $tbNum
  $tb = $tbPrefix . $i
  sql create table $tb using $mt tags( $i )
  
  $x = -1440
  $y = 0
  while $y < $rowNum
    $ms = $x . m 
    sql insert into $tb values (now $ms , $y , $y ) 
    $x = $x + 1
	$y = $y + 1
  endw 
 
  $i = $i + 1
endw 

sleep 100

print =============== step2 c1

sql select count(*) from $mt interval(1d)
print select count(*) from $mt interval(1d) ===> $data00 $data01
if $data01 != 200 then 
  return -1
endi

$st = $stPrefix . c1
sql create table $st as select count(*) from $mt interval(1d)

print =============== step3 c2
sql select count(tbcol) from $mt interval(1d)
print select count(tbcol) from $mt interval(1d) ===> $data00 $data01
if $data01 != 200 then 
  return -1
endi

$st = $stPrefix . c2
sql create table $st as select count(tbcol) from $mt interval(1d)

print =============== step4 c3
sql select count(tbcol2) from $mt interval(1d)
print select count(tbcol2) from $mt interval(1d) ===> $data00 $data01
if $data01 != 200 then 
  return -1
endi

$st = $stPrefix . c3
sql create table $st as select count(tbcol2) from $mt interval(1d)

print =============== step5 avg
sql select avg(tbcol) from $mt interval(1d)
print select avg(tbcol) from $mt interval(1d) ===> $data00 $data01
if $data01 != 9.500000000 then 
  return -1
endi

$st = $stPrefix . av
sql create table $st as select avg(tbcol) from $mt interval(1d)

print =============== step6 su
sql select sum(tbcol) from $mt interval(1d)
print select sum(tbcol) from $mt interval(1d) ===> $data00 $data01
if $data01 != 1900 then 
  return -1
endi

$st = $stPrefix . su
sql create table $st as select sum(tbcol) from $mt interval(1d)

print =============== step7 mi
sql select min(tbcol) from $mt interval(1d)
print select min(tbcol) from $mt interval(1d) ===> $data00 $data01
if $data01 != 0 then 
  return -1
endi

$st = $stPrefix . mi
sql create table $st as select min(tbcol) from $mt interval(1d)

print =============== step8 ma
sql select max(tbcol) from $mt interval(1d)
print select max(tbcol) from $mt interval(1d) ===> $data00 $data01
if $data01 != 19 then 
  return -1
endi

$st = $stPrefix . ma
sql create table $st as select max(tbcol) from $mt interval(1d)

print =============== step9 fi
sql select first(tbcol) from $mt interval(1d)
print select first(tbcol) from $mt interval(1d) ===> $data00 $data01
if $data01 != 0 then 
  return -1
endi

$st = $stPrefix . fi
sql create table $st as select first(tbcol) from $mt interval(1d)

print =============== step10 la
sql select last(tbcol) from $mt interval(1d)
print select last(tbcol) from $mt interval(1d) ===> $data00 $data01
if $data01 != 19 then 
  return -1
endi

$st = $stPrefix . la
sql create table $st as select last(tbcol) from $mt interval(1d)

print =============== step11 wh
sql select count(tbcol) from $mt where ts < now + 4m interval(1d)
print select count(tbcol) from $mt where ts < now + 4m interval(1d) ===> $data00 $data01
if $data01 != 200 then 
  return -1
endi

$st = $stPrefix . wh
#sql create table $st as select count(tbcol) from $mt where ts < now + 4m interval(1d)

print =============== step12 as
sql select count(tbcol) from $mt interval(1d)
print select count(tbcol) from $mt interval(1d) ===> $data00 $data01
if $data01 != 200 then 
  return -1
endi

$st = $stPrefix . as
sql create table $st as select count(tbcol) as c from $mt interval(1d)

print =============== step13
print sleep 120 seconds
sleep 120000 

print =============== step14
$st = $stPrefix . c1
sql select * from $st
print ===> select * from $st ===> $data00 $data01
if $data01 != 200 then 
  return -1
endi

$st = $stPrefix . c2
sql select * from $st
print ===> select * from $st ===> $data00 $data01
if $data01 != 200 then 
  return -1
endi

$st = $stPrefix . c3
sql select * from $st
print ===> select * from $st ===> $data00 $data01
if $data01 != 200 then 
  return -1
endi

$st = $stPrefix . av
sql select * from $st
print ===> select * from $st ===> $data00 $data01
if $data01 != 9.500000000 then 
  return -1
endi

$st = $stPrefix . su
sql select * from $st
print ===> select * from $st ===> $data00 $data01
if $data01 != 1900 then 
  return -1
endi

$st = $stPrefix . mi
sql select * from $st
print ===> select * from $st ===> $data00 $data01
if $data01 != 0 then 
  return -1
endi

$st = $stPrefix . ma
sql select * from $st
print ===> select * from $st ===> $data00 $data01
if $data01 != 19 then 
  return -1
endi

$st = $stPrefix . fi
sql select * from $st
print ===> select * from $st ===> $data00 $data01
if $data01 != 0 then 
  return -1
endi

$st = $stPrefix . la
sql select * from $st
print ===> select * from $st ===> $data00 $data01
if $data01 != 19 then 
  return -1
endi

$st = $stPrefix . wh
#sql select * from $st
#print ===> select * from $st ===> $data00 $data01
#if $data01 != 200 then 
#  return -1
#endi

$st = $stPrefix . as
sql select * from $st
print ===> select * from $st ===> $data00 $data01
if $data01 != 200 then 
  return -1
endi
