system sh/stop_dnodes.sh


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

sleep 3000
sql connect

print ======== step1 
sql create database d3
sql use d3
sql create table tb (ts timestamp, a int)
sql insert into tb values(now-28d, -28)
sql select * from tb order by ts desc
if $rows != 1 then
  return -1
endi
if $data01 != -28 then
  return -1
endi
if $data02 != null then
  return -1
endi
if $data03 != null then
  return -1
endi
if $data04 != null then
  return -1
endi
if $data05 != null then
  return -1
endi
if $data06 != null then
  return -1
endi
if $data07 != null then
  return -1
endi
if $data08 != null then
  return -1
endi

print ======== step2
sleep 2500
sql alter table tb add column b smallint
sql insert into tb values(now-25d, -25, 0)
sleep 3000
sql select * from tb order by ts desc
print $rows
if $rows != 2 then
  return -1
endi
if $data01 != -25 then
  return -1
endi
if $data11 != -28 then
  return -1
endi
if $data02 != 0 then
  return -1
endi
if $data12 != null then
  return -1
endi
if $data13 != null then
  return -1
endi
if $data14 != null then
  return -1
endi
if $data15 != null then
  return -1
endi
if $data16 != null then
  return -1
endi
if $data17 != null then
  return -1
endi
if $data18 != null then
  return -1
endi

print ======== step3
sleep 2500
sql alter table tb add column c tinyint
sql insert into tb values(now-22d, -22, 3, 0)
sleep 3000
sql select * from tb order by ts asc
if $rows != 3 then then
  return -1
endi
if $data01 != -28 then
  return -1
endi
if $data02 != null then
  return -1
endi
if $data03 != null then
  return -1
endi
if $data04 != null then
  return -1
endi
if $data05 != null then
  return -1
endi
if $data06 != null then
  return -1
endi
if $data07 != null then
  return -1
endi
if $data08 != null then
  return -1
endi
if $data11 != -25 then
  return -1
endi
if $data12 != 0 then
  return -1
endi
if $data13 != null then
  return -1
endi
if $data14 != null then
  return -1
endi
if $data15 != null then
  return -1
endi
if $data16 != null then
  return -1
endi
if $data17 != null then
  return -1
endi
if $data18 != null then
  return -1
endi
if $data21 != -22 then
  return -1
endi
if $data22 != 3 then
  return -1
endi
if $data23 != 0 then
  return -1
endi
if $data24 != null then
  return -1
endi
if $data25 != null then
  return -1
endi
if $data26 != null then
  return -1
endi
if $data27 != null then
  return -1
endi
if $data28 != null then
  return -1
endi

print ======== step4
sleep 2500
sql alter table tb add column d int
sql insert into tb values(now-19d, -19, 6, 3, 0)
sleep 3000
sql select * from tb order by ts asc
if $rows != 4 then then
  return -1
endi
if $data01 != -28 then
  return -1
endi
if $data02 != null then
  return -1
endi
if $data03 != null then
  return -1
endi
if $data04 != null then
  return -1
endi
if $data05 != null then
  return -1
endi
if $data06 != null then
  return -1
endi
if $data07 != null then
  return -1
endi
if $data08 != null then
  return -1
endi
if $data11 != -25 then
  return -1
endi
if $data12 != 0 then
  return -1
endi
if $data13 != null then
  return -1
endi
if $data14 != null then
  return -1
endi
if $data15 != null then
  return -1
endi
if $data16 != null then
  return -1
endi
if $data17 != null then
  return -1
endi
if $data18 != null then
  return -1
endi
if $data21 != -22 then
  return -1
endi
if $data22 != 3 then
  return -1
endi
if $data23 != 0 then
  return -1
endi
if $data24 != null then
  return -1
endi
if $data25 != null then
  return -1
endi
if $data26 != null then
  return -1
endi
if $data27 != null then
  return -1
endi
if $data28 != null then
  return -1
endi
if $data31 != -19 then
  return -1
endi
if $data32 != 6 then
  return -1
endi
if $data33 != 3 then
  return -1
endi
if $data34 != 0 then
  return -1
endi
if $data35 != null then
  return -1
endi
if $data36 != null then
  return -1
endi
if $data37 != null then
  return -1
endi
if $data38 != null then
  return -1
endi

print ======== step5
sleep 2500
sql alter table tb add column e bigint
sql insert into tb values(now-16d, -16, 9, 5, 4, 3)
sleep 3000
sql select count(e) from tb
if $data00 != 1 then
  return -1
endi
sql select count(c) from tb
if $data00 != 3 then then
  return -1
