bg
Join – example 2 – BangDB = NoSQL + AI + Stream

Join – example 2

chevron

IOT example for stream join

Temperature and Pressure streams joining with active-passive mode [ 3 and 5 option for active-passive ]

Example 2

Again same IOT scenario, but we will limit to two streams for clarity. These two streams, namely temp and pressure will join with each other using active, passive rule (3, 5) where pressure stream is active stream and temp is passive one.

Let's define the schema first;

{ "schema" : "myschema", "streams" :[ { "name":"temp_stream", "type":1, "swsz":81600, "inpt":[], "attr":[{"name":"temp", "type":11}, {"name":"point", "type":5, "kysz":48, "sidx":1, "stat":1} ], "join":[{"name":"temp_pressure_join", "type":3, "tloc":3000, "iatr":["temp", "point"], "rstm":"pressure_stream", "ratr":["pressure"], "jqry":{"cond":["point"], "opid":11, "args":["point"]}, "ostm":"temp_pressure_stream"}] }, { "name":"pressure_stream", "type":1, "inpt":[], "attr":[{"name":"pressure", "type":11}, {"name":"point", "type":5, "kysz":48, "sidx":1, "stat":1} ], "join":[{"name":"temp_pressure_join", "type":5, "tloc":3000, "ratr":["temp", "point"], "rstm":"temp_stream", "iatr":["pressure"], "jqry":{"cond":["point"], "opid":11, "args":["point"]}, "ostm":"temp_pressure_stream"}] }, { "name":"temp_pressure_stream", "type":3, "inpt":["temp_stream", "pressure_stream"], "attr":[{"name":"point", "type":5, "kysz":48, "sidx":1, "stat":1}, {"name":"temp", "type":11}, {"name":"pressure", "type":11} ] } ] }
Now pump data;
put [ temp_stream ] : {"temp":70.1, "point":1} put [ pressure_stream ] : {"pressure":10.2, "point":2} put [ pressure_stream ] : {"pressure":11.1, "point":1} put [ pressure_stream ] : {"pressure":11.5, "point":1} put [ pressure_stream ] : {"pressure":11.8, "point":1} put [ temp_stream ] : {"temp":71.1, "point":2} put [ pressure_stream ] : {"pressure":11.9, "point":1} put [ pressure_stream ] : {"pressure":12.1, "point":2} put [ temp_stream ] : {"temp":71.2, "point":1} put [ pressure_stream ] : {"pressure":12.5, "point":1} Here is the data for temp stream; {"temp":70.10000000000001,"point":1,"_pk":1584945351349346,"_v":1} {"temp":71.10000000000001,"point":2,"_pk":1584945351429690,"_v":1} {"temp":71.2,"point":1,"_pk":1584945351491986,"_v":1} Here is the data for pressure stream; {"pressure":10.2,"point":2, "_pk":1584945351359800,"_v":1} {"pressure":11.1,"point":1, "_pk":1584945351372994,"_v":1} {"pressure":11.5,"point":1, "_pk":1584945351388063,"_v":1} {"pressure":11.8,"point":1, "_pk":1584945351399370,"_v":1} {"pressure":11.9,"point":1, "_pk":1584945351450466,"_v":1} {"pressure":12.1,"point":2, "_pk":1584945351461066,"_v":1} {"pressure":12.5,"point":1, "_pk":1584945351523036,"_v":1} Here is the data for joined temp_pressure stream; {"pressure":11.1,"_pk":1584945351372994, "temp":70.10000000000001,"point":1,"_jpk1":1584945351349346,"_v":1} {"pressure":11.5,"_pk":1584945351388063, "temp":70.10000000000001,"point":1,"_jpk1":1584945351349346,"_v":1} {"pressure":11.8,"_pk":1584945351399370, "temp":70.10000000000001,"point":1,"_jpk1":1584945351349346,"_v":1} {"pressure":11.9,"_pk":1584945351450466, "temp":70.10000000000001,"point":1,"_jpk1":1584945351349346,"_v":1} {"pressure":12.1,"_pk":1584945351461066, "temp":71.10000000000001,"point":2,"_jpk1":1584945351429690,"_v":1} {"pressure":12.5,"_pk":1584945351523036, "temp":71.2,"point":1,"_jpk1":1584945351491986,"_v":1}