Description:
Attach an operation of grouping records in a channel by comparing each one with its next and return the original channel.
Syntax:
ch.group(x,…)
Note:
The function attaches a computation to channel ch, which will group its records by expression x, whose value is compared only with the directly next each record, and returns the original channel ch. This is equivalent to a merge and ch should be ordered.
This is an attachment computation.
Option:
@i |
With this option and with grouping expression x being a Boolean expression, start a new group if the result of x is true. Be sure there’s only one x in this case |
@1 |
Get the first record of every group to form a record sequence and return it to the original channel (here it is number 1 rather than letter l) |
Parameter:
ch |
A channel |
x |
Grouping expression |
Return value:
Channel
Example:
|
A |
|
1 |
=demo.cursor("select EID,GENDER,DEPT,NAME,SALARY from EMPLOYEE").sortx(GENDER,DEPT) |
Return a cursor ordered by by GENDER and DEPT fields. |
2 |
=channel() |
Create a channel. |
3 |
=A2.group(GENDER,DEPT) |
Attach a computation to channel A2, which will group its records by GENDER and DEPT. |
4 |
=A2.fetch() |
Execute the result set function in channel A2 and keep the current data in channel. |
5 |
=A1.push(A2) |
Be ready to push cursor A1’s data to channel A2, but the action needs to wait. |
6 |
=A1.skip() |
Fetch data from cursor A1 while pushing data into the channel to execute the attached computation and keep the result. |
7 |
=A2.result() |
Get channel A2’s result:
|
|
A |
|
1 |
=demo.cursor("select EID,GENDER,DEPT,NAME,SALARY from EMPLOYEE").sortx(DEPT) |
Return a cursor ordered by DEPT field |
2 |
=channel() |
Create a channel. |
3 |
=channel() |
Create a channel. |
4 |
=A2.group@1(DEPT) |
Attach a computation to channel A2, which will group its records by DEPT field and use @1 option to get the first record of every group to form a record sequence, and return the original channel A2. |
5 |
=A2.fetch() |
Execute the result set function in channel A2 and keep the current data in channel. |
6 |
=A3.group@i(GENDER=="F") |
Attach a computation to channel A3, which will group its records by DEPT field and use @i option to create a new group whenever DEPT =="HR" is met, and return the original channel A3. |
7 |
=A3.fetch() |
Execute the result set function in channel A3 and keep the current data in channel. |
8 |
=A1.push(A2,A3) |
Be ready to push the data in A1’s cursor to channels A2 and A3, but the action needs to wait. |
9 |
=A1.skip() |
Fetch data from cursor A1 while pushing data into the channel to execute the attached computation and keep the result. |
10 |
=A2.result() |
Get channel A2’s result:
|
11 |
=A3.result() |
Get channel A3’s result:
|