T. group ()

Read(449) Label: records, pseudo table, group, neighbor,

Description:

Define a computation, which will group records by comparing the grouping field in each with its next neighbor, on a pseudo table and return a new pseudo table.

Syntax:

T.group(xi,…)

Note:

The function defines a computation on pseudo table T that should be ordered, which will group records by grouping expression xi whose value will only be compared with its next neighbor – which amounts to a merge, and return a new pseudo table.

Parameter:

T

A pseudo table

xi

Grouping expression; use comma to separate multiple grouping fields or expressions

Option:

@i

x is a Boolean expression. Begin a new group when a record makes it return true. In this case there should be only one x

@1

Get the first record of every group to form a record sequence and return it; here it is number 1, instead of letter l

@v

Store the composite table in the column-wise format when loading it the first time, which helps to increase performance

Return value:

Pseudo table object

Example:

 

A

 

1

=create(file).record(["D:/file/pseudo/empT.ctx"])

 

2

=pseudo(A1)

Generate a pseudo table object, whose data is as follows:

3

=A2.group(GENDER,DEPT)

Define a computation on A2’s pseudo table, which will put records where both GENDER and DEPT values are same into the same group, and return a new pseudo table.

4

=A3.import()

Import data from A3’s pseudo table while executing the computation in A3 defined on A2’s pseudo table, and return the following pseudo table:

5

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

With @i option, create a new group whenever the record meets the condition GENDER=="F".

6

=A5.import()

Get data from A5’s pseudo table.

 

 

7

=A2.group@1(GENDER)

With @1 option, return the first record of each group.

8

=A7.cursor().fetch()

Fetch data from A7’s pseudo table: