1- streamer class C(Int x, Monitor<Int> m)
1+ // reada src/test/resources/csparql/13_static_join.smol
22
3- Unit register()
4- String static = pushStatic("heap,staticTable");
3+ class Observation(Int x, Int ts) end
4+
5+ class Controller(List<C> streamers)
6+
7+ Unit register(String static)
8+ List<C> objs = this.streamers;
9+ while objs != null do
10+ C o = objs.content;
11+ o.register(static);
12+ objs = objs.next;
13+ end
14+ end
15+
16+ Unit doStream(Int ts)
17+ List<C> objs = this.streamers;
18+ while objs != null do
19+ C o = objs.content;
20+ o.doStream(ts);
21+ objs = objs.next;
22+ end
23+ end
24+
25+ String windowToString()
26+ String s = "";
27+ List<C> objs = this.streamers;
28+ while objs != null do
29+ C o = objs.content;
30+ String res = o.windowToString();
31+ s = s ++ o ++ " ( " ++ res ++ ") ";
32+ objs = objs.next;
33+ end
34+ return s;
35+ end
36+ end
37+
38+ streamer class C(Int x, Int mult, Observation obs, Monitor<Int> m)
39+
40+ Unit register(String static)
541 Monitor<Int> m = monitor("
6- SELECT (SUM(?x) as ?sumX)
7- FROM STREAM %1 [RANGE 3s TUMBLING]
8- FROM <%2>
9- WHERE { ?s prog:C_x ?x . ?s a prog:C . }
10- ", this, static);
42+ SELECT (?x * ?k AS ?res)
43+ FROM NAMED WINDOW <win> ON %1 [RANGE PT5.001s STEP PT2s]
44+ FROM %2
45+ WHERE {
46+ ?streamer prog:C_mult ?k.
47+ WINDOW ?w {
48+ ?streamer prog:C_obs ?obs .
49+ ?obs prog:Observation_x ?x .
50+ }
51+ }
52+ ",
53+ this,
54+ static
55+ );
1156 this.m = m;
1257 end
1358
14- Unit doStream() emits(this.x)
59+ Unit doStream(Int ts) emits(this.obs, this.obs.x, this.obs.ts)
60+ this.obs = new Observation(this.x, ts);
1561 this.x = this.x + 1;
1662 end
1763
@@ -28,29 +74,62 @@ streamer class C(Int x, Monitor<Int> m)
2874end
2975
3076main
31- C o = new C(10, null);
32- o.register();
33-
77+ // configure simulation
3478 clock Int i = 100;
3579 Int endAt = 200;
3680
81+ Observation obs = new Observation(1, i);
82+ C o1 = new C(0, 2, obs, null);
83+ C o2 = new C(10, 3, null, null);
84+ C o3 = new C(20, 10, null, null);
85+
86+ // push static data
87+ String static = pushStatic("heap,staticTable");
88+
89+ // initialize stream
90+ List<C> l3 = new List<C>(o3, null);
91+ List<C> l2 = new List<C>(o2, l3);
92+ List<C> streamers = new List<C>(o1, l2);
93+ Controller ctrl = new Controller(streamers);
94+
95+ // initialize monitor
96+ ctrl.register(static);
97+
98+ // run simulation
3799 while i < endAt do
38- o.doStream();
39- String res = o.windowToString();
100+
101+ // put triples in the stream
102+ ctrl.doStream(i);
103+
104+ // read window contents
105+ String res = ctrl.windowToString();
40106 print(">>" ++ intToString(i) ++ ": " ++ res);
107+
108+ // advance clock (timestamp)
41109 i = i + 1;
42110 end
43111end
44112
45113// Output:
46- // >>100:
47- // >>101:
48- // >>102:
49- // >>103: 0
50- // >>104: 0
51- // >>105: 0
52- // >>106: 0
114+ // >>100: obj8 ( ) obj9 ( ) obj10 ( )
115+ // >>101: obj8 ( ) obj9 ( ) obj10 ( )
116+ // >>102: obj8 ( ) obj9 ( ) obj10 ( )
117+ // >>103: obj8 ( 0 2 ) obj9 ( 30 33 ) obj10 ( 200 210 )
118+ // >>104: obj8 ( 0 2 ) obj9 ( 30 33 ) obj10 ( 200 210 )
119+ // >>105: obj8 ( 0 2 4 6 ) obj9 ( 30 33 36 39 ) obj10 ( 200 210 220 230 )
120+ // >>106: obj8 ( 0 2 4 6 ) obj9 ( 30 33 36 39 ) obj10 ( 200 210 220 230 )
121+ // >>107: obj8 ( 2 4 6 8 10 ) obj9 ( 33 36 39 42 45 ) obj10 ( 210 220 230 240 250 )
122+ // >>108: obj8 ( 2 4 6 8 10 ) obj9 ( 33 36 39 42 45 ) obj10 ( 210 220 230 240 250 )
123+ // >>109: obj8 ( 6 8 10 12 14 ) obj9 ( 39 42 45 48 51 ) obj10 ( 230 240 250 260 270 )
124+ // >>110: obj8 ( 6 8 10 12 14 ) obj9 ( 39 42 45 48 51 ) obj10 ( 230 240 250 260 270 )
125+ // >>111: obj8 ( 10 12 14 16 18 ) obj9 ( 45 48 51 54 57 ) obj10 ( 250 260 270 280 290 )
53126// ..
54127
55128// Notes:
56- // Error: Static join does not work!
129+ // - pushStatic("heap, staticTable") dumps static data to output.ttl
130+ // - This file contains triples for C_mult property of each streamer object (static data)
131+
132+ // - Results from streamers are multiplied by {2, 3, 10} respectively
133+ // - Stream data is inside the window: ?x
134+ // - Static data is outside the window: ?k
135+ // - Static data is joined with stream data: ?x * ?k
0 commit comments