Add Columns

Use function addColumn to add columns to a stream table or a DFS table.

ID=1..6
x=1..6\5
t1=table(ID, x)
db=database("dfs://rangedb",RANGE,  1 4 7)
pt = db.createPartitionedTable(t1, `pt, `ID)
pt.append!(t1);

addColumn(pt,["price", "qty"],[DOUBLE, INT]);

After using addColumn and before data with the new schema is inserted, we can still insert data with the old schema.

t2=table(1 as ID, 1.2 as x)
pt.append!(t2)
select * from pt;
ID x price qty
1 0.2
2 0.4
3 0.6
1 1.2
4 0.8
5 1
6 1.2

After data with the new schema is inserted, however, data with the old schema can no longer be inserted.

t3=table(1 as ID, 1.6 as x, 10.0 as price, 6 as qty)
pt.append!(t3)
select * from pt;
ID x price qty
1 0.2
2 0.4
3 0.6
1 1.2
1 1.6 10 6
4 0.8
5 1
6 1.2
t4=table(2 as ID, 2.2 as x)
pt.append!(t4);
// output
The data to append contains fewer columns than the schema.