keys()

Read(630) Label: table sequence, set a key,

Here’s how to use keys() function.

T .keys()

Description:

Set a key for a table sequence.

Syntax:

T.keys(Ki,…)

Note:

The function sets Ki,… as the key of the table sequence T. The absence of the parameter will clear the key. A T.create() operation will copy the key at the same time.

Parameters:

T

A table sequence

Ki

Key name

Options:

@t(…,KT)

Set the last parameter KT as the time key, and make all other parameters the basic keys

Return value:

A table sequence with a key

Example:

 

A

 

1

=demo.query("select EID,NAME,DEPT,SALARY,HIREDATE from EMPLOYEE order by EID asc,DEPT asc")

 

2

=A1.keys(EID,DEPT)

Set EID&DEPT fields as A1’s key

3

=A1(1).key()

[1,R&D]

4

=A1.keys()

Remove the key

5

=A1(1).key()

Return null because A1 doesn’t set a key

6

=A1.keys@t(EID,DEPT,HIREDATE)

Set EID and DEPT as A1’s basic keys and HIREDATE as time key

7

=A1.create()

Copy the key since table sequence T has one

8

=A7.insert(0,1,"Jack","HR",3000,date("2022-03-09"))

9

=A8(1).key()

[1,HR]; here values of basic keys are returned

Related functions:

r.key()

v.v()

T.keys( Ki,… )

Description:

Define the key(s) for an in-memory table.

Syntax:

T.keys(Ki,…)

Note:

The function defines key(s) Ki,…, which may include the time key, for in-memory table T.

Parameters:

Ki

Key name; can be one or multiple keys; delete all keys of an in-memory table when the parameter is absent

T

An in-memory table

Options:

  @t(…,KT)  Set the last parameter KT as the time key and all other key fields constitute the basic key

Return value:

An  in-memory table

Example:

 

A

 

1

=demo.cursor("select EID,NAME,GENDER from EMPLOYEE where EID<10")

Return cursor of the retrieved data

2

=A1.memory()

Return an in-memory table

3

=A2.keys(EID,NAME)

Set EID and NAME as the in-memory table’s keys

4

=A3(1).key()

Get the keys of the first record and return the result:

5

=A2.keys()

Delete all keys of the in-memory table

6

=A3(1).key()

Query the keys of the first record and return null

7

=demo.cursor("select * from employee").memory()

Return an in-memory table

8

=A7.keys@t(EID,HIREDATE)

Set EID as the basic key and HIREDATE as the time key in A7’s in-memory table

T.keys(Ki,…;n)

Description:

Set primary key for a table sequence or an in-memory table and create index for the table at the same time.

Syntax:

T.keys(Ki,…;n) 

Note:

The function sets primary key Ki,... for table sequence/in-memory table T and, in the meantime, creates an index over the key. To create a hash index, one of @i option and parameter n should be present. To create a serial byte index, omit parameter n. When both @s option and parameter n exist, ignore the option.

Parameters:

Ki

Primary key, which can be one or multiple; delete all keys of an in-memory table when this parameter is absent

T

A table sequence/in-memory table

n

An integer greater than 1, which is length of the hash table; its default length is the table length.

Options:

@i

Create a hash index

@s

Create a serial byte index for a serial byte primary key

@m

Enable parallel processing

@t

Indicate that a table has a time key

@n

Indicate that a table has a sequence number key

Return value:

A table sequence/memory table

Example:

 

A

 

1

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

 

2

=A1.keys(EID,DEPT;1)

Set EID, DEPT as A1’s primary key and create a hash index for it;  length of the hash is 1

3

=A1.keys@i(EID,DEPT)

Same as A2

4

=A1.keys@i(EID,DEPT;1)

Same as A2

5

=A1.keys@is(EID)

Set EID as A1’s primary key and create a serial byte index over the key

 

6

=A1.keys@is(EID;1)

Set EID as A1’s primary key and create a hash index whose length is 1 for the key; ignore @s option since parameter n is present

7

=A1.keys@im(EID,DEPT;1)

Create an index using parallel processing

8

=demo.cursor("select * from employee").memory()

Return an in-memory table

9

=A8.keys@t(HIREDATE)

Set HIERDATE as the time key and create an serial byte index

10

=file("STUDENTS.txt").import@t().keys(SID)

Set SID as the table sequence’s primary key

11

=file("SCORES.txt").import@t().keys@in(CLASS,NAME)

Set CLASS and NAME as the table sequence’s primary key and create index on the sequence number key

12

=A10.switch(xh,A11)

Replace values of sequecne number key with the referenced records in A11’s table