run()

Read(780) 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, assign the results to Fi field and return 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:

The table sequence P that has been modified

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.

Return value:

The modified sequence/record sequence A

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.

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:

Compute an expression against each of the records in a channel and return the channel with new field values.

Syntax:

ch.run (xi:Fi,…)

Note:

The function computes expression xi against each of the records in channel ch, assigns the results to Fi field and returns the original channel with new field values.  This is an attached computation.

Parameter:

ch

Channel

xi

New values of Fi field

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 ch.run() operation to A2’s channel to evaluate the expression SALARY+1000, and return the original channel with the new field values

4

=A2.fetch()

Attach ch.fetch() function that get the final result set to A2’s channel to fetch and store the existing data in the channel

5

=A1.push(A2)

Push data in A1’s cursor into A2’s channel

6

=A1.fetch()

 

7

=A2.result()

cs .run()

Description:

Compute one or more expressions against each of the records in a cursor.

Syntax:

cs.run (xi:Fi,…)

Note:

The function computes expression xi over each record in cursor cs, assigns each result to Fi field, and returns the modified cursor cs. It supports multicursors.

Parameter:

cs

Cursor

xi

An expression

Fi

A field of cs

Return value:

  The modified original cursor

Example:

 

A

 

1

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

 

2

=A1.run(SALARY+1000:SALARY)

 

3

=A2.fetch()

4

=connect("demo").cursor("select DEPT,NAME,BIRTHDAY,1 as AGE from EMPLOYEE")

 

5

=A4.run(age(BIRTHDAY):AGE)

 

6

=A5.run(AGE-20:AGE)

 

7

=A6.fetch()

Related function:

A.run(xi:Fi,)