memory()

Read(3530) Label: memory,

Here’s how to use memory() function.

cs.memory( K,… )

Description:

Generate an in-memory table from a cursor.

Syntax:

cs.memory(K,…)

Note:

The function generates an in-memory table, whose key is K, from a cursor. When parameter K is absent, the newly-generated in-memory table will inherit the cursor’s key.

Parameter:

K

The key

cs

A cursor

Option:

@p

Group the would-be in-memory table by the first field; this requires that the cursor is ordered by the first field

@v

The option requires that data in the cursor should be of a pure table sequence and it enables to return a column-wise in-memory table

@x

Automatically close the cursor after the in-memory table is generated

Return value:

An in-memory table

Example:

 

A

 

1

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

Return the cursor with retrieved data.

2

=A1.memory(EID)

Return an in-memory table whose key is EID.

 

 

A

 

1

=connect("demo").query("select  EID,NAME,GENDER,SALARY  from  employee").sort(EID )

Return a table sequence ordered by EID.

2

=A1.cursor()

Return a cursor.

3

=A2.memory@p(EID)

Generate an in-memory table from A2’s cursor, which is segmented by the first field EID.

Generate a column-wise in-memory table:

 

A

 

1

=to(1000).new(~:ID,~*~:pNum)

Generate a table sequence of the following structure:

2

=A1.cursor()

Generate a cursor that contains a pure table sequence.

3

=A2.memory@v()

@v option enables to generate a column-wise in-memory table.

cs.memory( K,… )

Description:

Generate a cluster in-memory table from a cluster cursor.

Syntax:

cs.memory(K,…)

Note:

According to cluster cursor cs, the function generates a cluster in-memory table that distributed the same way as cs and whose key is K. If cs is a cluster multicursor, load a series of cursors in order.

Parameter:

K

The key; can be omitted

cs

A cluster cursor

Return value:

A cluster in-memory table

Example:

 

A

 

1

=file("test0.ctx","169.254.121.62:8281")

Open a cluster file.

2

=A1.open()

Open a cluster table.

3

=A2.attach(table)

Retrieve cluster table table.

4

=A3.cursor(NAME,GENDER;EID<6)

Get NAME field and GENDER field where EID<6 from cluster table table and return them as a cursor.

 5

=A4.memory(GENDER)

Generate a cluster in-memory table whose key is GENDER from a cluster cursor.

memory( h,V )

Description:

Generate a cluster in-memory table from a local in-memory table.

Syntax:

memory(h,V)

Note:

The function generates a cluster in-memory table from local in-memory table V, which is stored in a global variable, held in node sequence h.

Parameter:

h

A node sequence

V

An in-memory table’s global variable

Return value:

A cluster in-memory table

Example:

Suppose the global variable arg1 is already assigned value using env(v, data) in the initiation script init.dfx:

 

A

 

1

=memory(["192.168.31.72:8281","192.168.31.72:8291"],arg1)

Generate a cluster in-memory table from the local in-memory table arg1.

2

=A1.cursor().fetch()

T.memory()

Description:

Convert a table sequence to an in-memory table.

Syntax:

T.memory()

Note:

The function converts table sequence T into an in-memory table. If T is a pure table sequence, keep it pure.

Parameter:

T

A table sequence or a pure table sequence; if the table sequence has key an index, they will be inherited

Option:

@o

Directly use records of the original table sequence; when data of the original table sequence changes, the data in the returned in-memory table follows to change; by default the function copies and convert data in the original table sequence; in this case, data in the in-memory table does not follow to change even if data in the original table sequence changes

Return value:

In-memory table

Example:

 

A

 

1

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

 

2

=A1.keys(EID)

Set EID as A1’s key.

3

=A1.memory()

Convert table sequence A1 to an in-memory table, during which the key is inherited.

4

=A1.memory@o()

 

5

=A1.insert(0)

Append an empty record in the end of the original table sequence.

Check A2 and find that no empty record is displayed at the end; check A3 and find that there is an empty record at the end

6

=demo.query@v("select * from DEPT")

Return a pure table sequence.

7

=A6.memory()

Convert A6’s pure table sequence to an in-memory table and keep it pure.

T.memory( C,…;w )

Description:

Generate an in-memory table from an entity table.

Syntax:

T.memory(C,…;w)

Note:

