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

$dbPrefix = m_si_db
$tbPrefix = m_si_tb
$mtPrefix = m_si_mt

$tbNum = 10
$rowNum = 20
$totalNum = 200

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

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

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

sleep 100

print =============== step2
$i = 1
$tb = $tbPrefix . $i

sql select tbcol + 1 from $tb 
print ===> $data00 $data10 $data20 $data30
if $data00 != 1.000000000 then 
  return -1
endi

sql select tbcol + 1 from $tb where ts < now + 4m
print ===> $data00
if $data00 != 1.000000000 then 
  return -1
endi

sql select tbcol + 1 from $tb where ts > now + 4m
print ===> $data00
if $data00 != 6.000000000 then 
  return -1
endi

sql select tbcol + 1 from $tb where ts < now + 4m order by ts desc

sql select tbcol + 1 from $tb where ts > now + 4m order by ts desc

sql select tbcol + 1 from $tb where ts < now + 4m order by ts asc

sql select tbcol + 1 from $tb where ts > now + 4m order by ts asc

print =============== step3
$i = 1
$tb = $tbPrefix . $i

sql select tbcol - 1 from $tb 
print ===> $data00
if $data00 != -1.000000000 then 
  return -1
endi

sql select tbcol - 1 from $tb where ts < now + 4m
print ===> $data00
if $data00 != -1.000000000 then 
  return -1
endi

sql select tbcol - 1 from $tb where ts > now + 4m
print ===> $data00
if $data00 != 4.000000000 then 
  return -1
endi

print =============== step4
$i = 1
$tb = $tbPrefix . $i

sql select tbcol * 2 from $tb 
print ===> $data00
if $data00 != 0.000000000 then 
  return -1
endi

sql select tbcol * 2 from $tb where ts < now + 4m
print ===> $data00
if $data00 != 0.000000000 then 
  return -1
endi

sql select tbcol * 2 from $tb where ts > now + 4m
print ===> $data00
if $data00 != 10.000000000 then 
  return -1
endi

print =============== step5
$i = 1
$tb = $tbPrefix . $i

sql select tbcol / 2 from $tb 
print ===> $data00
if $data00 != 0.000000000 then 
  return -1
endi

sql select tbcol / 2 from $tb where ts < now + 4m
print ===> $data10
if $data10 != 0.500000000 then 
  return -1
endi

sql select tbcol / 2 from $tb where ts > now + 4m
print ===> $data00
if $data00 != 2.500000000 then 
  return -1
endi

sql select tbcol / 0 from $tb where ts > now + 4m
print ===> $data00
#if $data00 != 0.000000000 then 
#  return -1
#endi

print =============== step6
$i = 11
$tb = $tbPrefix . $i
sql create table $tb (ts timestamp, tbcol bool)
sql insert into $tb values(now, 0)
sql select tbcol + 2 from $tb -x step6
  return -1
step6:

print =============== step7
$i = $i + 1
$tb = $tbPrefix . $i
sql create table $tb (ts timestamp, tbcol tinyint)
sql insert into $tb values(now, 0);
sql select tbcol + 2 from $tb 
print ===> $data00
if $data00 != 2.000000000 then 
  return -1
endi
sql select tbcol - 2 from $tb 
print ===> $data00
if $data00 != -2.000000000 then 
  return -1
endi
sql select tbcol * 2 from $tb 
print ===> $data00
if $data00 != 0.000000000 then 
  return -1
endi
sql select tbcol / 2 from $tb 
print ===> $data00
if $data00 != 0.000000000 then 
  return -1
endi

print =============== step8
$i = $i + 1
$tb = $tbPrefix . $i
sql create table $tb (ts timestamp, tbcol smallint)
sql insert into $tb values(now, 0);
sql select tbcol + 2 from $tb 
print ===> $data00
if $data00 != 2.000000000 then 
  return -1
endi
sql select tbcol - 2 from $tb 
print ===> $data00
if $data00 != -2.000000000 then 
  return -1
endi
sql select tbcol * 2 from $tb 
print ===> $data00
if $data00 != 0.000000000 then 
  return -1
endi
sql select tbcol / 2 from $tb 
print ===> $data00
if $data00 != 0.000000000 then 
  return -1
endi

print =============== step9
$i = $i + 1
$tb = $tbPrefix . $i
sql create table $tb (ts timestamp, tbcol bigint)
sql insert into $tb values(now, 0);
sql select tbcol + 2 from $tb 
print ===> $data00
if $data00 != 2.000000000 then 
  return -1
endi
sql select tbcol - 2 from $tb 
print ===> $data00
if $data00 != -2.000000000 then 
  return -1
endi
sql select tbcol * 2 from $tb 
print ===> $data00
if $data00 != 0.000000000 then 
  return -1
endi
sql select tbcol / 2 from $tb 
print ===> $data00
if $data00 != 0.000000000 then 
  return -1
endi

print =============== step10
$i = $i + 1
$tb = $tbPrefix . $i
sql create table $tb (ts timestamp, tbcol float)
sql insert into $tb values(now, 0);
sql select tbcol + 2 from $tb 
print ===> $data00
if $data00 != 2.000000000 then 
  return -1
endi
sql select tbcol - 2 from $tb 
print ===> $data00
if $data00 != -2.000000000 then 
  return -1
endi
sql select tbcol * 2 from $tb 
print ===> $data00
if $data00 != 0.000000000 then 
  return -1
endi
sql select tbcol / 2 from $tb 
print ===> $data00
if $data00 != 0.000000000 then 
  return -1
endi

print =============== step11
$i = $i + 1
$tb = $tbPrefix . $i
sql create table $tb (ts timestamp, tbcol double)
sql insert into $tb values(now, 0);
sql select tbcol + 2 from $tb 
print ===> $data00
if $data00 != 2.000000000 then 
  return -1
endi
sql select tbcol - 2 from $tb 
print ===> $data00
if $data00 != -2.000000000 then 
  return -1
endi
sql select tbcol * 2 from $tb 
print ===> $data00
if $data00 != 0.000000000 then 
  return -1
endi
sql select tbcol / 2 from $tb 
print ===> $data00
if $data00 != 0.000000000 then 
  return -1
endi

print =============== step12
$i = $i + 1
$tb = $tbPrefix . $i
sql create table $tb (ts timestamp, tbcol binary(100))
sql insert into $tb values(now, '0');
sql select tbcol + 2 from $tb -x step12
  return -1
step12:

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

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