fetch()

Read(1582) Label: fetch,

Here’s how to use fetch() function.

cs .fetch()

Description:

Fetch one or more records from a cursor/cluster cursor.

Syntax:

cs.fetch(n;x)

Note:

Only one of the parameters n and x is valid. The function fetches n records when n is valid, or fetches records continuously till the value of expression x (Here x doesn’t return a boolean value) changes or becomes true (Here x returns a boolean value) when x is valid, and then returns them as a sequence/record sequence/table sequence or returns null if the cursor has already been fetched out. It is often used to retrieve a large amount of data in batches. When both n and x are omitted, the function returns all records in a cursor and closes cursor.

Parameter:

cs

A cursor/cluster cursor

n

An integer

x

Grouping expression, according to which cs is sorted. With x, n will be ignored

Option:

@0

Won’t actually fetched out the selected data from the cursor. The option enables an action functionally equivalent to copying the data; it doesn’t support parameter x.

@x

Close the cursor after data is fetched.

Return value:

   A sequence/record sequence/table sequence

Example:

 

A

 

1

=demo.cursor("select * from EMPLOYEE order by SALARY desc")

Return a cursor of retrieved data sorted by SALARY.

2

=A1.fetch@0(3)

Select top 3 highest-paid employees.

3

=A1.derive(interval@y(BIRTHDAY,HIREDATE):EntryAge, age(HIREDATE):WorkAge)

IMG_256

With @0 option used in A2, A3 fetches data from a complete cursor

4

=A1.fetch()

 

5

=demo.cursor("select * from EMPLOYEE order by SALARY desc")

 

6

=A1.fetch(;SALARY)

Stop data retrieval when SALARY change to select a group of highest- and equally-paid employees..

7

=A1.fetch()

Return the remaining records in the cursor.

8

=demo.cursor("select * from EMPLOYEE order by SALARY desc")

 

9

=A8.fetch@x(3)

Close the cursor after data is fetched.

10

=demo.cursor("select * from EMPLOYEE order by SALARY desc")

 

11

=A10.fetch(3;SALARY==13000)

Stop data retrieval when the value of the expression is true

 

 

A

 

1

[192.168.0.110:8281,192.168.18.143:8281]

A sequence of nodes

2

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

1.emp.ctx on node 192.168.0.110 holds a part where EID is from 1 to 250 and 2.emp.ctx on node 192.168.18.143 holds another part where EID is from 251 to 500

3

=A2.open()

Open a cluster homo-name files group

4

=A3.cursor()

Return a cluster cursor

5

=A4.fetch()

Fetch records form the cluster cursor

Related function:

db.cursor()

cs.skip()

ch .fetch()

Description:

Fetch and store the existing data in a channel.

Syntax:

ch.fetch(f)

Note:

The function fetches and stores the existing data in channel ch; write result of data retrieval to bin file f when parameter f is present. It is a result set generation function.

Parameter:

ch

Channel

f

A bin file

Return value:

Channel

Example:

 

A

 

1

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

 

2

=channel()

Create a channel

3

=channel()

 

4

=A2.select(ORDERID>100)

Attach ch.select() operation to the channel

5

=A3.select(ORDERID>100)

 

6

=A2.fetch()

Attach ch.fetch() function that returns the final result to A2’s channel while retaining the exisitng data in the channel

7

=A3.fetch("sales.btx")

Attach ch.fetch() function that gets the final result set to A3’s channel, and define writing result to bin file sales.btx in the main directory

8

=A1.push(A2,A3)

Push A1’s data in into the channel

9

=A1.fetch()

 

10

=A2.result()

Get the result of performing the operation from the channel

mcs .fetch()

Description:

Get records from a multicursor.

Syntax:

mcs.fetch()

Note:

The function gets all records from a multicursor. The order of the resulting records could be different from their orginal order.

Parameter:

mcs

Multicursor

Return value:

Record sequence

Example:

 

A

 

1

=file("D:/txt_files/orders.txt").cursor@m()

Return a multicursor

2

=A1.fetch()

Fetch records from a multicursor

3

=file("D://tb1.txt").import()

tb1.txt contains 10w rows

4

=A3.cursor()

Generate an ordinary cursor

5

=A4.fetch(15000)

Fetch the first 15000 rows

6

=A3.cursor@m(10)

Generate a multicursor

7

=A6.fetch(15000)

Fetch the first 15000 rows

Here the fetched records are different from those in A5. With a multicursor, data is fetched from each cursor and then unioned; while with an ordinary cursor, data is sequentially fetched