T.cursor(x:C,…;wi…;k:n)

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. The process is like this: split zone table 1 into n segments, divide each of the other zone tables synchronously according to the zone table 1, retreive the kth segment of each zone table, and merge them by the dimension and return the result.

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 ofDefault number of subcursors in a multicursor set inTool-Optionsif n is absent

@v

Generate a pure table sequence-based column-wise cursor, which has higher performance than regular cursors

@x

Automatically close the entity table/in-memory table after data in the cursor is fetched

@o

Get records in order without merging zone tables when T is a multizone composite table; all zone tables are segmented synchronously

@w

Used on a multizone composite table;

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; retrieve a zone table after the first one wholly if they are small enough;

Handle the deletion 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

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:

1K=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, ordinal 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, ordinal numbers of Ki values in Ti will be assigned to Ki.

w is a filter expression; you can reference Ki in w.

3K: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.

4K:Ti:null

Filter away all records that satisfy K:Ti.

5K:Ti:#

Locate records according to ordinal numbers, compare ordinal 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 (kn) representing the kth segment

n

A positive integer representing the number of segments; return all records when parameters k:n are absent

Return value:

A 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, promptingStream 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.

6

=A3.cursor@o(;;1:3)

With @o option, do not perform merge on the multizone composite table but retrieve records in the order of segments instead; below is the content of the returned cursor:

The upper half of the table is records of zone table 1.nc.ctx and the lower half contains records of 2.nc.ctx.

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 ordinal 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 ordinal 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 perform update merge:

 

A

 

1

=connect("demo").cursor("select  EID,NAME,GENDER  from employee") 

Return a cursor whose content is as follows:

2

=file("ec.ctx":[1,2])

Homo-name files group: 1.ec.ctx and 2.ec.ctx.

3

=A2.create@y(#EID,NAME,GENDER;if(GENDER=="F",1,2))

Create a multizone composite table, set EID as its key and put records where GENDER is F to 1.ec.ctx and the other records to 2.ec.ctx.

4

=A3.append@ix(A1)

Append cursor A1’s data to the multizone composite table.

5

=create(EID,NAME,GENDER).record([1,"AAA","M"]).cursor()

Return a cursor whose content is as follows:

6

=file("ec.ctx":[3])

 

7

=A6.create@y(#EID,NAME,GENDER;3)

Add a zone table named 3.ec.ctx.

8

=A7.append@i(A5)

Append cursor A5’s data to zone table 3.ec.ctx; both zone table 1.ec.ctx and zone table 3.ec.ctx contain records whose primary key values are [1] .

9

=file("ec.ctx":[1,2,3]).open()

Open multizone composite table ec.ctx.

10

=A9.cursor(;;1:3)

Split the multizone composite table into multiple segments, retrieve the first segment and return a cursor, whose content is as follows:

11

=A9.cursor@w(;;1:3)

With @w option, perform update merge and return a cursor whose content is as follows:

Use @w option to recognize deletion mark:

 

A

 

1

=connect("demo").cursor("select  EID,NAME,GENDER  from employee") 

 

2

=A1.derive(false: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 deletion 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([2,true,,,0,true,,]).cursor()

Return a cursor 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 deletion mark field.

10

=A9.append@i(A7)

Append cursor A1’s records to zone table 3.ecd.ctx, where the deletion mark field value corresponding to the record whose primary key value is 2 is true and the record whose primary key value is 0 is a newly-added one in the zone table – which means the latter’s key value is unique.

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 composite table ecd.ctx as a cursor and recognize the deletion mark – that is, do not return the record whose primary key value is 2 to the cursor, and retain the record whose value is unique and marked by deletion mark – that is, the record whose primary key value is 0 is returned to the cursor, whose content is as follows: