Here’s how to use attach() function.
Description:
Retrieve an attached table from a cluster composite table.
Syntax:
T.attach(T’)
Note:
The function retrieves attached table T’, which should already exist, from cluster composite table T.
Parameters:
T |
A cluster composite table |
T’ |
An attached table |
Return value:
An attached table
Example:
Here’s composite table emp1.ctx:
|
A |
|
1 |
=file("D:\\emp1.ctx") |
|
2 |
=A1.create(#EID,NAME) |
Create the composite table’s base table |
3 |
=demo.cursor("select EID,NAME from employee ") |
|
4 |
=A2.append(A3) |
Append records to the base table |
5 |
=A2.attach(t1, SURNAME,DEPT ) |
Add attached table t1 to the base table |
6 |
=demo.cursor("select EID,SURNAME,DEPT from employee") |
|
7 |
=A5.append(A6) |
Append records to attached table t1 |
8 |
=A2.attach(t2,GENDER,SALARY) |
Add attached table t2 to the base table |
9 |
=demo.cursor("select EID,GENDER,SALARY from employee ") |
|
10 |
=A8.append(A9) |
Append records to attached table t2 |
|
A |
|
1 |
=file("emp1.ctx":[1],["192.168.0.116:8281","192.168.0.129:8281"]) |
Generate a cluster file |
2 |
=A1.create() |
Create a cluster composite table |
3 |
=A2.attach(t1) |
Retrieve attached table t1 |
Description:
Add an attached table to the base table of a composite table.
Synatx:
T.attach(T’,C…)
Note:
The function adds attached table T’ to a composite table’s base table T. A composite table can have one or multiple attached tables. The attached table’s dimensions include the dimensions of its parent table (the base table); its column names should be different from the base table’s column names.
Parameters:
T |
A base table |
T’ |
An attached table |
C |
Attached table column, can be omitted; return an attached table named T’ if it is absent; a C preceded by # is a dimension |
Return value:
An attached table
Example:
|
A |
|
1 |
=file("D:/ctb.ctx") |
|
2 |
=A1.create(#k1,v1) |
Create the composite table’s base table where k1 is the dimension and v1 is the column |
3 |
=A2.attach(table2,#k2,v2) |
Add attached table table2 to A2’s base table; k1 and k2 are the attached table’s dimensions and v1 and v2 are its columns |
4 |
=A2.attach(table3,v3) |
Add attached table table3 to A2’s base table; k1 is the attached table’s dimension and v1 and v3 are its columns |
Description:
Attach an operation to a channel.
Syntax:
ch.attach(…)
Note:
The function attaches an operation to channel ch. The sign ~ used in the expression parameter … represents the result of the previous operation performed in the channel.
Parameters:
ch |
Channel |
… |
An expression of performing an operation over a sequence |
Return value:
Channel
Example:
|
A |
|
1 |
=demo.query("select EID,NAME,SALARY from EMPLOYEE") |
|
2 |
=channel() |
Create a channel |
3 |
=A2.select(SALARY>10000) |
Attach a ch.select() operation to the channel |
4 |
=A2.attach(~.sort(-SALARY)) |
Attach a A.sort() operation to the channel |
5 |
=A2.fetch() |
Attach ch.fetch() function that gets the final result set to A2’s channel to fetch and store the existing data in the channel |
6 |
=A1.push(A2) |
Push the data in A1’s sequence into the channel |
7 |
=A2.result() |
Get the result of the last operation performed in the channel |