endi
sql select * from tb order by ts asc
if $rows != 5 then then
  return -1
endi
if $data01 != -28 then
  return -1
endi
if $data02 != null then
  return -1
endi
if $data03 != null then
  return -1
endi
if $data04 != null then
  return -1
endi
if $data05 != null then
  return -1
endi
if $data06 != null then
  return -1
endi
if $data07 != null then
  return -1
endi
if $data08 != null then
  return -1
endi
if $data11 != -25 then
  return -1
endi
if $data12 != 0 then
  return -1
endi
if $data13 != null then
  return -1
endi
if $data14 != null then
  return -1
endi
if $data15 != null then
  return -1
endi
if $data16 != null then
  return -1
endi
if $data17 != null then
  return -1
endi
if $data18 != null then
  return -1
endi
if $data21 != -22 then
  return -1
endi
if $data22 != 3 then
  return -1
endi
if $data23 != 0 then
  return -1
endi
if $data24 != null then
  return -1
endi
if $data25 != null then
  return -1
endi
if $data26 != null then
  return -1
endi
if $data27 != null then
  return -1
endi
if $data28 != null then
  return -1
endi
if $data31 != -19 then
  return -1
endi
if $data32 != 6 then
  return -1
endi
if $data33 != 3 then
  return -1
endi
if $data34 != 0 then
  return -1
endi
if $data35 != null then
  return -1
endi
if $data36 != null then
  return -1
endi
if $data37 != null then
  return -1
endi
if $data38 != null then
  return -1
endi
if $data41 != -16 then
  return -1
endi
if $data42 != 9 then
  return -1
endi
if $data43 != 5 then
  return -1
endi
if $data44 != 4 then
  return -1
endi
if $data45 != 3 then
  return -1
endi
if $data46 != null then
  return -1
endi
if $data47 != null then
  return -1
endi
if $data48 != null then
  return -1
endi

print ======== step6
sleep 2500
sql alter table tb add column f float
sql insert into tb values(now-13d, -13, 12, 11, 10, 9, 8)
sleep 3000
sql select * from tb order by ts asc
if $rows != 6 then then
  return -1
endi
if $data01 != -28 then
  return -1
endi
if $data02 != null then
  return -1
endi
if $data03 != null then
  return -1
endi
if $data04 != null then
  return -1
endi
if $data05 != null then
  return -1
endi
if $data06 != null then
  return -1
endi
if $data07 != null then
  return -1
endi
if $data08 != null then
  return -1
endi
if $data11 != -25 then
  return -1
endi
if $data12 != 0 then
  return -1
endi
if $data13 != null then
  return -1
endi
if $data14 != null then
  return -1
endi
if $data15 != null then
  return -1
endi
if $data16 != null then
  return -1
endi
if $data17 != null then
  return -1
endi
if $data18 != null then
  return -1
endi
if $data21 != -22 then
  return -1
endi
if $data22 != 3 then
  return -1
endi
if $data23 != 0 then
  return -1
endi
if $data24 != null then
  return -1
endi
if $data25 != null then
  return -1
endi
if $data26 != null then
  return -1
endi
if $data27 != null then
  return -1
endi
if $data28 != null then
  return -1
endi
if $data31 != -19 then
  return -1
endi
if $data32 != 6 then
  return -1
endi
if $data33 != 3 then
  return -1
endi
if $data34 != 0 then
  return -1
endi
if $data35 != null then
  return -1
endi
if $data36 != null then
  return -1
endi
if $data37 != null then
  return -1
endi
if $data38 != null then
  return -1
endi
if $data41 != -16 then
  return -1
endi
if $data42 != 9 then
  return -1
endi
if $data43 != 5 then
  return -1
endi
if $data44 != 4 then
  return -1
endi
if $data45 != 3 then
  return -1
endi
if $data46 != null then
  return -1
endi
if $data47 != null then
  return -1
endi
if $data48 != null then
  return -1
endi
if $data51 != -13 then
  return -1
endi
if $data52 != 12 then
  return -1
endi
if $data53 != 11 then
  return -1
endi
if $data54 != 10 then
  return -1
endi
if $data55 != 9 then
  return -1
endi
if $data56 != 8.00000 then
  return -1
endi
if $data57 != null then
  return -1
endi
if $data58 != null then
  return -1
endi

print ======== step7
sleep 2500
sql alter table tb add column g double
sql insert into tb values(now-10d, -10, 15, 14, 13, 12, 11, 10)
sleep 3000
sql select * from tb order by ts asc
if $rows != 7 then
  return -1
