groupn()

Read(321) Label: group,

Here’s how to use group() function.

cs.groupn( x;C )

Description:

Group records in a cursor and push them respectively into a sequence of channels.

Syntax:

cs.groupn(x;C)

Note:

The function groups records in cursor cs and pushes them respectively into a sequence of channels.

Parameters:

cs

Cursor records

x

Grouping expression

C

A sequence of channels

Return value:

The original cursor

Example:

 

A

 

1

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

 

2

=channel()

Create a channel

3

=channel()

Create a channel

4

=A1.groupn(if(GENDER=="F",1,2);[A2,A3])

Group cursor records, and push one group where GENDER is F into A2’s channel and the other group into A3’s channel

5

=A2.fetch()

Keep data in the channel in place

6

=A3.fetch()

Keep data in the channel in place

7

=A1.fetch()

 

8

=A2.result()

Get result from A2’s channel

9

=A3.result()

Get result from A3’s channel

ch.groupn( x;C )

Description:

Group records in channel ch and push them respectively into a sequence of channels.

Syntax:

ch.groupn(x;C)

Note:

The function groups records in channel ch and pushes them respectively into a sequence of channels.

Parameters:

ch

Channel

x

Gouping expression

C

A sequence of channels

Return value:

A channel

Example:

 

A

 

1

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

 

2

=channel(A1)

Push cursor records into a sequence of channels and return a channel

3

=channel()

Create a channel

4

=channel()

Create a channel

5

=A2.groupn(if(GENDER=="F",1,2);[A3,A4])

Group records of A2’s channel, and push one group where GENDER is F into A3’s channel and the other group into A4’s channel

6

=A3.fetch()

Attach ch.fetch() function that gets the final result set to A3’s channel but keep data in A3’s channel in place

7

=A4.fetch()

Attach ch.fetch() function that gets the final result set to A4’s channel but keep data in A4’s channel in place

8

=A1.fetch()

 

9

=A3.result()

Get result from A3’s channel

10

=A4.result()

Get result from A4’s channel

cs.groupn(x;F)

Description:

Group records of a cursor and write the subset groups as a sequence of bin files.

Syntax:

cs.groupn(x;F)

Note:

The function groups records of cursor cs and writes the subset groups as a sequence of bin files.

Parameters:

cs

Cursor records

x

Grouping expression

F

A sequence of bin file objects

Return value:

The original cursor

Example:

 

A

 

1

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

 

2

=[file("f_dept.btx"),file("m_dept.btx")]

A sequence of bin file objects

3

=A1.groupn(if(GENDER=="F",1,2);A2)

Put records where GENDER is F into the first group and other records into the second group, and then write the subset groups into a sequence of bin files in order

4

=A3.fetch()