changelogStreamTable

Syntax

changelogStreamTable(keyColumn, X, [X1], [X2], .....)

or

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

Details

Creates a keyed stream table with an internal status column.

  • The table contains an internal status column of type CHAR for tracking data change log. Currently supports two states:
    1. 'N': NEW, indicating a new record when the key does not exist;
    2. 'U': UPDATE, indicating an updated record when the key already exists.
  • The status column also supports user-defined status values.
  • Queries return only the latest record for each key.

Parameters

keyColumn is a string scalar or vector indicating the name of the primary key columns (which must be of INTEGRAL, TEMPORAL, LITERAL or FLOATING type).

For the first scenario: X, X1, X2 ... can be vectors, matrices or tuples. Each vector, each matrix column and each tuple element must have the same length. When Xk is a tuple:
  • If the elements of Xk are vectors of equal length, each element of the tuple will be treated as a column in the table.
  • If Xk contains elements of different types or unequal lengths, it will be treated as a single column in the table (with the column type set to ANY), and each element will correspond to the value of that column in each row.
For the second scenario:
  • capacity is a positive integer indicating 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 an integer no less than 0 indicating the initial size (in terms of the number of rows) of the table. If size=0, create an empty table; If size>0, the initialized values are:
    • false for Boolean type;
    • 0 for numeric, temporal, IPADDR, COMPLEX, and POINT types;
    • Null value for Literal, INT128 types.
  • Note:
    If colTypes is an array vector, size must be 0.
  • colNames is a STRING vector of column names.
  • colTypes is a string vector of data types. The non-key columns can be specified as an array vector type or ANY type.

Returns

A table.

Examples

share changelogStreamTable(`sym`time, 100:0, `sym`time`price, [STRING,DATETIME,DOUBLE]) as tickStream
n=4
data1 = table(take("000001.SH", n) as sym, take(2021.02.08T09:30:00 + 1..2, n) as time, 10+rand(100.0, n) as price)
tickStream.append!(data1)
select * from tickStream
sym time price
0 000001.SH 2021.02.08 09:30:01 89.723076797026
1 000001.SH 2021.02.08 09:30:02 69.34098429496888

Related functions: keyedStreamTable, getStreamTableChangelog