Versions Compared

Key

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

...

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):

...

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

...