append()

Read(409) Label: append,

Here’s how to use append() function.

T.append( cs )

Description:

Append records in cursor/distributed cursor cs to a table T.

Syntax:

T.append(cs)

 

Note:

 

When T is a multi-zone composite table, cs can be an ordinary cursor or a multicursor. An ordinary cursor or each part of the multicursor can only corresponds to one zone. The missing subfile member(s) in the homo-name files group will be automatically generated if necessary (which should be among the zone numbers defined for the homo-name files group). When T is a cluster composite table, you can only write records of a cluster cursor to it. If there is already data in T, you can append records of an ordinary cursor to it; in this case the cursor can be a multicursor. Once appending is finished, indexs of the composite table will automatically updated.

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.

Structures of cs and T should be the same if the former is a cluster distributed cursor. Data will be appended to a corresponding zone  of the cluster table according to segmentation expression. The attached table should be synchronously segmented according to the parent table’s segmentation strategy. So the appending action can be performed only when the parent table has unique data ordered by the key.

Parameters:

T

An entity table/multi-zone composite table/cluster composite table

cs

A cursor/cluster distributed cursor

Options:

  @m  A merge appending; doesn’t support an attached table

@i

Real-time appending whenever a retrieval happens and when the application exits; by default an appending is executed only when there is a specified number of new records

@a

Append to a patch file and merge with the existing data for retrieval; create one if there isn’t a corresponding patch file

@x

It is possible that the data in a single cursor corresponds to multiple zones in a multi-zone composite table. In that case the zone expression needs to be calculated at each append

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

14

=demo.cursor("select EID,NAME,GENDER from employee where EID<30")

 

15

=file("empTest.ctx")

 

16

=A15.create(#EID,NAME,GENDER)

 

17

=A16.append@a(A14)

Use @a option to append A14’s data to the patch file; here we create patch file empTest_SF.ctx because there isn’t one

 

 

Ø  When parameter T is a multi-zone composite table:

 

A

 

1

=file("deptTest.ctx":[1,2,3])

Return a homo-name files group

2

=A1.create(#DEPTID,DEPTNAME;;DEPTID%2+1)

Generate a multi-zone composite table

3

=demo.cursor("select * from dept")

 

4

=A2.append@x(A3)

A3 corresponds to multiple zones of A2, so you need to calculate the zone expression DEPTID%2+1 at each append to add data of the ordinary cursor A3 to the multi-zone composite table; an incompletete homo-name files group wil automatically generated if deptTest.ctx can’t be found within the 1/2 part of each zone

Ø  When parameter T is a cluster composite table:

 

A

 

1

=file("emp.ctx":[2],["192.168.0.104:8281","192.168.190.129:8281"])

Open a cluster file

2

=A1.open()

Return a cluster table

3

=file("emp.ctx":[1],["192.168.0.104:8281","192.168.190.129:8281"]).open().cursor()

Return a cluster cursor

4

=A2.append(A3)

Append data of the cluster cursor to the cluster composite table

5

=file("emp1.ctx":[1],["192.168.0.104:8281"])

There is data in emp1.ctx

6

=A4.open()

 

7

=file("d://emp.ctx").open().cursor()

Open a local file and return an ordinary cursor

8

=A5.append(A6)

As there is data in the cluster composite table

9

=A5.append@m(A6)

@m option enables a merge append

 

f.append()

Description:

Cocatenate two same-structure composite table.

Syntax:

f.append( f’,p)

 

Note:

The function appends an unencrypted composite table file f’ to another composite table file f. The two should have same structure, otherwise the appending will fail. Once the appending fails, use rollback() function to restore the previous state. Parameter p can be omitted if f is an unencrypted composite table file.

Parameters:

f’

A composite table file

p

The write password for composite table file f

Options:

@x

Delete f’after the appending

Return value:

A composite table file

Example:

 

A

 

1

=file("D:\\append1.ctx")

 

2

=A1.create(#EID,NAME,DEPT,SALARY)

Create the composite table’s base table

3

=demo.cursor("select EID,NAME,DEPT,SALARY from EMPLOYEE where EID<10 order by  EID")

 

4

=A2.append@i(A3)

Append cursor records to the entity table and write them out immediately

5

=file("D:\\append2.ctx")

 

6

=A5.create(#EID,NAME,DEPT,SALARY)

Create the composite table’s base table

 

7

=demo.cursor("select EID,NAME,DEPT,SALARY from EMPLOYEE where  EID>10and  EID<20  order by  EID")

 

8

=A6.append@i(A7)

Append cursor records to the entity table and write them out immediately

9

=A1.append(A5)

Append unencrypted composite table f’ to another unencrypted composite table f

10

=A9.create().cursor().fetch()

11

=file("D:\\append3.ctx")

 

12

=A11.create(#EID,NAME,DEPT,SALARY;;;"123":"11")

Create an encrypted base table for the composite table

13

=demo.cursor("select EID,NAME,DEPT,SALARY from EMPLOYEE where EID<5 order by  EID")

 

14

=A12.append@i(A13)

Append cursor records to the entity table and write them out immediately

 

15

=A11.append(A5,"123")

Append unencrypted composite table f’ to encrypted composite table f

16

=A11.open("11").cursor().fetch()

17

=A1.append@x(A5)

Concatenate the two composite tables and then delete append2.ctx