ch.news()

Read(1172) Label: field value, update, channel,

Description:

Generate records according to the given condition, concatenate them into a new table sequence and return it to the original channel.

Syntax:

ch.news(X;xi:Fi,…)

Note:

The function attaches a computation to channel ch, which will compute expression xi on record sequence X, use the results as values of the new field Fi to generate multiple records and form a new table sequence, and returns the result to the original channel.

 

This is an attachment computation.

Parameter:

ch

A channel.

X

A record sequence.

xi

Expression, whose results will be field values; the sign ~ used in the parameter references data from X instead of A. The sign # is used to represent a field with a sequence number.

Fi

Field name in the given channel; will be automatically identified if the parameter is omitted.

Option:

@1

Enable a left join; when a record in the given record sequence is empty, create an empty record for the new table sequence.

Return value:

Channel

Example:

 

A

 

1

=demo.cursor("select EID,NAME,DEPT,GENDER,BIRTHDAY,SALARY from EMPLOYEE")

Return a cursor.

2

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

Return a table sequence:

3

=A2.group(GENDER;~:gup)

Group table sequence A2 by GENDER field and return the following result:

4

=A1.groupx(GENDER;avg(SALARY):avg)

Group table sequence A1 by GENDER field, compute average SALARY values in each group and return a cursor. Below is the returned data:

5

=A4.join(GENDER,A3:GENDER,gup)

Attach a computation to cursor A4, which will perform a foreign-key-style join with table A3, and return the original cursor A4. Below is the returned data of A4 executing A5’s compuation:

6

=channel(A5)

Create a channel and be ready to push cursor A5’s data to the channel, but the push action needs to wait.

7

=A6.news(gup;EID,#2:Lname,GENDER,age(~.BIRTHDAY):Age,SALARY+50: Salary,avg:AvgSalary)

Attach a computation to channel A6, which will get values for gup table - #2Lname means renaming the table’s second field Lname, and form a table sequence consisiting of fields EID, Lname,GENDER, Age, Salary and AvgSalary, and return the result to the original channel.

8

=A6.fetch()

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

9

=A5.fetch()

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

10

=A6.result()

Get channel A6’s result:

Use @1 option:

 

A

 

1

=demo.cursor("select EID,NAME,DEPT,GENDER,BIRTHDAY,SALARY from EMPLOYEE")

Return a cursor.

2

=demo.query("select EID,NAME,DEPT,GENDER,BIRTHDAY,SALARY from EMPLOYEE where GENDER='M' ")

Return a table sequence:

3

=A2.group(GENDER;~:gup)

Group table sequence A2 by GENDER field and return the following result:

4

=A1.groupx(GENDER;avg(SALARY):avg)

Group table sequence A1 by GENDER field, compute average SALARY values in each group and return a cursor. Below is the returned data:

5

=A4.join(GENDER,A3:GENDER,gup)

Attach a computation to cursor A4, which will perform a foreign-key-style join with table A3, and return the original cursor A4. Below is the returned data of A4 executing A5’s compuation:

6

=channel(A5)

Create a channel and be ready to push cursor A5’s data to the channel, but the push action needs to wait.

7

=A6.news@1(gup;EID,NAME,GENDER,age(~.BIRTHDAY):Age,Salary,avg:AvgSalary)

Attach a computation to channel A6, which will get values for gup table - #2Lname means renaming the table’s second field Lname, and form a table sequence consisiting of fields EID, Lname,GENDER, Age, Salary and AvgSalary, and return the result to the original channel.

Use @1 option to perform a left join; create an empty record for the result table sequence when a record in the record sequene is empty.

8

=A6.fetch()

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

9

=A5.fetch()

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

10

=A6.result()

Get channel A6’s result: