• esProc
Tutorial
Function Reference
User Reference
External Library Guide
Data File Tool Manual
DQL Tutorial
Cluster Server Manager Manual
SPL Command Executor Manual
• YModel
User Reference
JSON-style Parameter Guide
• ReportLite
User Reference
• Official Website

# id()

Here’s how to use id() function.

## A .id()

Description:

Get distinct values from a sequence.

Syntax:

A.id(xi,…;n)

Note:

The function gets top n distinct values of the expressions xi,…. If the number of distinct values in an expression x is less than n, return all distinct values as a sequence; the result set consists of one ordinary sequence when there is only one expression x.

Parameter:

 xi An expression; use ~ to represent x if the latter is omitted n The number of to-be-retrieved distinct values counting from the beginning; return all values if it is absent

Option:

 @o Without sorting, remove the neighboring duplicate members only @u Do not sort the result set by x; it doesn’t work with @o @h Used over a grouped table with each group ordered to speed up grouping @0 Discard members on which expression x is computed and gets empty result @m Enable parallel processing to increase performance of complex computations on a large volume of data, with indefinite computing order; the parameter and @o option are mutually exclusive @n Judge whether a member is distinct or not according to position when there is only one xi and xi is a natural number @b Judge whether a member is distinct or not according to the bit length in a byte in order to reduce storage usage when there is only one xi and xi is a natural number

Return value:

The new sequence composed of the distinct values of x

Example:

 A 1 =demo.query("select * from EMPLOYEE") 2 =A1.id(DEPT) Sort members in ascending order 3 =A1.id@o(DEPT) No sorting 4 =A1.id([DEPT,GENDER]) Get the distinct values after sorting by DEPT & GENDER 5 =["a","b","c","a"].id() Omitting x indicates it is the sequence members themselves that will be computed to get the distinct values. Return ["a","b","c"] as with this case 6 =A1.id@u([DEPT,GENDER]) Do not sort the result set by x 7 =A1.id(DEPT,GENDER) Return all distinct values as parameter n is absent   8 =A1.id(DEPT,GENDER;4) Return the first 4 distinct values; return all GENDER values as the field has less than 4 distinct values   9 =file("D:/emp10.txt").import@t() For data file emp10.txt, every 10 records are ordered by DEPT 10 =A9.id@h(DEPT) As A19 is grouped and ordered by DEPT, @h option is used to speed up grouping A 1 =demo.query("select * from DEPT") 2 =A1.id(FATHER) Return value: [null,1,2,11,12] 3 =A1.id@0(FATHER) Return value: [1,2,11,12]

Related function:

## ch .id()

Description:

Generate a channel consisting of values of one or more fields.

Syntax:

ch.id(xi,…;n)

Note:

The function generates a channel containing a sequence of sequences, each of which is made up of values of xi field in channel ch. Get at most n values for each xi field; return a channel containing one sequence when there is only one xi field. It is for getting the result set from the channel.

Parameter:

 ch Channel xi Expression; use comma to separate multiple expressions n Integer; can’t be omitted

Return value:

Channel

Example:

 A 1 =demo.cursor("select EID,NAME,DEPT,SALARY from EMPLOYEE") 2 =channel() Create a channel 3 =channel() Create a channel 4 =A2.id(#1,DEPT;10) 5 =A3.id(DEPT;5) 6 =A1.push(A2,A3) Push data in A1’s cursor into A2’s channel and A3’s channel 7 =A1.fetch() 8 =A2.result() 9 =A3.result() ## cs .id()

Description:

Generate a sequence consisting of values of fields in a given cursor.

Syntax:

cs.id(xi,…;n)

Note:

The function generates a sequence of sequences, each of which is made up of values of xi field in cursor cs. Get at most n values for each xi field; return a sequence when there is only one xi field.

Parameter:

 cs A cursor xi An expression; use comma to separate multiple expressions n An integer; return all values when omitted

Option:

 @o Do not sort data while removing neighboring duplicate members; require that data is ordered by expression x @u Do not sort result set by expression x; the option and @o are mutually exclusive @h Used to segment ordered data, which increases efficiency @0 Discard members on which expression x is computed and gets empty result @n Judge whether a member is distinct or not according to position when there is only one xi and xi is a natural number @b Judge whether a member is distinct or not according to the bit length in a byte in order to reduce storage usage when there is only one xi and xi is a natural number

Return value:

Sequence

Example:

 A 1 =demo.cursor("select * from EMPLOYEE" ) 2 =A1.id(#1,DEPT;5) 3 =demo.cursor("select * from EMPLOYEE" ) 4 =A3.id(DEPT;5) 5 =demo.cursor("select * from EMPLOYEE" ).sortx(DEPT).id@o(DEPT) Do not sort records, but remove the neighboring duplicate records only 6 =demo.cursor("select * from EMPLOYEE" ).id@u(DEPT) Do not sort result set by DEPT A 1 =demo.cursor("select * from DEPT") Below is content of DEPT table: 2 =A1.id(FATHER) Return value: [null,1,2,11,12] 3 =A1.reset() 4 =A1.id@0(FATHER) Return value: [1,2,11,12]