cs.switch(F i ,A i :x;… )

Read(667) Label: cursor, specified field,

Description:

Attach the action of switching specified field values to the referencing record field values to a cursor and return the original cursor.

Syntax:

cs.switch(Fi,Ai:x;…)

Note:

The function attaches a computation to cursor cs, which will replace values of Fi field in cursor cs with the corresponding records in Ai, and returns the original cursor cs. x is the primary key or logical primary key of Ai, and the matching condition is Fi =x. By default, an Fi field value is displayed as empty when no record in Ai can match it.

 

This is a delayed function.

Parameter:

cs

A cursor/A multicursor.

Fi

A field of a cursor.

Ai

A table sequence/A record sequence.

x

The primary key or logical primary key of Ai; the parameter can be omitted if primary key is already set for Ai.

Option:

@i

If no value corresponding to Fi is found, then remove this record.

@d

Perform the inverse operation of @i to obtain cursor records that have no matching value Ai for F field.

@1

If the Fi field value of a record in channel ch doesn’t exist in Ai, then generate a record of the same structure as Ai with expression x being the primary key. Here is number 1.

Return value:

Cursor

Example:

When x is the primary key of Ai:

 

A

 

1

=demo.cursor("SELECT top 5 EID,DEPT,NAME FROM EMPLOYEE")

Return a cursor whose data is as follows:

2

=demo.query("SELECT DEPT,MANAGER FROM DEPARTMENT").keys(DEPT)

Return a table sequence whose key is DEPT:

3

=A1.switch(DEPT,A2)

Attach a computation to cursor A1, which will replace DEPT values to A2’s records pointed by the referencing field in the cursor, and return cursor A1; as A2’s key is DEPT, parameter x can be omitted.

4

=A1.fetch()

Fetch data from cursor A1 where A3’s computation is executed:

 

When x isn’t the primary key or logical key of Ai:

 

A

 

1

=demo.cursor("SELECT top 10 EID,DEPT,NAME FROM EMPLOYEE")

Return a cursor whose data is as follows:

2

=demo.query("SELECT top 6 DEPT,MANAGER FROM DEPARTMENT")

Return a table sequence:

3

=A1.switch(DEPT,A2:DEPT)

Attach a computation to cursor A1, which will match cursor A1’s DEPT field with corresponding DEPT field in table sequence A2 and display the non-matching values as nulls, and return cursor A1.

4

=A1.fetch()

Fetch data from cursor A1 where A3’s computation is executed:

 

Use @i option to delete non-matching records:

 

A

 

1

=demo.cursor("SELECT top 10 EID,DEPT,NAME FROM EMPLOYEE")

Return a cursor whose data is as follows:

2

=demo.query("SELECT top 6 DEPT,MANAGER FROM DEPARTMENT")

Return a table sequence:

3

=A1.switch@i(DEPT,A2:DEPT)

Attach a computation to cursor A1, which will match cursor A1’s DEPT field with corresponding DEPT field in table sequence A2 and, with @i option, delete the non-matching records, and return cursor A1.

4

=A1.fetch()

Fetch data from cursor A1 where A3’s computation is executed:

 

Use @d option to keep the non-matching records only:

 

A

 

1

=demo.cursor("SELECT top 10 EID,DEPT,NAME FROM EMPLOYEE")

Return a cursor whose data is as follows:

2

=demo.query("SELECT top 6 DEPT,MANAGER FROM DEPARTMENT")

Return a table sequence:

3

=A1.switch@d(DEPT,A2:DEPT)

Attach a computation to cursor A1, which will match cursor A1’s DEPT field with corresponding DEPT field in table sequence A2 and, with @d option, retain the non-matching records only, and return cursor A1.

4

=A1.fetch()

Fetch data from cursor A1 where A3’s computation is executed:

 

When @1 option works:

 

A

 

1

=demo.cursor("SELECT top 10 EID,DEPT,NAME FROM EMPLOYEE")

Return a cursor whose data is as follows:

2

=demo.query("SELECT top 6 DEPT,MANAGER FROM DEPARTMENT")

Return a table sequence:

3

=A1.switch@1(DEPT,A2:DEPT)

Attach a computation to cursor A1, which will match cursor A1’s DEPT field with corresponding DEPT field in table sequence A2 and, with @1 option, generate a record of same structure as A2 when the current value does not match, and return cursor A1.

4

=A1.fetch()

Fetch data from cursor A1 where A3’s computation is executed:

Related function:

P.switch()

cs.switch(Fi,Ai:x;…)

Description:

Replace values of a specified field in a cluster cursor with the corresponding referencing records in another table.

Syntax:

cs.switch(Fi,Ai:x;…)

Note:

The function replaces a value of Fi field in cursor/multicursor/cluster cursor cs with the corresponding record in Ai by matching the Fi value with parameter x, which is the primary key or logical primary key of Ai. An Fi field value displays as empty when no record in Ai matches it.

Parameter:

cs

A cursor/multicursor/cluster cursor

Fi

A field in the cursor

Ai

A cluster in-memory table

x

The primary key or logical primary key of Ai; the parameter can be omitted if primary key is already set for Ai

Option:

@c

With a distributed cluster in-memory table, the operation won’t involve a cross-node reference but it assumes that the referenced records are local

Return value:

The original cursor

Example:

 

A

 

1

=demo.cursor("SELECT * FROM DEPARTMENT")

Return a cursor.

2

[192.168.0.110:8281,192.168.18.143:8281]

 

3

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

 

4

=A3.open()

Open the composite table.

5

=A4.cursor()

Return a cluster cursor.

6

=A5.groups@c(DEPT:dept;sum(SALARY):totalSalary)

Return a cluster in-memory table.

7

=A1.switch@c(DEPT,A6:dept)

Replace values of DEPT field of the cursor with the referencing field values and return the switched cursor.

8

=A7.fetch()

Fetch data from the switched cursor: