keyedStreamTable

Syntax

keyedStreamTable(keyColumn, X, [X1], [X2], …..)

or

keyedStreamTable(keyColumn, capacity:size, colNames, colTypes)

Arguments

keyColumn is a string scalar or vector indicating the name of the primary key columns.

For the first scenario: X, X1, …. are vectors.

For the second scenario:

capacity is the amount of memory (in terms of the number of rows) allocated to the table. When the number of rows exceeds capacity, the system will first allocate memory of 1.2~2 times of capacity, copy the data to the new memory space, and release the original memory. For large tables, these steps may use significant amount of memory.

size is the initial size (in terms of the number of rows) of the table. If size=0, create an empty table. For this scenario, size must be 0.

colNames is a string vector of column names.

colTypes is a string vector of data types.

Details

Create a stream table with one or multiple columns as the primary key. The primary key must contain a unique value for each row.

When new records are being inserted into a keyed stream table, the primary key values will be checked:

  • If the key value of a new record is identical to that of an existing record, the existing record will NOT be updated.

  • If multiple records with identical key values (which are different from the existing ones) are being inserted at one time, only the first record can be successfully inserted.

Examples

Example 1

$ id=`A`B`C`D`E
$ x=1 2 3 4 5
$ t1=keyedStreamTable(`id, id, x)
$ t1;

id

x

A

1

B

2

C

3

D

4

E

5

Example 2

$ t2=keyedStreamTable(`id,100:0,`id`x, [INT,INT])
$ insert into t2 values(1 2 3,10 20 30);
$ t2;

id

x

1

10

2

20

3

30

If we try to insert a new row with duplicate primary key value as one of the existing rows, the new row will not be inserted:

$ insert into t2 values(3 4 5,35 45 55)
$ t2;

id

x

1

10

2

20

3

30

4

45

5

55

the record with id=3 has not been overwritten.

There are multiple columns in the primary key:

$ t=keyedStreamTable(`sym`id,1:0,`sym`id`val,[SYMBOL,INT,DOUBLE])
$ insert into t values(`A`B`C`D`E,5 4 3 2 1,52.1 64.2 25.5 48.8 71.9);
$ insert into t values(`A`B`R`T`Y,5 8 3 2 1,152.3 164.6 125.5 148.8 171.6);
$ t;

sym

id

val

A

5

52.1

B

4

64.2

C

3

25.5

D

2

48.8

E

1

71.9

B

8

164.6

R

3

125.5

T

2

148.8

Y

1

171.6