Description:
Attach a computation of getting field values to a channel and return the original channel.
Syntax:
ch.new(xi:Fi,…)
Note:
The function attaches a computation to channel ch, which will compute expression xi over each of its records and form a new table sequence having same number of records as in ch, with field names being Fi that uses results of xi as values, and returns the original ch.
This is an attachment computation.
Parameter:
ch |
A channel. |
xi |
An expression, whose values are used as new field values. It is treated as null if omitted; in that case, parameter : Fi can’t be omitted. The sign # is used to represent a field with a sequence number. |
Fi |
Field name in the given channel; use the identifiers parsed from expression xi if it is omitted. |
Option:
@i |
Won’t generate the corresponding record when the result of computing expression xi is null. |
Return value:
Channel
Example:
|
A |
|
1 |
=demo.cursor("select * from SCORES") |
Return a cursor. |
2 |
=file("D:\\txt_files\\data1.txt").cursor@t() |
Below is data1.txt:
|
3 |
=channel() |
Create a channel. |
4 |
=channel() |
Create a channel. |
5 |
=A3.new(CLASS,#2:ID,SCORE+5:newScores) |
Attach a computation to channel A3 and return the original channel. #2:ID means renaming the second field of A3 ID; compute SCORE+5 on SCORE field, rename the column newScores, and form a new table sequence consisting of ID field, CLASS field and newScores field. |
6 |
=A3.fetch() |
Execute the result set function in channel A3 and keep the current data in channel. |
7 |
=A4.new@i(CLASS,STUDENTID,SUBJECT,SCORE:score) |
Attach a computation to channel A4, which uses @i option to not to generate the corresponding record if the result of computing a SCORE value is null, and return the original channel. |
8 |
=A4.fetch() |
Execute the result set function in channel A4 and keep the current data in channel |
9 |
=A1.push(A3) |
Be ready to push data in A1’s cursor to A3’s channel, but the action needs to wait. |
10 |
=A2.push(A4) |
Be ready to push data in A2’s cursor to A4’s channel, but the action needs to wait. |
11 |
=A1.fetch() |
Fetch data from cursor A1 while pushing data to channel A3 to execute the attached computation and keep the result. |
12 |
=A3.result() |
Get channel A3’s result:
|
13 |
=A2.fetch() |
Fetch data from cursor A2 while pushing data to channel A4 to execute the attached computation and keep the result. |
14 |
=A4.result() |
Get channel A4’s result:
|