system sh/stop_dnodes.sh
system sh/deploy.sh -n dnode1 -i 1
system sh/exec.sh -n dnode1 -s start
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
print $data00 $data01 $data02 $data03 $data04 $data05 $data06

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
sql alter table tb add column b smallint
sql insert into tb values(now-25d, -25, 0)
sql select * from tb order by ts desc
print $data00 $data01 $data02 $data03 $data04 $data05 $data06
print $data10 $data11 $data12 $data13 $data14 $data15 $data16
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
sql alter table tb add column c tinyint
sql insert into tb values(now-22d, -22, 3, 0)
sql select * from tb order by ts asc
print $data00 $data01 $data02 $data03 $data04 $data05 $data06
print $data10 $data11 $data12 $data13 $data14 $data15 $data16
print $data20 $data21 $data22 $data23 $data24 $data25 $data26
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
sql alter table tb add column d int
sql insert into tb values(now-19d, -19, 6, 3, 0)
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
sql alter table tb add column e bigint
sql insert into tb values(now-16d, -16, 9, 5, 4, 3)
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
sql alter table tb add column f float
sql insert into tb values(now-13d, -13, 12, 11, 10, 9, 8)
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
sql alter table tb add column g double
sql insert into tb values(now-10d, -10, 15, 14, 13, 12, 11, 10)
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
sql alter table tb add column h binary(10)
sql insert into tb values(now-7d, -7, 18, 17, 16, 15, 14, 13, '11')
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
system sh/exec.sh -n dnode1 -s start

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

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