The function filters entity table T according to filtering condition w and imports the data into the memory to generate an in-memory table containing column C. we can handle an in-memory table as we do to a table sequence. When parameter C,… is absent but parameter w is present, the semicolon before w can’t be omitted. If a column C is preceded by # in the entity table, column C will be the key of in-memory table T. Use null to record a C value if it does not exist in T. The in-memory table inherits the entity table’s key if you don’t set a key for it.

Parameter:

C

A column name; import all columns when the parameter is omitted

w

Filtering condition; won’t perform filtering when the parameter is omitted

T

An entity table in a composite table

Option:

@p

Group the would-be in-memory table by the first field, and this requires that the entity table must be ordered by the first field; when the entity table is already segmented and the to-be-imported fields include its first field, the result in-memory table will inherit the composite table’s segmentation property

@v

The option requires that the entity table be a pure table sequence and it enables to return a column-wise in-memory table

@x

Automatically close the entity table after the in-memory table is generated

@w

Used on a multizone composite table;

Perform update merge; ignore the record in the zone table having the smaller number when there are same key values in two zone tables;

Split zone tables according to the way of segmenting the first zone table; first read certain zone tables after the first one wholly if they are small enough

Return value:

An in-memory table or a column-wise in-memory table

Example:

 

A

 

1

=file("D:\\employees.ctx")

employees is an existing composite table file.

2

=A1.open()

Open the composite table.

3

=A2.attach(t1)

Return the composite table’s attached table t1.

4

=A2.memory()

Generate an in-memory table using all columns of the base table.

5

=A2.memory(EID,Dept,Name;EID<5)

Get some columns where EID<5 from the base table to generate an in-memory table.

6

=A3.memory()

Get all columns from the attached table to generate an in-memory table.

 

 

A

 

1

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

Return a cursor ordered by EID.

2

=file("emp.ctx")

Generate a composite table file.

3

=A2.create@yp(#EID,NAME,GENDER,SALARY)

Create the composite table’s base table and use the first field as the segmentation key.

4

=A3.append@i(A1)

Append data of the cursor to the base table.

5

=A2.open()

Open the composite table file.

6

=A5.memory@p(EID,NAME)

Generate an in-memory table from A5’s entity table; @p option enables using the first field as the segmentation field, and as the composite table is already segmented and the fields A6 retrieves include the first field EID, the generated in-memory table will inherit the composite table’s segmentation property.

Create a column-wise in-memory table:

 

A

 

1

=to(1000).new(~:ID,~*~:pNum).cursor()

Return a cursor that contains a pure table sequence of the following structure:

2

=file("tb1.ctx")

Generate a composite table file.

3

=A2.create@y(#ID,pNum)

Generate the composite table’s base table.

4

=A3.append@i(A1)

Append data of the cursor to the base table.

5

=A4.memory@v()

@v option enables to return a column-wise in-memory table.

Generate an in-memory table from a multizone composite table:

 

A

 

1

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

Return a cursor whose content is as follows:

2

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

Define a homo-name files group: 1.em.ctx and 2.em.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.em.ctx and the other records to 2.em.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("em.ctx":[3])

 

7

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

Add a zone table named 3.em.ctx.

8

=A7.append@i(A5)

Append cursor A5’s data to zone table 3.em.ctx and now both 1.em.ctx and 3.em.ctx have a record whose primary key is [1] .

9

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

Open multizone composite table em.ctx.

10

=A9.memory()

Generate an in-memory table from the multizone composite table:

11

=A9.memory@w()

Generate an in-memory table from the multizone composite table and use @w option to perform update merge.

T.memory( C,…;w )

Description:

Generate a cluster in-memory table from a cluster entity table.

Syntax:

T.memory(C,…;w)

Note:

The function generates a cluster in-memory table, which inherits the zone table expression, from a cluster entity table T, which must have at least one dimension that is used to segment T and facilitates the segmentation. Clear a node’s memory at exit; will perform auto-clear when timeout occurs.

Parameter:

C

A column name; import all columns when the parameter is omitted

w

Filtering condition; won’t perform filtering when the parameter is omitted

T

A cluster composite table’s entity table with dimensions

Return value:

Cluster in-memory table object

Example:

 

A

 

1

=file("emp1.ctx",["192.168.0.116:8281","192.168.0.129:8281"])

Open a cluster file.

2

=A1.open()

Generate a cluster table.

3

=A2.attach(t1)

Get cluster table t1.

4

=A3.memory(NAME,GENDER;EID<5)

Get columns NAME and GENDER with EID being less than 5 from t1 to generate an in-memory table.