addSparseReactiveMetrics
Syntax
addSparseReactiveMetrics(engine, metrics)
Details
Adds sparse stateful computation metrics to the specified SparseReactiveStateEngine.
The format of the new metrics is the same as the metrics parameter of
createSparseReactiveStateEngine.
Parameters
engine is a STRING scalar or an object, specifying the sparse reactive stateful engine to which computation metrics are added.
metrics is a table specifying the set of metrics to be added. Its schema is
the same as the metrics parameter of
createSparseReactiveStateEngine: keyColumn(s), formula,
outputMetricKey.
Returns
Returns no value or returns an execution status (subject to the actual product implementation).
Examples
Create a sparse reactive state engine with a metric for A001, add a moving average metric with a window size of 3 for A003, and insert data to view the results.
// Create the input schema and output table
inputSchema = table(1:0, `deviceID`value, [STRING, DOUBLE])
outputTable = table(1:0, `deviceID`outputMetricKey`outputValue, [STRING, STRING, DOUBLE])
// Define the initial metric for A001 and create the engine
metrics = table(
["A001"] as deviceID,
["value * 2"] as formula,
["A001_1"] as outputMetricKey
)
sparseMetricEngine = createSparseReactiveStateEngine(
name="sparseMetricEngine",
metrics=metrics,
dummyTable=inputSchema,
outputTable=outputTable,
keyColumn="deviceID"
)
// Add the moving average metric for A003
newMetrics = table(
["A003"] as deviceID,
["mavg(value,3)"] as formula,
["A003_1"] as outputMetricKey
)
addSparseReactiveMetrics("sparseMetricEngine", metrics=newMetrics)
// Insert data directly into the engine and save the results
data = table(
["A001", "A003", "A003", "A003"] as deviceID,
[5.0, 10.0, 20.0, 30.0] as value
)
sparseMetricEngine.append!(newData=data)
result = select * from outputTable
// Remove the engine created by this example
dropStreamEngine(name="sparseMetricEngine")
result
| deviceID | outputMetricKey | outputValue |
|---|---|---|
| A001 | A001_1 | 10 |
| A003 | A003_1 | |
| A003 | A003_1 | |
| A003 | A003_1 | 20 |
Related functions: createSparseReactiveStateEngine, getSparseReactiveMetrics, deleteSparseReactiveMetric
