ch. group()

Description:

Group records in a channel by comparing each one with its neighbor(s) and return a channel.

Syntax:

ch.group(x)

Note:

The function groups the records in channel ch by expression x, during which each record is compared only with its neighbor(s) and returns a channel containing a series of sequences. This is equivalent to a merge. The resulting set won’t be sorted again. This is an attached computation.

Options:

@i

With this option and with grouping expression x being a bool expression, start a new group if the result of x is true. Be sure there’s only one x in this case.

Parameters:

ch

Channel

x

Grouping expression. Use the comma to separate multiple grouping fields/expressions.

Return value:

Channel

Example:

 

A

 

1

=demo.cursor("select EID,NAME,GENDER,DEPT,SALARY from EMPLOYEE")

 

2

=channel()

Create a channel

3

=channel()

Create a channel

4

=A2.group(GENDER,DEPT)

Group records by GENDER field and DEPT field

5

=A2.fetch()

Attach ch.fetch() function that gets the final result to A2’s channel to fetch and store the existing data in the channel

6

=A3.group@i(GENDER=="F")

Start a new group whenever GENDER=="F"

7

=A3.fetch()

Attach ch.fetch() function that gets the final result to A3’s channel

8

=A1.push(A2,A3)

Be ready to push the data in A1’s cursor into A2’s channel and A3’s channel, but the action needs to wait

9

=A1.skip()

Data in A1’s cursor is pushed into the channel and operations are performed as the skip() operation is performed over A1

10

=A2.result()

11

=A3.result()