system sh/stop_dnodes.sh
system sh/ip.sh -i 1 -s up
system sh/deploy.sh -n dnode1 -m 192.168.0.1 -i 192.168.0.1
system sh/cfg.sh -n dnode1 -c commitLog -v 0
system sh/exec.sh -n dnode1 -s start
sleep 3000
sql connect

$dbPrefix = ca_db
$tbPrefix = ca_tb
$stbPrefix = ca_stb
$tbNum = 10
$rowNum = 10000
$totalNum = $tbNum * $rowNum
$ts0 = 1537146000000
$delta = 600000
print ========== col_arithmetic_operation.sim
$i = 0
$db = $dbPrefix . $i
$stb = $stbPrefix . $i

sql drop database $db -x step1
step1:
sql create database $db
sql use $db
sql create table $stb (ts timestamp, c1 int, c2 bigint, c3 float, c4 double, c5 smallint, c6 tinyint, c7 bool, c8 binary(10), c9 nchar(10)) tags(t1 int)

$i = 0
$ts = $ts0
$halfTbNum = $tbNum / 2
while $i < $halfTbNum
  $tbId = $i + $halfTbNum
  $tb = $tbPrefix . $i
  $tb1 = $tbPrefix . $tbId
  sql create table $tb using $stb tags( $i )
  sql create table $tb1 using $stb tags( $tbId )
  
  $x = 0
  while $x < $rowNum
    $xs = $x * $delta
    $ts = $ts0 + $xs
    $c = $x / 10
    $c = $c * 10
    $c = $x - $c
    $binary = 'binary . $c
    $binary = $binary . '
    $nchar = 'nchar . $c
    $nchar = $nchar . '
    sql insert into $tb values ( $ts , $c , $c , $c , $c , $c , $c , true, $binary , $nchar ) 
    sql insert into $tb1 values ( $ts , NULL , $c , NULL , $c , NULL , $c , NULL, NULL , $nchar ) 
    $x = $x + 1
  endw 
  $i = $i + 1
endw 

##### select from table
$tb = $tbPrefix . 0
## TBASE-344
sql select c1*2 from $tb
if $rows != $rowNum then
  return -1
endi
if $data00 != 0.000000000 then
  return -1
endi
if $data10 != 2.000000000 then
  return -1
endi
if $data20 != 4.000000000 then
  return -1
endi
if $data90 != 18.000000000 then
  return -1
endi

sql select c4*1+1/2 from $tb
if $rows != $rowNum then
  return -1
endi
if $data00 != 0.500000000 then
  return -1
endi
if $data10 != 1.500000000 then
  return -1
endi
if $data90 != 9.500000000 then
  return -1
endi

#### illegal operations
sql_error select max(c2*2) from $tb
sql_error select 2*min(c1) from $tb
sql_error select max(c1-c2) from $tb
