system sh/stop_dnodes.sh
system sh/deploy.sh -n dnode1 -i 1
system sh/exec.sh -n dnode1 -s start
sql connect

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

$dbPrefix = ta_fi_db
$tbPrefix = ta_fi_tb
$mtPrefix = ta_fi_mt
$tbNum = 10
$rowNum = 20
$totalNum = 200

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

sql create database $db
sql use $db
sql create table $mt (ts timestamp, tbcol int) TAGS(tgcol binary(10))

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

print =============== step2
sql select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from $mt where tgcol = '1' 
print $data00 $data01 $data02 $data03 $data04 $data05 $data06 
if $data00 != 100 then 
  return -1
endi

sql select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from $mt where tg = '1' -x step2
  return -1
step2:

print =============== step3
sql select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from $mt where noexist = '1' -x step3
  return -1
step3:

print =============== step4
sql select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from $mt where tbcol = '1'  
if $rows != 1 then 
  return -1
endi
if $data00 != 10 then 
  return -1
endi

print =============== step5
sql select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from $mt
print $data00 $data01 $data02 $data03 $data04 $data05 $data06 
if $data00 != 200 then 
  return -1
endi

print =============== step6
sql select count(tbcol), avg(cc), sum(xx), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from $mt -x step6
  return -1
step6:

print =============== step7
sql select count(tgcol), avg(tgcol), sum(tgcol), min(tgcol), max(tgcol), first(tgcol), last(tgcol) from $mt -x step7
  return -1
step7:

print =============== step8
sql select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from $mt group by tbcol

print =============== step9
sql select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from $mt group by noexist  -x step9
  return -1
step9:

print =============== step10
sql select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from $mt group by tgcol 
print $data00 $data01 $data02 $data03 $data04 $data05 $data06 
if $data00 != 100 then 
  return -1
endi

print =============== step11
sql select count(tbcol) as c from $mt group by tbcol

print =============== step12
sql select count(tbcol) as c from $mt group by noexist -x step12
  return -1
step12:

print =============== step13
sql select count(tbcol) as c from $mt group by tgcol
print $data00 
if $data00 != 100 then 
  return -1
endi

print =============== step14
sql select count(tbcol) as c from $mt where ts > 1000 group by tgcol
print $data00 $data01 $data02 $data03 $data04 $data05 $data06 
if $data00 != 100 then
  print expect 100, actual $data00
  return -1
endi

print =============== step15
sql select count(tbcol) as c from $mt where noexist < 1  group by tgcol -x step15
  return -1
step15:

print =============== step16
sql select count(tbcol) as c from $mt where tgcol = '1' group by tgcol
print $data00 $data01 $data02 $data03 $data04 $data05 $data06 
if $data00 != 100 then 
  return -1
endi

print =============== clear
sql drop database $db
sql show databases
if $rows != 2 then 
  return -1
endi

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