share

Syntax

share <table> as <shared name>

or

share <engine> as <engine name>

Details

For the first usage: share the given table across all sessions with a shared name. Local objects including tables are invisible to other sessions. They need to be shared before they are visible to other sessions. The shared name must be different from any regular table name on all sessions. One server can support up to 65,535 shared tables.

For the second usage: share an engine and apply a write lock for concurrent writes (The shared engine must keep the same name as the original). To obtain the engine handle from another session, use function getStreamEngine.

Note that it is not allowed to share a stream table multiple times by modifying the shared table name.

Examples

  • For the first usage:

t1= table(1 2 3 as id, 4 5 6 as value);
share t1 as table1;
  • For the second usage

trades = streamTable(1:0, `time`sym`price, [TIMESTAMP, SYMBOL, DOUBLE])
share table(100:0, `sym`time`factor1, [SYMBOL, TIMESTAMP, DOUBLE]) as outputTable
engine = createReactiveStateEngine(name="test", metrics=[<time>, <mavg(price, 3)>], dummyTable=trades, outputTable=outputTable, keyColumn=`sym)
// share engine
share engine as "test"

Excute the following script in any of the sessions to which the node is connected:

// define function write1 to write to the engine
def write1(mutable engine) {
  N = 10
  for (i in 1..500) {
      data = table(take(now(), N) as time, take(`A`B, N) as sym, rand(10.0, N) as price)
      getStreamEngine(engine).append!(data)
  }
}
// define function write2 to write to the engine
def write2(mutable engine) {
  N = 10
  for (i in 1..500) {
      data = table(take(now(), N) as time, take(`C`D, N) as sym, rand(10.0, N) as price)
      getStreamEngine(engine).append!(data)
  }
}
// submit jobs write to the engine at the same time
submitJob("j1", "j1", write1, "test")
submitJob("j2", "j2", write2, "test")
// The number of output records is 10000, which is exactly the sum of records written by write1 and write2.
select count(*) from outputTable
10000

Related functions: Undefine Variables, undef