Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Context Store Management

The feature "context" can be added for management context information.

This means, it is possible to store or cache events without using the blocking window operator. First of all, this is useful for slowly changing events (like states in a smart home or in a factory), because in a window-operator you have to wait until the state changes a second time before the first change gets available. Therefore, the context store is a special concept to avoid such a blocking behavior. For each context event (each state), there is a context store needed. This means, for example, that there is one context store for each door in a smart home. After creating a context store, the system can use the store-operator to write into the store and can use the enrich-operator to read from the store. Furthermore, there is a RCP-view to show the actual content of the context sotrestore. All these parts works work as follows.

Context Store - create and drop

Creating and removing of context stores is done by a Continuous Query Language (CQL)-Statement. To create a new store, you may use the following statement (which is similar to the create stream statement):

...

It is possible to omit "IF EXISTS", because it only prevents for throwing an exception if the context store that has to be dropped does not exists.

 

STORE - writing into a store

The store operator is used for storing data. If you want to store the contents of "inputoperator" into the context store named "door4", the store-operator is used as follows:

...

so, you only have to define the name of the store. Notice, that the output-schema of inputoperator has to be union-compatible with the schema of the definied store. Union-compatible means: only the datatypes have to be equal, but not the names of the attributes.

ENRICH - reading from a store

The enrich operator is used for reading data. The enrich has technically two inputs: one for the data that should be enriched and one for the data from the context store. So, if a new event from the normal input gets into the enrich operator, it queries all temporally correlating context information from the context storage and merges it to the incoming event. Since it may happen that the there are two or more context states in the context storage that have to be merged, the enrich could produce also two or more enriched events.

To specify the enrich operator, you can use the simplest form in Procedural Query Language (PQL):

enriching = ENRICHCONTEXTENRICH({store = 'door5'}, inputoperator)

As the definition of the store-operator, you only have to define the store you want to read from. In this case, the complete tuple from the store is attached to the current tuple in the context-enrich-operator. Thus, the resulting outputschema is the concatenation of the input-schema of the enrich (or rather the stream that should be enriched by the operator) plus the outputschema of the context store.

Since, the tuple in the context store could have a lot of attributes and you only want to use a subset of them, you can also (optional) specify a list of attributes that are used for the enrichment:

enriching = ENRICHCONTEXTENRICH({store = 'door5', attributes=['state']}, inputoperator)

...

As mentioned before, the enrich only produces results if there is at least one context state in the context store that temporally correlates with the incoming event (which means: they have overlapping timeintervals). In this case, it may happen that the event that has to be enrich is to old and there is no suitable context state, e.g.: the event a is valid at [100;120) and the context state c is valid at [200;oo). Thus, the event a cannot be enriched because it is too old. If you still want to use such a event but without an enriched context state, you can use the outer-option:

enriching = ENRICHCONTEXTENRICH({store = 'door5', attributes=['state'], outer='true'}, inputoperator)

if the outer-option is set to "true", the enrich will enrich events with "null"-values instead of discarding them (thus, its like an outer join).

MAP

Together with the Map operator it is possible to retrieve single values from the context store with the function ContextStore(storeName)

Code Block
languagepql
out = MAP({Expressions=["elementAt(ContextStore('door5'),0)","input.x"],input}

Remark: The ContextStore functions delivers a tuple in this case and elementAt reads the attribute from the tuple. Else the whole tuple will be added.

View - show the context of stores

if you use the rcp-view, you can use the "Context Store" view. This can be found under the menu windows -> show view -> other... -> odysseus.

...