endi
if $data01 != -28 then
  return -1
endi
if $data02 != null then
  return -1
endi
if $data03 != null then
  return -1
endi
if $data04 != null then
  return -1
endi
if $data05 != null then
  return -1
endi
if $data06 != null then
  return -1
endi
if $data07 != null then
  return -1
endi
if $data08 != null then
  return -1
endi
if $data11 != -25 then
  return -1
endi
if $data12 != 0 then
  return -1
endi
if $data13 != null then
  return -1
endi
if $data14 != null then
  return -1
endi
if $data15 != null then
  return -1
endi
if $data16 != null then
  return -1
endi
if $data17 != null then
  return -1
endi
if $data18 != null then
  return -1
endi
if $data21 != -22 then
  return -1
endi
if $data22 != 3 then
  return -1
endi
if $data23 != 0 then
  return -1
endi
if $data24 != null then
  return -1
endi
if $data25 != null then
  return -1
endi
if $data26 != null then
  return -1
endi
if $data27 != null then
  return -1
endi
if $data28 != null then
  return -1
endi
if $data31 != -19 then
  return -1
endi
if $data32 != 6 then
  return -1
endi
if $data33 != 3 then
  return -1
endi
if $data34 != 0 then
  return -1
endi
if $data35 != null then
  return -1
endi
if $data36 != null then
  return -1
endi
if $data37 != null then
  return -1
endi
if $data38 != null then
  return -1
endi
if $data41 != -16 then
  return -1
endi
if $data42 != 9 then
  return -1
endi
if $data43 != 5 then
  return -1
endi
if $data44 != 4 then
  return -1
endi
if $data45 != 3 then
  return -1
endi
if $data46 != null then
  return -1
endi
if $data47 != null then
  return -1
endi
if $data48 != null then
  return -1
endi
if $data51 != -13 then
  return -1
endi
if $data52 != 12 then
  return -1
endi
if $data53 != 11 then
  return -1
endi
if $data54 != 10 then
  return -1
endi
if $data55 != 9 then
  return -1
endi
if $data56 != 8.00000 then
  return -1
endi
if $data57 != null then
  return -1
endi
if $data58 != null then
  return -1
endi
if $data61 != -10 then
  return -1
endi
if $data62 != 15 then
  return -1
endi
if $data63 != 14 then
  return -1
endi
if $data64 != 13 then
  return -1
endi
if $data65 != 12 then
  return -1
endi
if $data66 != 11.00000 then
  return -1
endi
if $data67 != 10.000000000 then
  return -1
endi
if $data68 != null then
  return -1
endi

print ======== step8
sleep 2500
sql alter table tb add column h binary(10)
sql insert into tb values(now-7d, -7, 18, 17, 16, 15, 14, 13, '11')
sleep 3000
sql select * from tb order by ts asc
if $rows != 8 then
  return -1
endi
if $data01 != -28 then
  return -1
endi
if $data02 != null then
  return -1
endi
if $data03 != null then
  return -1
endi
if $data04 != null then
  return -1
endi
if $data05 != null then
  return -1
endi
if $data06 != null then
  return -1
endi
if $data07 != null then
  return -1
endi
if $data08 != null then
  return -1
endi
if $data11 != -25 then
  return -1
endi
if $data12 != 0 then
  return -1
endi
if $data13 != null then
  return -1
endi
if $data14 != null then
  return -1
endi
if $data15 != null then
  return -1
endi
if $data16 != null then
  return -1
endi
if $data17 != null then
  return -1
endi
if $data18 != null then
  return -1
endi
if $data21 != -22 then
  return -1
endi
if $data22 != 3 then
  return -1
endi
if $data23 != 0 then
  return -1
endi
if $data24 != null then
  return -1
endi
if $data25 != null then
  return -1
endi
if $data26 != null then
  return -1
endi
if $data27 != null then
  return -1
endi
if $data28 != null then
  return -1
endi
if $data31 != -19 then
  return -1
endi
if $data32 != 6 then
  return -1
endi
if $data33 != 3 then
  return -1
endi
if $data34 != 0 then
  return -1
endi
if $data35 != null then
  return -1
endi
if $data36 != null then
  return -1
endi
if $data37 != null then
  return -1
endi
if $data38 != null then
  return -1
endi
if $data41 != -16 then
  return -1
endi
if $data42 != 9 then
  return -1
endi
if $data43 != 5 then
  return -1
endi
if $data44 != 4 then
  return -1
endi
if $data45 != 3 then
  return -1
