alter1.sim 2.3 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
system sh/stop_dnodes.sh
system sh/deploy.sh -n dnode1 -i 1
system sh/exec.sh -n dnode1 -s start
sql connect

$dbPrefix = alt1_db

print ========== alter1.sim
$db = $dbPrefix

sql drop database if exists $db
sql create database $db
sql use $db

sql create table stb (ts timestamp, speed double, mileage double) tags(carId int, carModel int)
sql create table car1 using stb tags (1, 1)
sql create table car2 using stb tags (2, 1)
sql create table car3 using stb tags (3, 2)
sql insert into car1 values (now-1s, 100, 10000)
sql insert into car2 values (now, 100, 10000)
sql insert into car3 values (now, 100, 10000)
sql insert into car1 values (now, 120, 11000)
print ================== add a column
sql alter table stb add column c1 int
sql describe stb
if $rows != 6 then
  return -1
endi

sql select * from stb
print rows = $rows
if $rows != 4 then
  return -1
endi
if $data03 != NULL then
  return -1
endi
if $data13 != NULL then
  return -1
endi
if $data23 != NULL then
  return -1
endi
if $data33 != NULL then
  return -1
endi

sql select c1 from stb
if $rows != 4 then
  return -1
endi
if $data00 != NULL then
  return -1
endi
if $data30 != NULL then
  return -1
endi

sql select c1+speed from stb
if $rows != 4 then
  return -1
endi

sql select c1+speed from car1
if $rows != 2 then
  return -1
endi
if $data00 != NULL then
  return -1
endi
if $data10 != NULL then
  return -1
endi

sql select * from car1
if $rows != 2 then
  return -1
endi
if $data03 != NULL then
  return -1
endi
if $data13 != NULL then
  return -1
endi

print ================== insert values into table
S
Shengliang Guan 已提交
87
sql insert into car1 values (now, 1, 1,1 ) (now +1s, 2,2,2) car2 values (now, 1,3,3)
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105

sql select c1+speed from stb where c1 > 0
if $rows != 3 then
  return -1
endi

print ================== add a tag
sql alter table stb add tag t1 int
sql describe stb
if $rows != 7 then
  return -1
endi
if $data60 != t1 then
  return -1
endi

print ================== change a tag value
sql alter table car1 set tag carid=10
S
Shengliang Guan 已提交
106
sql select distinct carId, carmodel from car1
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
if $rows != 1 then
  return -1
endi

if $data00 != 10 then
  return -1
endi

sql select * from stb where carid = 10
if $rows != 4 then
  return -1
endi

sql alter table car2 set tag carmodel = 2
sql select * from stb where carmodel = 2
print $rows
if $rows != 3 then
  return -1
endi

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