Description:
Segment an entity table or an in-memory table or a multizone composite table and return the cursor of a specified segment.
Syntax:
T.cursor(x:C,…;wi,…;k:n)
Note:
The function computes expression x over data in entity table/in-memory table/multizone composite table T, filters the result table according to filtering expression wi, splits it into n segment and returns the kth segment as a cursor, where C is the field name. If T is an attached table, the queried data is allowed to include a primary table field.
Segment all zone tables synchronously and merge the result when T is a multizone composite table.
Option:
@m |
The T.cursor@m(x:C…;wi,...;n) function with this option generates a multicursor segmented into n parts. n is an integer; the function returns an ordinary cursor if n<2; use the value of【Default number of subcursors in a multicursor】 set in【Tool】-【Options】if n is absent. |
@v |
Generate a pure table sequence-based columnwise cursor, which has higher performance than regular cursors. |
@x |
Automatically close the entity table/in-memory table after data in the cursor is fetched. |
@g |
When T is a multizone composite table and if group() operation will be executed on the result cursor, use this option to speed up the computation. |
@w |
Used on a multizone composite table with update mark; Perform update merge; when zone tables share a same key value, ignore the record contained in the zone table with a smaller number; segmentation is performed according to the way zone table 1 is split; Handle the update mark and do not return records with a deletion mark to the cursor; but if the key value of a record with the deletion mark is unique in the multizone composite table, just retain it; This option enables retrieving key field(s) as well as the deletion mark field, if there is one, forcefully. |
@z |
Get data in the inverse order; do not support segmentation in this case. |
@p |
Perform MERGE by the first field when parameter T is a multizone composite table. |
Parameter:
T |
An entity table or an in-memory table or a multizone composite table |
x |
Expression; by default, all fields of T will be returned to the cursor |
C |
Column alias; can be omitted |
wi |
Filtering condition; separate multiple conditions by comma(s) and their relationships are AND; besides regular filtering expressions, you can also use the following five types of syntax in a filtering condition, where K is a field in the entity table: 1.K=w w usually uses expression Ti.find(K) or Ti.pfind(K), where Ti is a table sequence. When value of w is null or false, the corresponding record in the entity table will be filtered away; when w is expression Ti.find(K) and the to-be-selected fields C,... contain K, Ti’s referencing field will be assigned to K; when w is expression Ti.pfind(K) and the to-be-selected fields C,... contain K, sequence numbers of K values in Ti will be assigned to K. 2.(K1=w1,…Ki=wi,w) Ki=wi is an assignment expression. Generally, parameter wi can use expression Ti.find(Ki) or Ti.pfind(K), where Ti is a table sequence; when wi is expression Ti.find(K) and the to-be-selected fields C,... contain Ki, Ti’s referencing field will be assigned to Ki correspondingly; when wi is expression Ti.pfind(Ki) and the to-be-selected fields C,... contain Ki, sequence numbers of Ki values in Ti will be assigned to Ki. w is a filter expression; you can reference Ki in w. 3.K:Ti Ti is a table sequence. Compare Ki value in the entity table with key values of Ti and discard records whose Ki value does not match; when the to-be-selected fields C,... contain K, Ti’s referencing field will be assigned to K. 4.K:Ti:null Filter away all records that satisfy K:Ti. 5.K:Ti:# Locate records according to sequence numbers, compare sequence numbers of records in table sequence Ti according to the entity table’s K values, and discard non-matching records; when the to-be-selected fields C,... contain K, Ti’s referencing field will be assigned to K |
k |
A positive integer (k≤n) representing the kth segment |
n |
A positive integer representing the number of segments; return all records when parameters k:n are absent |
Return value:
Unicursor/Multicursor
Example:
|
A |
|
1 |
for 100 |
|
2 |
=to(10000).new(#:k1,rand():c1).sort@o(k1) |
Return a table sequence:
|
3 |
=to(10000).new(#:k1,rand(10000):c2,rand()*1000:c3).sort@o(k1) |
Return a table sequence:
|
4 |
=A2.cursor() |
Return a cursor. |
5 |
=A3.cursor() |
Return a cursor. |
6 |
=file("D:\\tb4.ctx") |
Generate a composite table file. |
7 |
=A6.create(#k1,c1) |
Create A6’s base table whose key is k1. |
8 |
=A7.append(A4) |
Append data of A4’s cursor to A7’s base table. |
9 |
=A7.attach(table4,c2,c3) |
Create an attached table table4 for the base table. |
10 |
=A9.append(A5) |
Append data of A5’s cursor to attached table table4. |
11 |
=A9.cursor(;c2<1000;2:3) |
Divide records meeting c2<1000 in the attached table into 3 segments and return a cursor of all columns of the second segment. |
12 |
=A11.fetch() |
Fetch data from A11’s cursor.
|
13 |
=A7.cursor(;c1>0.99) |
Get records meeting c1>0.99 from A7’s base table |
14 |
=A13.fetch() |
Fetch data from A13’s cursor. b |
15 |
=A9.cursor(k1,c1:b,c3;c3>999) |
Get the base table’s k1 field and c1 field from attached table table4, as well as c3 field of the attached table, according to condition c3>999, and rename c1 b. |
16 |
=A15.fetch() |
Fetch data from A15’s cursor.
|
17 |
=A9.cursor@m(;;3) |
Use @m option to generate a multicursor from attached table table4. |
|
A |
|
1 |
=file("employee1.ctx") |
Generate composite table file employee1.ctx. |
2 |
=A1.create@y(#EID,NAME,GENDER,SALARY) |
Create the base table of composite table employee1.ctx, which contains columns EID, NAME, GENDER and SALARY and where EID is the dimension. |
3 |
=connect("demo").cursor("select EID,NAME,GENDER,SALARY from employee") |
Return a cursor. |
4 |
=A2.append@i(A3) |
Append records of A3’s cursor to A2’s base table. |
5 |
=A2.cursor@v(;SALARY>1000;) |
Return a column-wise cursor, and automatically close A2’s composite table after data is fetched from it.
|
6 |
=A5.groups(GENDER;avg(SALARY):SALARY_AVG) |
Perform grouping & aggregation operation on A5’s cursor.
|
7 |
=A2.cursor(;SALARY>2000) |
Error is reported, prompting“Stream Closed” . |
When T is a multizone composite table:
|
A |
|
1 |
=100000.new(~:ID,rand(2):FM).cursor() |
|
2 |
=file("nc.ctx":[1,2]) |
Generate a homo-names files group. |
3 |
=A2.create@y(#ID,FM;if(FM==1,1,2)) |
Return a multizone composite table. |
4 |
=A3.append@x(A1) |
Append cursor A1’s data to the multizone composite table; below is content of the multizone composite table: 1.nc.ctx 2.nc.ctx
|
5 |
=A3.cursor(;;1:3) |
Split the multizone composite table into three segments, return the first segment of each zone table, merge them and return result as a cursor:
Data in zone table 1 and that in zone table 2 has been merged by their dimensions. |
Use special types of filtering conditions:
|
A |
|
1 |
=file("emp.ctx") |
|
2 |
=A1.open() |
Open the composite table file. |
3 |
=A2.import() |
As no parameters are present, return all data in the entity table.
|
4 |
=5.new(~:ID,~*~:Num).keys(ID) |
Generate a table sequence using ID as the key.
|
5 |
=A2.cursor(EID,NAME;EID=A4.find(EID)) |
Use K=w filtering mode; in this case w is Ti.find(K) and entity table records making EID=A4.find(EID) get null or false are discarded; EID is the selected field, to which table sequence A4’s referencing field are assigned.
|
6 |
=A2.cursor(EID,NAME;EID=A4.pfind(EID)) |
Use K=w filtering mode; in this case w is Ti.pfind(K) and entity table records making EID=A4.pfind(EID) get null or false are discarded; EID is the selected field, to which its sequence numbers in table sequence A4 is assigned.
|
7 |
=A2.cursor(EID,NAME;EID:A4) |
Use K:Ti filtering mode; compare the entity table’s EID values with the table sequence’s key values and discard entity table records that cannot match.
|
8 |
=A2.cursor(NAME,SALARY;EID:A4) |
This is a case where K isn’t selected; EID isn’t the selected field, so only filtering is performed.
|
9 |
=A2.cursor(EID,NAME;EID:A4:null) |
Use K:Ti:null filtering mode; compare the entity table’s EID values with the table sequence’s key values and discard entity table records that can match.
|
10 |
=A2.cursor(EID,NAME;EID:A4:#) |
Use K:Ti:# filtering mode; compare with sequence numbers of table sequence’s records according to the entity table’s EID values, and discard records that cannot match.
|
11 |
=connect("demo").query("select top 2 NAME,GENDER from employee").keys(NAME) |
Return a table sequence using NAME as the key.
|
12 |
=A2.cursor(EID,NAME;(EID=A4.find(EID),NAME=A11.find(NAME),EID!=null&&NAME!=null)) |
Use (K1=w1,…Ki=wi,w) filtring mode; return records that meet all conditions |
Use @z option to get data in the inverse order:
|
A |
|
1 |
=100000.new(~:ID,rand(2):FM) |
|
2 |
=file("curz.ctx") |
|
3 |
=A2.create@y(#ID,FM) |
Create a composite table. |
4 |
=A3.append@i(A1) |
|
5 |
=A4.cursor().fetch() |
Return the composite table as a cursor and fetch data from the cursor:
|
6 |
=A4.cursor@z().fetch() |
Use @z option to get data in the inverse order and fetch data from the cursor as follows:
|
Use @w option to recognize update mark:
|
A |
|
1 |
=connect("demo").cursor("select EID,NAME,GENDER from employee") |
|
2 |
=A1.derive(:Defiled) |
|
3 |
=A2.new(EID,Defiled,NAME,GENDER) |
Return a cursor whose content is as follows:
|
4 |
=file("ecd.ctx":[1,2]) |
Define a homo-name files group: 1.ecd.ctx and 2.ecd.ctx. |
5 |
=A4.create@yd(#EID,Defiled,NAME,GENDER;if(GENDER=="F",1,2)) |
Create a multizone composite table, set EID as the key, use @d option to make Defiled field the update mark and put records where GENDER is F to 1.ed.ctx and the other records to 2.ed.ctx. |
6 |
=A5.append@ix(A3) |
Append cursor A3’s data to the multizone composite table. |
7 |
=create(EID,Defiled,NAME,GENDER).record([0,true,,,1,true,,, 2,false,"BBB","F"]) |
Return a table sequence whose content is as follows:
|
8 |
=file("ecd.ctx":[3]) |
|
9 |
=A8.create@yd(#EID,Defiled,NAME,GENDER;3) |
Add zone table 3.ecd.ctx and make Defiled the update mark field. |
10 |
=A9.append@i(A7) |
Append table sequence A7’s records to zone table 3.ecd.ctx. |
11 |
=file("ecd.ctx":[1,2,3]).open() |
Open composite table file ecd.ctx. |
12 |
=A11.cursor().fetch() |
Return all data in the multizone composite table ecd.ctx to the cursor; below is the returned content:
|
13 |
=A11.cursor@w().fetch() |
With @w option, return data in multizone composite table ecd.ctx as a cursor and recognize the update mark: Do not return the record whose EID value is 2 and where the update mark value is true (meaning to-be-deleted) to the cursor; Update the record where EID value is 2 and marked by false (meaning to-be-modified); Retain the record where EID value is 0, marked by true (meaning to-be-deleted), and whose key value is unique, and return it to the cursor; Below is content of the returned cursor:
|