Here’s how to use append() functions.
Description:
Append records in cursor/distributed cursor cs to an entity table T.
Syntax:
T.append(cs) |
Note:
The function append-writes records in cursor cs to entity table T.
When T is a multizone composite table, cs can be an ordinary cursor or a multicursor. Each part of the multicursor cs corresponds to one zone of T uniquely.
If a table has an attached table, appending data to the parent table requires that data be ordered by the key and be unique; otherwise, error will be reported.
The parent table can have records that don’t have matches in a sub table, but the opposite situation is not allowed; otherwise, the appending to an attached table will be disabled.
Parameter:
T |
An entity table/multizone composite table |
cs |
A cursor |
Option:
@i |
Real-time appending whenever a retrieval happens; force an appending when a composite table is closed; by default, an appending is executed only when there is a specified number of new records |
@x |
Calculate the zone table expression is at each append when appending data in a unicursor to a multizone composite table because the cursor could correspond to multiple zones |
Return value:
An entity table
Example:
Ø When parameter T is an entity table:
1 |
=create(k1,v1).record([1,10,2,20,3,30,4,40,10,100]) |
Create a table sequence |
2 |
=create(k1,k2,v2).record([1,1,"a",3,1,"c"]) |
Create a table sequence |
3 |
=create(k1,v3).record([1,"red",1,"blue",2,"red",2, "yellow",2,"red",2,"red",4,"black",4,"red",4,"red", 4,"red",4,"red",4,"red",10,"red"]) |
Create a table sequence |
4 |
=file("D:/ctb.ctx") |
|
5 |
=A4.create(#k1,v1) |
Create the composite table’s base table, where k1 is a dimension and v1 is the base table’s column |
6 |
=A5.attach(table2,#k2,v2) |
Add attached table table2 to A5’s base table; k1 and k2 are the attached table’s dimensions and v2 is its column |
7 |
=A5.attach(table3,v3) |
Add attached table table3 to A5’s base table; k1 is the attached table’s dimension and v3 is its column |
8 |
=A5.append(A1.cursor()) |
Append cursor records to the base table |
9 |
=A6.append(A2.cursor()) |
Append cursor records to attached table table2 |
10 |
=A7.append(A3.cursor()) |
Append cursor records to attached table table3 |
11 |
=A5.cursor().fetch() |
Return data of the base table |
12 |
=A6.cursor().fetch() |
Return data of the attached table table2 |
13 |
=A7.cursor().fetch() |
Return data of the attached table table3 |
Ø When parameter T is a multizone composite table:
|
A |
|
1 |
=connect("demo").cursor("select EID,NAME,GENDER,SALARY from employee where GENDER='M' order by SALARY") |
|
2 |
=connect("demo").cursor("select EID,NAME,GENDER,SALARY from employee where GENDER='F' order by SALARY") |
|
3 |
=[A1,A2].mcursor() |
Return a multicursor |
4 |
=file("emp.ctx":[1,2]) |
Generate a homo-name files group that contain two files 1.emp.ctx and 2.emp.ctx |
5 |
=A4.create@y(#EID,NAME,GENDER,SALARY;if(GENDER=="F",1,2)) |
Create a multizone composite table, where if(GENDER=="F",1,2) is a zone table expression, and @y optioin forces creating a new one even if the target file already exists |
6 |
=A5.append@i(A3) |
Append-write data in A3’s multicursor to A5’s multizone composite table (each part of the multicursor uniquely corresponds to a zone of the multizone composite table), where @i option enables an immediate append |
Ø When a unicursor is appended to a multizone composite table:
|
A |
|
1 |
=connect("demo").cursor("select EID,NAME,GENDER,SALARY from employee") |
Return a unicursor |
2 |
=file("emp.ctx":[1,2]) |
Generate a homo-name files group |
3 |
=A2.create (#EID,NAME,GENDER,SALARY;if(GENDER=="F",1,2)) |
Return a multizone composite table |
4 |
=A3.append@x(A1) |
Use @x to append data in the unicursor to the multizone composite table, where a zone table expression is calculated at each append |
5 |
=A3.close() |
Close the composite table |
Description:
Append-write records of a cursor to a pseudo table.
Syntax:
T.append(cs) |
|
Note:
The function append-writes records of cursor cs to pseudo table T. When source of the pseudo table is multiple composite table files – a sequence of files, append-write the records to the last file.
Parameter:
T |
A pseudo table |
cs |
A cursor |
Option:
@i |
Append-write immediately at exit of the program or at retrieval while, by default, perform the operation when the number of records reaches to a specified number |
@x |
Calculate the zone table expression is at each append when append-writing data in a unicursor to a pseudo table whose source composite table is a multizone one because the cursor could correspond to multiple zones |
Return value:
Pseudo table
Example:
Ø Append-write to a pseudo table:
|
A |
|
1 |
=create(file).record([["D:/file/pseudo/Employee1.ctx","D:/file/Employee2.ctx"]]) |
|
2 |
=pseudo(A1) |
Generate a pseudo table object |
3 |
=create(Dept,AvgSalary).record(["CSD",6400.53])
|
Create a table sequence |
4 |
=A2.append@i(A3.cursor()) |
Append A3’s cursor record to the pseudo table corresponding to the last composite table file Employee2.ctx |
Ø Append-write a unicursor to a pseudo table:
|
A |
|
1 |
=file("append/apps.ctx":[1,2]).create@yi(#eid, deptid;(deptid%2)+1) |
|
2 |
=to(1,10000).new(~:eid,rand(5)+1:deptid) |
Create a table sequence |
3 |
=pseudo(create(file,zone).record(["append/apps.ctx",[1,2]])) |
Generate a pseudo table object |
4 |
=A3.append@ix(A2.cursor()) |
With @x option, append-write A2’s unicursor to two zones of A3’s pseudo table by calculating the zone table expression at each append |