Here’s how to use append() functions.
Description:
Append records in a cursor/table sequence to an entity table.
Syntax:
T.append(cs)
Note:
The function append-writes records in cursor/table sequence cs to entity table T.
When T is a multizone composite table, cs can be 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/table sequence |
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 |
@m |
Write data through merge-append; append data after the last record by default; do not support attached tables for the time being |
@y |
Read records of cs to form an in-memory zone table but do not write the data to the external storage; mutually exclusive with other options; Return a multizone composite table consisting of the existing composite table and the in-memory zone table when T is a uni-composite table |
Return value:
Entity table
Example:
When parameter T is an entity table:
|
A |
|
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. |
|
A |
|
1 |
=demo.query("select EID,NAME from employee where EID>495") |
Return a table sequence:
|
2 |
=file("apm.ctx") |
|
3 |
=A2.create@y(#EID,NAME) |
Create a composite table. |
4 |
=A3.append(A1) |
Append data of A1’s table sequence to the composite table |
5 |
=create(EID,NAME).record([5,"Ashley"]) |
Return a table sequence.
|
6 |
=A3.append@m(A5) |
Append data of A5’s table sequence to the composite table; as @m option works, write data through merge-append. |
7 |
=A6.import() |
Import data from the composite table:
|
8 |
>A3.close() |
Close the composite table. |
Write data to the memory:
|
A |
|
1 |
=demo.query("select EID,NAME from employee where EID>495") |
Return a table sequence:
|
2 |
=file("apm.ctx") |
|
3 |
=A2.create@y(#EID,NAME) |
Create a composite table. |
4 |
=A3.append(A1) |
Append table sequence A1’s data to the composite table. |
5 |
=create(EID,NAME).record([5,"Ashley"]) |
Return a table sequence:
|
6 |
=A3.append@y(A5) |
Append table sequence A5’s data to the composite table; @y option enables reading A5’s data, writing it to the memory and returning a multizone composite table consisting of the uni-composite table and the in-memory zone table. |
7 |
=A6.import() |
View data in table A6, which contains A5’s data that has been appended.
|
8 |
>A3.close() |
Close the composite table. |
9 |
=A2.open().import() |
As A6 uses @y option, the appended data isn’t written to the external memory and a view shows that the composite table does not contain A5’s data.
|
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.
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 |
@y |
Write the appended records to the memory instead of keeping it in the external memory |
Return value:
Pseudo table
Example:
Append-write to a pseudo table:
|
A |
|
1 |
=create(file).record(["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. |
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. |
Use @y option to write the appended records to the memory:
|
A |
|
1 |
=create(file).record(["em.ctx"]) |
Return the pseudo table definition record. |
2 |
=pseudo(A1) |
Generate a pseudo table definition object. |
3 |
=A2.import() |
Read data from the pseudo table.
|
4 |
=create(EID,NAME).record([0,"AAAA"]) |
Return a table sequence:
|
5 |
=A2.append@y(A4.cursor()) |
Append table sequence A4’s records to pseudo table A2; @y option enables converting A4’s data to an in-memory zone table and writing it to the memory. |
6 |
=A2.import() |
Import data from the pseudo table, where there are records appended in A5.
|
7 |
>A2.close() |
Close the pseudo table. |
8 |
=pseudo(A1).import() |
Import data from pseudo table A1; as A5 uses @y option and the appended data isn’t written to the external memory, the imported pseudo table data here does not contain A4’s data; the result is the same as A3’s:
|