Description:
Attach a referencing field-based switch operation to a channel and return the original channel.
Syntax:
ch.switch(Fi,Ai:x;…)
Note:
The function attaches a computation to channel ch, which will switch values of field Fi to the referenced records of Ai, and return the original channel ch.
x is Ai’s primary key or logical primary key. The matching condition for the switch is Fi=x. By default, display Fi value as null when no match can be found in Ai for Fi.
This is an attached computation.
Parameter:
ch |
A channel |
Fi |
A field in channel ch |
Ai |
A table sequence/record sequence |
x |
Ai’s primary key or logical primary key; if x is already set as the primary key of Ai, parameter x can be omitted |
Option:
@i |
If no value corresponding to Fi is found, then remove this record |
@d |
Perform the inverse operation of @i, which obtains the records that have no value corresponding to F |
@1 |
If the Fi field value of a record in channel ch doesn’t exist in Ai , then generate a record of the same structure as Ai with expression x being the primay key; note that the option uses number 1 |
Return value:
Channel
Example:
x is Ai’s primary key:
|
A |
|
1 |
=demo.cursor("SELECT top 10 EID,DEPT,NAME FROM EMPLOYEE") |
Return a cursor, whose data is as follows:
|
2 |
=demo.query("SELECT DEPT,MANAGER FROM DEPARTMENT").keys(DEPT) |
Return a table sequence using DEPT as the key:
|
3 |
=channel() |
Create a channel. |
4 |
=A3.switch(DEPT,A2) |
Attach a computation to channel A3, which will switch DEPT field values to A2’s records pointed by the referencing field, and return result to channel A3; as A2’s key is DEPT, parameter x can be omitted. |
5 |
=A4.fetch() |
Execute the result set function in channel A2 and keep the current data in channel. |
6 |
=A1.push(A3) |
Be ready to push cursor A1’s data to channel A3, but the action needs to wait. |
7 |
=A1.skip() |
Fetch data from cursor A1 while pushing data to channel to execute the attached computation and keep the result. |
8 |
=A3.result() |
Get channel A3’s result:
|
x is Ai’s primary key or logical primary key:
|
A |
|
1 |
=demo.cursor("SELECT top 10 EID,DEPT,NAME FROM EMPLOYEE") |
Return a cursor, whose data is as follows:
|
2 |
=demo.query("SELECT top 6 DEPT,MANAGER FROM DEPARTMENT") |
Return a table sequence:
|
3 |
=channel(A1) |
Be ready to push cursor A1’s data to channel A3, but the action needs to wait. |
4 |
=A3.switch(DEPT,A2:DEPT) |
Attach a computation to channel A3, which will match its DEPT field with the corresponding DEPT field value in A2 – display a result record as null if no match can be found, and return the result to channel A3. |
5 |
=A4.fetch() |
Execute the result set function in channel A2 and keep the current data in channel. |
6 |
=A1.skip() |
Fetch data from cursor A1 while pushing data to channel to execute the attached computation and keep the result. |
7 |
=A3.result() |
Get channel A3’s result:
|
Use @i option to directly delete records in the channel that do not have matches:
|
A |
|
1 |
=demo.cursor("SELECT top 10 EID,DEPT,NAME FROM EMPLOYEE") |
Return a cursor whose data is as follows:
|
2 |
=demo.query("SELECT top 6 DEPT,MANAGER FROM DEPARTMENT") |
Return a table sequence:
|
3 |
=channel(A1) |
Be ready to push cursor A1’s data to channel A3, but the action needs to wait. |
4 |
=A3.switch@i(DEPT,A2:DEPT) |
Attach a computation to channel A3, which will match its DEPT field with the corresponding DEPT field value in A2 – use @i option to delete records that cannot find matches, and return the result to channel A3. |
5 |
=A4.fetch() |
Execute the result set function in channel A2 and keep the current data in channel. |
6 |
=A1.skip() |
Fetch data from cursor A1 while pushing data to channel to execute the attached computation and keep the result. |
7 |
=A3.result() |
Get channel A3’s result:
|
Use @d option to retain the non-matching records only:
|
A |
|
1 |
=demo.cursor("SELECT top 10 EID,DEPT,NAME FROM EMPLOYEE") |
Return a cursor whose data is as follows:
|
2 |
=demo.query("SELECT top 6 DEPT,MANAGER FROM DEPARTMENT") |
Return a table sequence;
|
3 |
=channel(A1) |
Be ready to push cursor A1’s data to channel A3, but the action needs to wait. |
4 |
=A3.switch@i(DEPT,A2:DEPT) |
Attach a computation to channel A3, which will match its DEPT field with the corresponding DEPT field value in A2 – use @d option to retain only the non-matching records, and return the result to channel A3. |
5 |
=A4.fetch() |
Execute the result set function in channel A2 and keep the current data in channel. |
6 |
=A1.skip() |
Fetch data from cursor A1 while pushing data to channel to execute the attached computation and keep the result. |
7 |
=A3.result() |
Get channel A3’s result:
|
Use @1 option;
|
A |
|
1 |
=demo.cursor("SELECT top 10 EID,DEPT,NAME FROM EMPLOYEE") |
Return a cursor whose data is as follows:
|
2 |
=demo.query("SELECT top 6 DEPT,MANAGER FROM DEPARTMENT") |
Return a table sequence:
|
3 |
=channel(A1) |
Be ready to push cursor A1’s data to channel A3, but the action needs to wait. |
4 |
=A3.switch@i(DEPT,A2:DEPT) |
Attach a computation to channel A3, which will match its DEPT field with the corresponding DEPT field value in A2 – use @1 option to generate a record of A2’s structure when no match can be found, and return the result to channel A3. |
5 |
=A4.fetch() |
Execute the result set function in channel A2 and keep the current data in channel. |
6 |
=A1.skip() |
Fetch data from cursor A1 while pushing data to channel to execute the attached computation and keep the result. |
7 |
=A3.result() |
Get channel A3’s result:
|