run()

Read(1698) Label: run,

Here’s how to use run() function.

r .run( x i ,… )

Description:

Compute an expression against a record and return the modified record.

Syntax:

r.run(xi,…)

Note:

The function computes the expression x against record r and return the modified record. Usually, it is used to change the field values of r, for example, when x is col1=col2+1, it will change the field value of col1.

Parameter:

r

A record

xi

An expression, which is generally a field name or a legal expression composed of field names, and in which "~" references the current record

Return value:

The modified record

Example:

 

A

 

1

=[[12,23]].new(~(1):col1,~(2):col2)

 

2

=A1(1).run(col1=col2+1)

3

=A1(1).run(col1=col2+1,col2=col1+col2)

Note:

Difference between r.(x) and r.run(x): r.(x) computes the value of expression x and returns it; r.run(x) modifies r through the computation of x, and returns the modified r.

Related function:

A.run(x1,x2,…xi)

P.run(xi:Fi,…)

P .run( x i : F i ,…)

Description:

Compute expressions against each member of a record sequence.

Syntax:

P.run(xi:Fi,…)

Note:

The function computes expression xi for each record in record sequence/table sequence P, assigns the results to Fi field and returns P that has been modified. The expression xi uses "~" to reference the current member of P.

Parameter:

P

A record sequence/table sequence.

xi

The new value of Fi field.

Fi

A field of A.

Return value:

Table sequence

Example:

 

A

 

1

=demo.query("select DEPT,NAME,BIRTHDAY from EMPLOYEE")

2

=A1.derive(age(BIRTHDAY):Age)

3

=A2.run(Age+10:Age)

Related function:

r.run()

A.run(x1,x2,xi)

A .run( x 1 , x 2 ,… x i )

Description:

Compute one or more expressions against each member in a sequence/record sequence and return a sequence composed of values of the expression.

Syntax:

A.run(x)

Compute one expression only.

A.run(x1,x2,…xi)

Compute multiple expressions.

Note:

The function computes expressions xi with each member in sequence/record sequence A and return the modified A. For example, when x is col1=col2+1, it will change the field value of col1.

Parameter:

A

A sequence/ record sequence.

x

An expression, which is generally a field name or a legal expression that is composed of field names, and in which "~" is used to reference the current record.

Option:

@m

Use parallel algorithm to handle data-intensive or computation-intensive tasks; no definite order for the records in the result set.

@z

Perform the inverse operation; only apply to non-pure sequences.

Return value:

Sequence/Record sequence

Example:

Use run function to modify the member values.

 

A

 

1

=[1,2,3,4,5]

 

2

=A1.run(~=~*~)

[1,4,9,16,25], use "~" to reference the current member.

 

Use run function to switch from EID to Name

 

A

 

1

=demo.query("select * from EMPLOYEE").keys(EID)

 

2

=demo.query("select * from DEPARTMENT")

3

=A2.run(MANAGER=A1.select@1(EID==A2.MANAGER).NAME)

4

=demo.query("select * from EMPLOYEE")

 

 

5

=demo.query("select * from DEPARTMENT")

 

 

6

=A5.run@m(MANAGER=A4.select@1(EID==A5.MANAGER).NAME)

 

Use @m option to increase performance of big data handling.

 

Use run function to link tables

 

A

 

1

=demo.query("select * from EMPLOYEE")

 

2

=demo.query("select * from DEPARTMENT")

 

3

=A2.run(MANAGER=A1.select@1(EID== A2.MANAGER))

4

=A2.MANAGER.STATE

California. When the field value is a record, the dot operator is used to reference a member within the record.

 

Perform the inverse operation:

 

A

 

1

=[1,2,3].run(~=iterate(~~+~))

[1,3,6].

2

=[1,2,3].run@z(~=iterate(~~+~))

Use @z option to perform the inverse operation and return result: [3,5,6].

Note:

Difference between A.(x) and A.run(x):

 

A.(x) evaluates expression x and returns a sequence composed of the values of this expression;

 

A.run(x) is modifies sequence/record sequence A through the computation of x and returns A which has been modified

Related function:

r.run()

P.run(xi:Fi,…)

ch .run()

Description:

Attach a computation that assigns values to a specified field and return the original channel.

Syntax:

ch.run (xi:Fi,…)

Note:

The function attaches a computation to channel ch, which will compute expression xi on each of its records and assign the results to Fi field, and returns the original channel ch.

This is an attachment computation.

Parameter:

ch

A channel.

xi

An expression.

Fi

Field name in the given channel.

Return value:

Channel

Example:

 

A

 

1

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

 

2

=channel()

Create a channel.

3

=A2.run(SALARY+1000:SALARY)

Attach a computation to A2’s channel, which will evaluate expression SALARY+1000 and assign the results to SALARY field, and return the original channel.

4

=A2.fetch()

Execute the result set function in channel A2 and keep the current data in channel.

5

=A1.push(A2)

Be ready to push cursor A1’s data to channel A2, but the action needs to wait..

6

=A1.fetch()

Fetch data from cursor A1 while pushing data to channel A2 to execute the attached computation and keep the result.

7

=A2.result()

Get channel A2’s result:

cs .run()

Description:

Attach the action of computing expression on each record to a cursor and return the original cursor.

Syntax:

cs.run (xi:Fi,…)

Note:

The function attaches a computation to cursor cs, which will compute expression xi over each record in cursor cs and assign each result to Fi field, and returns the modified cursor cs. It supports multicursors.

This is a delayed function.

Parameter:

cs

A cursor

xi

An expression

Fi

A field of cs

Return value:

  Cursor

Example:

 

A

 

1

=connect("demo").cursor("select EID,NAME,SALARY,HIREDATE,0 as SUBSIDY from EMPLOYEE ")

Return a cursor whose data is as follows:

2

=A1.run(age(HIREDATE):HIREDATE)

Attach a computation to cursor A1, which will assign results of computing age(HIREDATE) to HIREDATE, and return the original cursor A1.

3

=A1.run((HIREDATE * 2 * SALARY):SUBSIDY)

Attach a computation to cursor A1, which will assign results of computing HIREDATE * 2 * SALARY to SUBSIDY, and return the original cursor A1.

4

=A1.fetch()

Fetch data from cursor A1 where both A2 and A3’s computations are executed (it would be better to fetch data in batches when a large amount of data is involved):

Related function:

A.run(xi:Fi,)

T.run ()

Description:

Define value assignment operation on a pseudo table and return a new pseudo table.

Syntax:

T.run (xi:Fi,…)

Note:

The function defines a computation on pseudo table T, which will compute expression xi, and assign the results to Fi, and returns a new pseudo table.

Parameter:

T

A pseudo table.

xi

An expression.

Fi

A pseudo table field.

Return value:

Pseudo table

Example:

 

A

 

1

=create(file).record(["emp.ctx"])

Below is content of composite table emp.ctx:

2

=pseudo(A1)

Generate a pseudo table object.

3

=A2.run(SALARY+1000:SALARY)

Define a computation on A2’s pseudo table, which will add 1,000 to pseudo table’s field SALARY and assign the results to the field, and return a new pseudo table.

4

=A3.import()

Import data from A3’s pseudo table while executing the computation defined in A3 on A2’s pseudo table, and return the following table:

5

=A2.run(if(GENDER=="F",1,2):GENDER)

Define a computation on A2’s pseudo table, which will compute its field GENDER – return 1 if GENDER field value is F and return 2 if it isn’t – assign the results to GENDER, and return a new pseudo table.

6

=A5.import()

Import data from A5’s pseudo table while executing the computation defined in A5 on A2’s pseudo table, and return the following table: