Here’s how to use select() functions.
Description:
Return members of a sequence which satisfy a condition.
Syntax:
A.select(x) |
|
A.select(x1:y1, x2:y2, ......xi:yi) |
The simplified syntax of multiple-condition query using "&&", which is equal to A.select(x1== y1 && x2== y2 &&...... xi==yi) |
Note:
The function computes expression x against each member of the sequence A, and returns a new sequence composed of those members which make x return true.When there are no parameters, return all the members. If the name of a to-be-referenced column of the sequence is the same as a cell name, the sequence name should be attached before the column name in the expression.
Parameter:
A |
A sequence. |
x |
A boolean expression, which may be null. when using @b option, x should be an expression whose return value is a number. |
xi:yi |
xi is an expression, and yi is a comparing value. |
Option:
@1 |
Return the first member that fulfills the condition. |
@z |
Search the members from back to front |
@b |
Use binary search when A is an ascendingly ordered sequence. If A is not ascendingly ordered, this option should not be used, or it may bring about the incorrect result. When the option works with A.select(x1:y1, x2:y2, ......xi:yi) to find out members that make x in cmp(x,y) return the value 0, you can just write A.select@b(x1:y1, x2:y2, ......xi:yi) without cmp(). |
@m |
Use parallel algorithm to handle data-intensive or computation-intensive tasks; no definite order for the records in the result set; it can’t be used with @1bz options. |
@t |
Return an empty table sequence with data structure if the grouping and aggregate operation over the sequence returns null |
@c |
Enable getting the first ineligible member from left to right beginning from the first member |
@r |
Enable searching for the first eligible members from left to right and getting all members after it (inclusive) |
@v |
Return result as a pure table sequence when sequence A is a pure table sequence; return a pure sequence by default |
Return value:
A new sequence composed of members which make the expression x return true
Example:
|
A |
|
1 |
[2,5,4,3,2,1,4,1,3] |
|
2 |
=A1.select(~>3) |
[5,4,4] |
3 |
=A1.select@1(~>3) |
5 |
4 |
=A1.select@z(~>3) |
[4,4,5] |
5 |
=[1,2,3,4,5,6].select@b(~-4) |
[4] |
6 |
=demo.query("select * from EMPLOYEE order by EID") |
|
7 |
=A6.select(EID==9) |
|
8 |
=A6.select@b(EID-9) |
The expression x needs to be converted to a number with @b |
9 |
=A6.select(EID:9) |
|
10 |
=A6.select@b(EID:9) |
It’s no need to execute the conversion by using the colon when @b exists |
11 |
=A6.select(GENDER:"F",SALARY:7000) |
|
12 |
=A6.select@v() |
Return all members as there are no parameters; return a pure table sequence as @v option there is @v option |
13 |
=A6.select@m(EID==9) |
Use @m option to increase performance of big data handling. |
14 |
=A6.select@t(EID==501) |
Return an empty table sequence with the data structure |
15 |
=to(3).new(~:ID,~*~:A1) |
|
16 |
=A15.select(A15.A1==4) |
When a column name is namesake with a cell name, the column name referenced in an expression should be preceded by the corresponding sequence name |
17 |
[1,3,5,7,9,11,13] |
|
18 |
=A17.select@c(~<10) |
[1,3,5,7,9]; get the first ineligible member from left to right |
19 |
=A17.select@zc(~>10) |
[13,11]; get the first ineligible member backwards |
20 |
=A17.select@r(~>10) |
[11,13] |
.Related function:
Description:
Return members of a table sequence which satisfy a condition.
Syntax:
T.select(x) |
Note:
The function computes expression x against each member of table sequence T, and returns a new table sequence composed of those members which make x return true
Options:
@i |
Reuse T’s index, which may disrupt the order of the result set |
Parameter:
T |
A table sequence |
x |
Filtering expression; can be null |
Return value:
A table sequence
Example:
|
A |
|
1 |
=demo.query("select * from DEPT").keys@i(DEPTID) |
Create an index |
2 |
=A1.select@i(FATHER:12) |
Reuse A1’s index |
Description:
Select records from a pseudo table according to a specified condition.
Syntax:
T.select(x) |
|
Note:
The function calculates expression x on each record of pseudo table T and returns T containing records that make x true. It returns the orginal pseudo table retaining all its records when parameter x is absent.
Parameter:
T |
A pseudo table |
x |
A Boolean expression that is a filter condition, which can be null |
Return value:
A pseudo table object
Example:
|
A |
|
1 |
=create(file).record(["D:/file/pseudo/app.ctx"]) |
|
2 |
=pseudo(A1)
|
Generate a pseudo table object |
3 |
=A2.select(eid>7) |
Get records that satisfy eid>7 from A2’s pseudo table and return it |
4 |
=A2.select() |
Return A2’s pseudo table having all its original records |
Description:
Return a channel with records that meet the given condition.
Syntax:
ch.select(x)
Note:
The function calculates expression x against each of the records in channel ch, and returns the channel containing records that make values of x true. When the parameter x is omitted, return the original channel with all records. This is an attached computation.
Parameter:
ch |
Channel |
x |
Boolean expression |
Return value:
The original channel with records that meet the given condition
Example:
|
A |
|
1 |
=demo.cursor("select * from SALES") |
|
2 |
=channel() |
Create a channel |
3 |
=A2.select(ORDERID>100) |
Attach a ch.select() operation to A2’s channel to get records meeting the condition ORDERID>100 and return the channel with these eligible records |
4 |
=A2.fetch() |
Fetch and store the existing data in the channel |
5 |
=A1.push(A2) |
Push data in A1’s cursor into A2’s channel |
6 |
=A1.fetch() |
|
7 |
=A2.result() |
Get result from the channel |
Description:
Send records in a channel that can’t meet the given condition into another channel.
Syntax:
ch.select(x,ch’)
Note:
The function calculates expression x against each of the records in channel ch, and sends those records over which the value of x is false into channel ch’.
Parameter:
ch |
Channel |
x |
A boolean expression |
ch’ |
Channel |
Return value:
Channel ch’
Example:
|
A |
|
1 |
=demo.cursor("select EID,NAME,SALARY from EMPLOYEE " ) |
|
2 |
=channel() |
Create a channel |
3 |
=channel() |
Create a channel |
4 |
=A1.push(A2) |
Push data in A1’s cursor into A2’s channel |
5 |
=A2.select(EID<5,A3) |
Push records in A2’s channel that can’t meet the condition EID<5 into A3’s channel |
6 |
=A2.fetch() |
Attach ch.fetch() function that gets the final result set to A2’s channel to fetch and store the existing data in A2’s channel |
7 |
=A3.fetch() |
Attach ch.fetch() function that gets the final result set to A3’s channel to fetch and store the existing data in A3’s channel |
8 |
=A1.skip() |
|
9 |
=A2.result() |
|
10 |
=A3.result() |
|
Description:
Return a cursor with records meeting the given condition.
Syntax:
cs.select(x)
Note:
The function calculates expression x against each of the records in cursor cs and returns a cursor containing records that can make the value of x true. When parameter x is omitted, return the original cursor with all records. The function supports multicursors.
Parameter:
cs |
A cursor |
x |
A boolean value |
Return value:
The original cursor with eligible records
Example:
|
A |
|
1 |
=demo.cursor("select * from SCORES") |
|
2 |
=A1.select(STUDENTID>10) |
Select the records where STUDENTID is greater than 10 from the SCORE table |
3 |
=A2.fetch() |
|
Description:
Send records in a cursor that can’t meet the given condition into a channel.
Syntax:
cs.select(x,ch’)
Note:
The function calculates expression x against each of the records in cursor cs, and sends those records over which the value of x is false into channel ch’.
Parameter:
cs |
Cursor |
x |
A boolean value |
ch’ |
Channel |
Return value:
Channel ch’
Example:
|
A |
|
1 |
=demo.cursor("select EID,NAME,SALARY from EMPLOYEE" ) |
|
2 |
=channel() |
Create a channel |
3 |
=A1.select(EID<5,A2) |
Push records that don’t meet the condition EID<5 into A2’s channel |
4 |
=A2.fetch() |
Fetch and store the existing data in the channel |
5 |
=A1.fetch() |
|
6 |
=A2.result() |
Get result from the channel |
Description:
Write the records that unsatisfy the specified expression into a bin file.
Syntax:
cs.select(x;f)
Note:
The function computes expression x over each record of cursor cs and writes the records that unsatisfy expression x into the bin file f.
Parameter:
cs |
Cursor |
x |
Boolean expression |
f |
bin file |
Return value:
The original cursor
Example:
|
A |
|
1 |
=demo.cursor("select * from dept") |
|
2 |
=file("dept.btx") |
|
3 |
=A1.select(DEPTID<5;A2) |
Write the records that cannot meet the condition DEPTID<5 into bin file dept.btx |
4 |
=A3.fetch() |
|