Here’s how to use id() function.
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.
Parameters:
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 |
Options:
@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 |
Return value:
The new sequence composed of the distinct values of x
Example:
|
A |
|
1 |
=demo.query("select * from EMPLOYEE") |
|
2 |
=A1.id(DEPT) |
|
3 |
=A1.id@o(DEPT) |
No sorting |
4 |
=A1.id([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 |
Related functions:
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.
Parameters:
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() |
|
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.
Parameters:
cs |
Cursor |
xi |
Expression; use comma to separate multiple expressions |
n |
Integer; return all values when omitted |
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) |
|