Here’s how to use join() function.
Description:
Join multiple sequences together.
Syntax:
join(Ai:Fi,xj,..;…)
Note:
The function joins multiple sequences of Ai according to the condition that the value of relational field/expression xj is equal to x1, and generates a table sequence whose fields are Fi,…. which reference the records of the original record sequences Ai. If xj is omitted, then use the key of Ai. An omitted xj won’t be matched. No matter how many record sequences are mutually related, the equivalence determination is conducted according to the x1 in A1. Therefore this is a one-to-many relationship.
Parameters:
Fi |
Field name of the resulting table sequence |
Ai |
Sequences or record sequences to be joined |
xj |
Relational field/ expression |
Options:
@f |
Full join;if no matching records are found, then use nulls to correspond |
@1 |
Left join; it is the number "1" instead of the letter "l" |
@m |
If all Ai are ordered against xj, then use merge operation to compute |
@p |
Perform a join according to positions while ignoring parameter xj |
@x |
If field values of the sequences to be joined are records, the joining values will be unfolded |
Return value:
A new table sequence whose fields are all referencing ones
Example:
|
A |
|
||
1 |
=demo.query("select top 3 EID,NAME from EMPLOYEE").keys(EID) |
|
||
2 |
=demo.query("select top 3 EID,NAME from FAMILY").keys(EID) |
|
||
3 |
=join(A1:Employee,EID;A2:Familymembers,EID) |
Normal
join. The non-matching items
will be discarded. Every field is a ref field pointing to the
corresponding
record in the original table
sequence |
||
4 |
=join@f(A1:Employee,EID;A2:Familymembers,EID) |
|
||
5 |
=join@1(A1:Employee,EID;A2:Familymembers,EID) |
Left
join. Take the first table sequence as the basis, and use nulls if no matching items are found |
||
6 |
=join@m(A1:Employee,EID;A2:Familymembers,EID) |
If all the relational fields are in the same
order, then merge operation can be used to
compute;
If they are not in the same order,
then error will occur. |
||
7 |
=join@p(A1:Employee;A2:Familymembers) |
|
||
8 |
=join(A1:Employee;A2:Familymembers) |
|
||
9 |
=join(A1:Employee1;A2:Familymembers1) |
|
||
10 |
=join(A7:Employee2;A8:Familymembers2) |
|
||
11 |
=join@x(A7:Employee2;A8:Familymembers2) |
Field values of A7 and A8 are records, the joining values will be unfolded |
Related functions:
Description:
A foreign-key-style join between table sequences/record sequences, or a table sequence and a record sequence.
Syntax:
A.join(C:.,T:K,x:F,…; …;…)
Note:
The function matches C field of table sequence/record sequence A with the key of table sequence/record sequence T to find the desired records. Add an F field represented by x, which is T’s field expression, to A to generate a new table sequence. K can be omitted or represented by #. When omitted, K is T’s key; when written as #, K is represented by a sequence number.
Options:
@i |
Delete a record with a non-matching foreign key value; by default a non-matching record will be represented by null. If parameters x:F are omitted, perform the filtering purely over parameter A |
@o(F;) |
Use the record as the value of F field to generate a new record; here expression x is equivalent to ~ |
@d |
If parameter x:F is absent, delete the records matching the foreign key and perform the filtering operation only over table sequence/record sequence A |
@k |
When parameter x is ~, record the relationship between parameter F and parameter C to identify the potentially associative foreign key |
Parameters:
A |
Table sequence/record sequence |
C |
A’s foreign key; separate multiple fields in a composite key with the colon |
T |
Table sequence/record sequence/memory table |
K |
T’s key |
x |
T’s field expression, which can be represented by ~ and #; the pound sign # represents the sequence number of a record in T; record the sequence number as 0 if a record doesn’t exist in T |
F |
Field name in expression x |
Return value:
A table sequence/record sequence
Example:
|
A |
|
1 |
=demo.query("select * from EMPLOYEE order by EID" ) |
|
2 |
=demo.query("select * from PERFORMANCE order by EMPLOYEEID").keys(EMPLOYEEID) |
|
3 |
=demo.query("select * from PERFORMANCE order by EMPLOYEEID").cursor().memory().keys(EMPLOYEEID) |
Return a memory table |
4 |
=A1.join(EID,A2,BONUS+1:SALARY1) |
Use null to represent a record with non-matching foreign key value |
5 |
=A1.join(EID,A3,BONUS+1:SALARY1) |
A3 is a memory table; the resut is the same as above, where null is used to represent a record with non-matching foreign key value |
6 |
=A1.join@i(EID,A2,BONUS+1:SALARY1) |
Delete a record with non-matching foreign key value |
7 |
=A1.join@i(EID,A2:#1,BONUS+1:SALARY1) |
Same result as A4’s; #1 means the first field |
8 |
=A1.join@o(F1;EID,A2,BONUS+1:SALARY1) |
Records are the values of F1 field |
9 |
=A1.join@i(EID,A2) |
As parameters x:F are omitted, perform the filtering purely over parameter A1 |
10 |
=A1.join@d(EID,A2) |
Since parameter x:F is absent, delete the records matching the foreign key and perform the filtering operation only over A1 |
Description:
A foreign-key-style join between a channel and a record sequence.
Syntax:
ch.join(C:.,T:K,x:F,…; …;…)
Note:
The function uses the key of table sequence/record sequence T to match C,… field in channel ch, and add an F field to ch by joining T’s field expression x to for a new channel. K can be omitted or represented by #; when it is omitted, use T’s key; when represented by #, the key is pointed by a sequence number. This is an attached computation.
Options:
@i |
Delete the whole record if the foreign key can’t be matched; by default make it null. |
@o(F;…) |
Generate a new record by introducing the original record as a new field; field expression x can be represented by ~. |
Parameters:
ch |
Channel |
C |
Foreign key of a given channel; use comma to separate a composite key |
T |
Table sequence/record sequence |
K |
Key of the given table sequence/record sequence |
x |
A field expression of the given table sequence/record sequence |
F |
Name of the field expression |
Return value:
Channel
Example:
|
A |
|
1 |
=demo.cursor("select EID,NAME,SALARY from EMPLOYEE order by EID" ) |
|
2 |
=demo.query("select * from PERFORMANCE order by EMPLOYEEID").keys(EMPLOYEEID) |
|
3 |
=channel() |
Create a channel |
4 |
=channel() |
|
5 |
=channel() |
|
6 |
=channel() |
|
7 |
=A1.push(A3,A4,A5,A6) |
Be ready to push data in A1’s cursor into channel A3,A4,A5 and A6, but the action needs to wait |
8 |
=A3.join(EID,A2, BONUS+1:SALARY1) |
A normal join, where a record can’t be matched with the foreign key is recorded as null |
9 |
=A8.fetch() |
Fetch and store the existing data in the channel |
10 |
=A4.join@i(EID,A2: #1, #3+1:SALARY1) |
#1 represents the first field, and #3 represents the third field |
11 |
=A10.fetch() |
|
12 |
=A5.join@i(EID,A2, BONUS+1:SALARY1) |
Delete the whole record since it doesn’t match the foreign key |
13 |
=A12.fetch() |
|
14 |
=A6.join@o(F1;EID,A2,~.BONUS+1:SALARY1) |
Make the original record as the F1 field |
15 |
=A14.fetch() |
|
16 |
=A1.fetch() |
|
17 |
=A3.result() |
|
18 |
=A4.result() |
|
19 |
=A5.result() |
Get the same result as A18 |
20 |
=A6.result() |
|
Description:
A foreign-key-style join between a cursor and a table sequence/record sequence.
Syntax:
cs.join(C:.,T:K,x:F,…; …;…)
Note:
The function matches foreign key field C of cursor cs with the key of parameter T to find the corresponding records in T. Add an F field represented by x, which is T’s field expression, to cs and return the original cursor. K can be omitted or represented by #. When omitted, K is T’s key; when written as #, K is represented by a sequence number. It supports the multicursor.
Parameters:
cs |
A cursor/A multicursor |
C |
Cursor cs’s foreign key; separate multiple fields in a composite key with the colon |
T |
A table sequence/A record sequence |
K |
T’s key |
x |
T’s field expression |
Field name in expression x. |
Options:
@i |
Delete a record with a non-matching foreign key value; by default a non-matching record will be represented by null |
@o(F;…) |
Use the record as the value of F field to generate a new record; here expression x can be represented by ~, which is T’s record |
@d |
If parameters x:F are absent, only perform a filtering over the cursor by deleting its records where the foreign key is matched |
Return value:
The orignal cursor
Example:
|
A |
|
1 |
=demo.cursor("select EID,NAME,DEPT,SALARY from EMPLOYEE where EID<10 order by EID" ) |
Return retrieved data as a cursor: |
2 |
=demo.query("select * from PERFORMANCE order by EMPLOYEEID").keys(EMPLOYEEID) |
Return a table sequence: |
3 |
=A1.join(EID,A2,BONUS+1:SALARY1) |
Normal join; a non-matching record will be displayed as null |
4 |
=A3.fetch() |
|
5 |
=demo.cursor("select EID,NAME,DEPT,SALARY from EMPLOYEE where EID<10 order by EID" ) |
Same as A1 |
6 |
=demo.query("select * from PERFORMANCE order by EMPLOYEEID").keys(EMPLOYEEID) |
Same as A2 |
7 |
=A5.join@i(EID,A6, BONUS+1:SALARY1) |
Delete non-matching records |
8 |
=A7.fetch() |
|
9 |
=demo.cursor("select EID,NAME,DEPT,SALARY from EMPLOYEE where EID<10 order by EID" ) |
Same as A1 |
10 |
=demo.query("select * from PERFORMANCE order by EMPLOYEEID").keys(EMPLOYEEID) |
Same as A2 |
11 |
=A9.join@i(EID,A10: #1, #3+1:SALARY1) |
#1 represents the 1st field; #3 represents the 3rd field |
12 |
=A11.fetch() |
Same as A8 |
13 |
=demo.cursor("select EID,NAME,DEPT,SALARY from EMPLOYEE where EID<10 order by EID" ) |
Same as A1 |
14 |
=demo.query("select * from PERFORMANCE order by EMPLOYEEID").keys(EMPLOYEEID) |
Same as A2 |
15 |
=A13.join@o(F1;EID,A14,BONUS+1:SALARY1) |
Use records as values of F1field |
16 |
=A15.fetch() |
|
17 |
=demo.cursor("select EID,NAME,DEPT,SALARY from EMPLOYEE where EID<10 order by EID" ) |
Same as A2 |
18 |
=demo.query("select * from PERFORMANCE order by EMPLOYEEID").keys(EMPLOYEEID) |
Same as A2 |
19 |
=A17.join@o(F1;EID,A18,~:SALARY1) |
Replace parameter x with the sign ~ |
20 |
=A19.fetch() |
|
21 |
=file("D:\\test7.ctx") |
|
22 |
=A21.create(#EMPLOYEEID,EVALUATION,BONUS;EMPLOYEEID |
Create a composite table |
23 |
=A22.attach(table3,#EMPLOYEEID,EVALUATION,BONUS) |
Add an attached table |
24 |
=demo.cursor("select * from PERFORMANCE") |
Return a table sequence |
25 |
=A23.append(A24) |
Append records to A23’s attached table |
26 |
=demo.cursor("select EID,NAME,DEPT,SALARY from EMPLOYEE where EID<10 order by EID" ) |
|
Related functions:
Description:
A foreign-key-style join between a cluster cursor and a record sequence.
Syntax:
cs.join(C:.,T:K,x:F,…; …;…)
Note:
The function matches foreign key field C,… of cluster cursor cs with the key of parameter T to find corresponding records in table T. Add an F field represented by x, which is T’s field expression, to cs and return the original cluster cursor. K can be omitted or represented by #. When omitted, K is T’s key; when written as #, K is represented by a sequence number. It supports the multicursor.
Options:
@c |
With a distributed cluster table, the operation won’t involve a cross-node reference but it assumes that the referenced records are local |
Parameters:
cs |
A cursor/multicursor/cluster cursor |
C |
cs’s foreign key; separate multiple fields in a composite key with the colon |
T |
A cluster memory table |
K |
T’s key |
x |
T’s field expression |
F |
Name of T’s field expression |
Return value:
The original cursor
Example:
|
A |
|
1 |
[192.168.18.143:8281] |
|
2 |
=file("emp_1.ctx":[2], A1) |
|
3 |
=A2.open() |
|
4 |
=A3.cursor() |
A cluster cursor |
5 |
[192.168.0.110:8281] |
|
6 |
=file("PERFORMANCE.ctx":[1],A5) |
|
7 |
=A6. open () |
|
8 |
=A7.cursor() |
|
9 |
=A8.memory() |
A cluster memory table |
10 |
=A4.join(EID,A9:EMPLOYEEID, BONUS*12:total) |
Match EID field of A4’s cluser cursor with the key field EMPLOYEEID of A9’s cluster memory table, make the value of calculating expression BONUS*12 over the memory table total field and join it up with the cluster cursor, and return the cluster cursor |
11 |
=A10.fetch() |
Fetch data from A10’s cursor |
Description:
Join a pseudo table and table sequence/record sequence through the foreign key.
Syntax:
T.join(C:.,A:K,x:F,…; …;…)
Note:
The function matches foreign key field C,… of pseudo table T with table sequence or record sequence A’s key values to get corresponding records from the latter, joins field expression x of A to T and names it F, and returns a pseudo table. Parameter K is by default A’s key when it is absent, or is a column number represented by the number sign # .
This is is a delay function.
Parameters:
T |
A pseudo table |
C |
T’s Foreign key field; use comma to separate fields of a composite key |
A |
A table sequence/record sequence |
K |
A’s key |
x |
A’s field expressions |
F |
Name of field expression x |
Options:
@i |
Enable deleting the whole record if it is not matched with the foreign key; use null to represent the corresponding value by default |
@o(F;…) |
Enable using the whole record’s A as field F to generate a new record in T; in this case x is replaced by the tilde ~ to denote the whole record |
@d |
Enable deleting the whole matching records when parameters x:F are absent to perform filtering on the pseudo table |
Return value:
A pseudo table
Example:
|
A |
|
1 |
=file("px1.ctx").open().pseudo() |
Return a pseudo table as follows: |
2 |
=demo.query("select * from PERFORMANCE order by EMPLOYEEID").keys(EMPLOYEEID) |
Return a table sequence as follows: |
3 |
=A1.join(EID,A2, BONUS+1:SALARY1) |
The ordinary join that uses null to represent a foreign key value that is not matched |
4 |
=A3.import() |
Return a pseudo table as follows: |
5 |
=file("px1.ctx").open().pseudo() |
Same as A1 |
6 |
=A5.join@i(EID,A2, BONUS+1:SALARY1) |
Delete records where the foreign key values that are not matched |
7 |
=A6.import() |
Return a pseudo table as follows: |
8 |
=file("px1.ctx").open().pseudo() |
Same as A1 |
9 |
=A8.join@i(EID,A2: #1, #3+1:SALARY1) |
#1 represents the first field; #3 represents the third field |
10 |
=A9.import() |
Return same pseudo table as A7 |
11 |
=file("px1.ctx").open().pseudo() |
Same as A1 |
12 |
=A11.join@o(F1;EID,A2,BONUS+1:SALARY1) |
Add the whole record as a new field F1 |
13 |
=A12.import() |
Return a pseudo table as follows: |
14 |
=file("px1.ctx").open().pseudo() |
Same as A1 |
15 |
=A14.join@o(F1;EID,A2,~:SALARY1) |
Use the tilde ~ to replace parameter x to denote a whole record of A2 |
16 |
=A15.import() |
|
17 |
=file("px1.ctx").open().pseudo() |
Same as A1 |
18 |
=A17.join@d(EID,A2) |
As parameters x:F are absent, delete all matching records from the pseudo table to perform filter |
19 |
=A18.import() |
|