endi
if $data46 != null then
  return -1
endi
if $data47 != null then
  return -1
endi
if $data48 != null then
  return -1
endi
if $data51 != -13 then
  return -1
endi
if $data52 != 12 then
  return -1
endi
if $data53 != 11 then
  return -1
endi
if $data54 != 10 then
  return -1
endi
if $data55 != 9 then
  return -1
endi
if $data56 != 8.00000 then
  return -1
endi
if $data57 != null then
  return -1
endi
if $data58 != null then
  return -1
endi
if $data61 != -10 then
  return -1
endi
if $data62 != 15 then
  return -1
endi
if $data63 != 14 then
  return -1
endi
if $data64 != 13 then
  return -1
endi
if $data65 != 12 then
  return -1
endi
if $data66 != 11.00000 then
  return -1
endi
if $data67 != 10.000000000 then
  return -1
endi
if $data68 != null then
  return -1
endi
if $data71 != -7 then
  return -1
endi
if $data72 != 18 then
  return -1
endi
if $data73 != 17 then
  return -1
endi
if $data74 != 16 then
  return -1
endi
if $data75 != 15 then
  return -1
endi
if $data76 != 14.00000 then
  return -1
endi
if $data77 != 13.000000000 then
  return -1
endi
if $data78 != 11 then
  return -1
endi
if $data79 != null then
  return -1
endi

print ======== step9
system sh/exec.sh -n dnode1 -s stop -x SIGINT
sleep 5000
system sh/exec.sh -n dnode1 -s start
sleep 5000

sql select * from tb
if $rows != 8 then
  return -1
endi
if $data01 != -28 then
  return -1
endi
if $data02 != null then
  return -1
endi
if $data03 != null then
  return -1
endi
if $data04 != null then
  return -1
endi
if $data05 != null then
  return -1
endi
if $data06 != null then
  return -1
endi
if $data07 != null then
  return -1
endi
if $data08 != null then
  return -1
endi
if $data11 != -25 then
  return -1
endi
if $data12 != 0 then
  return -1
endi
if $data13 != null then
  return -1
endi
if $data14 != null then
  return -1
endi
if $data15 != null then
  return -1
endi
if $data16 != null then
  return -1
endi
if $data17 != null then
  return -1
endi
if $data18 != null then
  return -1
endi
if $data21 != -22 then
  return -1
endi
if $data22 != 3 then
  return -1
endi
if $data23 != 0 then
  return -1
endi
if $data24 != null then
  return -1
endi
if $data25 != null then
  return -1
endi
if $data26 != null then
  return -1
endi
if $data27 != null then
  return -1
endi
if $data28 != null then
  return -1
endi
if $data31 != -19 then
  return -1
endi
if $data32 != 6 then
  return -1
endi
if $data33 != 3 then
  return -1
endi
if $data34 != 0 then
  return -1
endi
if $data35 != null then
  return -1
endi
if $data36 != null then
  return -1
endi
if $data37 != null then
  return -1
endi
if $data38 != null then
  return -1
endi
if $data41 != -16 then
  return -1
endi
if $data42 != 9 then
  return -1
endi
if $data43 != 5 then
  return -1
endi
if $data44 != 4 then
  return -1
endi
if $data45 != 3 then
  return -1
endi
if $data46 != null then
  return -1
endi
if $data47 != null then
  return -1
endi
if $data48 != null then
  return -1
endi
if $data51 != -13 then
  return -1
endi
if $data52 != 12 then
  return -1
endi
if $data53 != 11 then
  return -1
endi
if $data54 != 10 then
  return -1
endi
if $data55 != 9 then
  return -1
endi
if $data56 != 8.00000 then
  return -1
endi
if $data57 != null then
  return -1
endi
if $data58 != null then
  return -1
endi
if $data61 != -10 then
  return -1
endi
if $data62 != 15 then
  return -1
endi
if $data63 != 14 then
  return -1
endi
if $data64 != 13 then
  return -1
endi
if $data65 != 12 then
  return -1
endi
if $data66 != 11.00000 then
  return -1
endi
if $data67 != 10.000000000 then
  return -1
endi
if $data68 != null then
  return -1
endi
if $data71 != -7 then
  return -1
endi
if $data72 != 18 then
  return -1
endi
if $data73 != 17 then
  return -1
endi
if $data74 != 16 then
  return -1
endi
if $data75 != 15 then
  return -1
endi
if $data76 != 14.00000 then
  return -1
endi
if $data77 != 13.000000000 then
  return -1
endi
if $data78 != 11 then
  return -1
endi
