cgroups()

Read(3237) Label: cgroups,

Here’s how to use cgroups() function.

T.cgroups( F i ,…;y:G i ,…;w;f,… )

Description:

Perform grouping & aggregation using the composite table/multizone composite table’s preaggregation file.

Syntax:

T.cgroups(Fi,…;y:Gi,…;w;f,…)

Note:

The function uses composite table/multizone composite table T’s preaggregation file(s) f,… to perform grouping & aggregation and returns a table sequence that uses Fi,… as the key.

A preaggregation file can only be used when its grouping field and aggregate expression are the same as Fi and y.

Parameter:

T

Composite table/multizone composite table

Fi

Grouping field

y

Aggregate expression

Gi

Aggregate field name

w

Filtering condition; cannot omitted

f

T’s preaggregation file; find the suitable one when there are multiple preaggregation files (f,…)

Option:

@m(…;n)

Enable parallel processing; parameter n is the number of parallel threads, which is the “max number of parallel threads” specified in the designer by default or parallelNum value configured in raqsoftConfig.xml by default when esProc is used by being integrated in the third-party application

Return value:

Table sequence

Example:

 

A

 

1

=file("empcub.ctx")

 

2

=A1.create@y(#EID,NAME,GENDER,DEPT,SALARY)

Create a composite table

3

=demo.query("select  EID,NAME,GENDER,DEPT,SALARY from employee ")

Return a table sequence:

4

=A2.append(A3)

Append cursor A3’s data to the composite table

5

=file("cub1")

Preaggregation file object

6

=A2.cuboid(A5,DEPT;count(EID))

Generate preaggregation file cub1 for the composite table: perform count on EID by DEPT field

7

=file("cub2")

Preaggregation file object

8

=A2.cuboid(A7,DEPT,GENDER;avg(SALARY))

Generate preaggregation file cub2 for the composite table: perform avg on SALARY by DEPT field and GENDER field

9

=A2.cgroups(DEPT;count(EID):IdNum;;A5)

Perform grouping & aggregation on the composite table using preaggregation file cub1 and return result as follows:

10

=A2.cgroups(DEPT,GENDER;avg(SALARY):AvgSalary;;A5,A7)

Perform grouping & aggregation on the composite table using the preaggregation file – since grouping field and aggregation file in A5’s preaggregation file are not consistent with Fi and y specified in A10, A7’s preaggregation instead of A5’s is used for computation – and return following result:

11

=A2.cgroups(DEPT;avg(SALARY):AvgSalary,count(EID):IdNum;;A5,A7)

Both preaggregation files in A5 and A7 are not used in the computation because their grouping fields and aggregate expressions are not same as Fi and y specified in A11