Mergex()

Read(303) Label: merge, cursor sequence,

Here is how to use mergex() function.

CS.mergex()

Description:

Merge data of the member cursors of a cursor sequence.

Syntax:

CS.mergex(xi,…)

Note:

CS is a sequence of cursors ordered by [xi,…], and from each cursor a sequence of records can be output. The function merges the records of these cursors by the expression xi. Members of the cursor sequence must be of the same structure. If members are multicursors, they must have the same number of parallel cursors and be segmented synchronically.

Parameters:

CS

A sequence of cursors.

xi

An expression. If perfoming merge by multiple fields, use comma to separate them, for example, x1,x2...

Options:

@u

Union operation. Remove the duplicate records from the resulting cursor obtained by unioning the cursor members of CS in certain order. By default the duplicate records are included

@i

Intersection operation. Return a cursor composed of common members of members of CS, the sequence of cursors.

@d

Difference operation. Create a new cursor by removing members of CS2&CSn from CS1

@0

Put records with null values at the end

@x

Only merge distinct records in member cursors

Return value:

A cursor

Example:

 

A

B

C

 

 

1

=demo.cursor("select * from STOCKRECORDS")

Retrieve data and return a cursor

 

2

For

 

 

3

 

=A1.fetch(500)

Fetch data from the cursor

4

 

if B3==null

break

 

5

 

else

 

 

6

 

 

=B3.sort(STOCKID)

Sort by STOCKID

7

 

 

=file("D:\\"+"a"+string(A2)+".txt").export@t(C6)

Store data retrieved each time in a file.

8

 

 

=B1=B1|file("D:\\"+"a"+string(A2)+".txt")

File object sequence

9

for B1

 

 

 

10

 

=A9.cursor@t()

 

 

11

 

=C1=C1|B10

 

File cursor sequence

12

=C1.mergex(STOCKID)

Merge members of the sequence in order by STOCKID.

13

=A12.fetch()

Get records from the merged cursor

14

=directory@p("D://*.txt")

Below are several txt files:

15

for A14

 

 

 

16

 

=file(A15).c

rsor@t()

=B14=B14|B16

 

17

=B14.mergex@i(STOCKID)

=A17.fetch()

 

 Return a cursor composed of their common members, with STOCKID already ordered.

18

=directory@p("D://*.txt")

 

The txt files are

the same as the above

19

for A18

 

 

 

20

 

=file(A19).cursor@t()

=B18=B18|B20

 

21

=B18.mergex@u(STOCKID)

=A21.fetch()

 

 Return a new cursor in which

duplicate records have been removed. STOCKID is already ordered.

 

22

=directory@p("D://*

txt")

 

The txt files are

the same as above

23

for A22

 

 

 

24

 

=file(A23).cursor@t()

=B22=B22|

24

 

25

=B22.mergex@d(STOCKID)

=A25.fetch()

 

 

A new cursor created by removing from the first cursor the members of the other cursors; STOCKID is already ordered.

26

=directory@p("D://*.txt")

 

 

 

27

for A26

 

 

 

28

 

=file(A27).cursor@t()

=B26=B26|B28

 

29

=B26.mergex@x(STOCKID)

=A29.fetch()

 

Get dinstinct recors from the cursors to create a new cursor ordered by STOCKID

Related functions:

A.merge()

cs.mergex()

Description:

Merge all parts of a cluster cursor into a local ordinary cursor.

Synatx:

cs.mergex(xi,…)

Note:

The function merges all parts of a cluster cursor by field expression xi. Parameter cs is a sequence made up of all parts of a cluster cursor ordered by field expressions [xi,…]. If cs is multicursor for a composite table and there are no parameters, perform the merge by dimension(s).

Parameters:

cs

A sequence consisting of all parts of a cluster cursor

xi

A field expression; use the comma to separate multiple expressions if it is a merge by multiple fields, like x1,x2...

Return value:

An ordinary cursor

Example:

 

A

 

1

=file@0("emp2.ctx",["127.0.0.1:8282"])

Open a cluster file

2

=A1.create()

Create a cluster composite table

3

=A2.cursor(EID,NAME;EID<8)

Return a part of the cluster cursor

4

=A2.cursor(EID,NAME;EID>495)

Return a part of the cluster cursor

5

=[A3,A4].mergex(EID)

Merge two parts of the cluster cursor in A3 and A4 by EID and return a local ordinary cursor

6

=A5.fetch()

 

 

A

 

1

[192.168.0.110:8281,192.168.18.143:8281]

 

2

=file@0("emp.ctx", A1)

Distributed composite table file

3

=A2.create()

Open a cluster composite table

4

=A3.cursor@m(;;3)

Return a cluster multicursor

5

=A4.mergex()

Perform the merge by deminsion as A4 is a multicursor for a composite table and there are no parameters

mcs.mergex()

Description:

Merge multicursors into an ordinary cursor.

Syntax:

mcs.mergex(xi,…)

Note:

The function merges multicursors by field expression xi. Parameter mcs is a sequence of multicursors ordered by field expressions [xi,…], in which each member is synchronously segmented and has the same number of segments. When mcs is a sequence of multicursors for a composite table, perform the merge automatically by dimensions.

Parameters:

mcs

A sequence of multicursors

xi

A field expression; use the comma to separate multiple expressions if it is a merge by multiple fields, like x1,x2...

Return value:

An ordinary cursor

Example:

 

A

 

1

=demo.query("select EID,NAME,GENDER,SALARY from EMPLOYEE where EID<6")

Data is ordered by EID

2

=demo.query("select EID,NAME,GENDER,SALARY from EMPLOYEE where EID<10 and EID>5")

Data is ordered by EID

3

=[A1.cursor(),A2.cursor()].mcursor()

Union A1 and A2 into a multicursor

4

=[A1.cursor(),A2.cursor()].mcursor()

Same as A3

5

=[A3,A4].mergex(EID)

Merge A3 and A3’s multicursors by EID

6

=A5.fetch()