Skip to content

Commit a09940f

Browse files
committed
smol scripts for csparql unit tests added
1 parent 9601d0a commit a09940f

14 files changed

+847
-0
lines changed
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
// Commands:
2+
// java -jar build/libs/smol.jar
3+
// reada stream/01_physical_window.smol
4+
5+
streamer class C(Int x, Monitor<Int> m)
6+
7+
Unit register()
8+
Monitor<Int> m = monitor("
9+
SELECT (SUM(?x) as ?sumX)
10+
FROM STREAM %1 [RANGE TRIPLES 3]
11+
WHERE { ?s prog:C_x ?x }
12+
", this);
13+
this.m = m;
14+
end
15+
16+
Unit doStream() emits(this.x)
17+
this.x = this.x + 1;
18+
end
19+
20+
String windowToString()
21+
String s = "";
22+
List<Int> l = window(this.m);
23+
while l != null do
24+
s = s ++ intToString(l.content) ++ " ";
25+
l = l.next;
26+
end
27+
return s;
28+
end
29+
end
30+
31+
main
32+
C o = new C(0, null);
33+
o.register();
34+
35+
Int i = 100;
36+
Int endAt = 200;
37+
while i < endAt do
38+
o.doStream();
39+
String res = o.windowToString();
40+
print(">>" ++ intToString(i) ++ ": " ++ res);
41+
i = i + 1;
42+
end
43+
end
44+
45+
// Output:
46+
// >>100:
47+
// >>101:
48+
// >>102: 6 = 1+2+3
49+
// >>103: 6
50+
// >>104: 6
51+
// >>105: 15 = 4+5+6
52+
// >>106: 15
53+
// >>107: 15
54+
// >>108: 24 = 7+8+9
55+
// ..
56+
57+
// Notes:
58+
// - First 2 windows are empty because the window size is 3 triples
59+
// - RANGE TRIPLES 3 = sliding window of 3 triples
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
streamer class C(Int x, Monitor<Int> m)
2+
3+
Unit register()
4+
Monitor<Int> m = monitor("
5+
SELECT (SUM(?x) as ?sumX)
6+
FROM STREAM %1 [RANGE 3s TUMBLING]
7+
WHERE { ?s prog:C_x ?x }
8+
", this);
9+
this.m = m;
10+
end
11+
12+
Unit doStream() emits(this.x)
13+
this.x = this.x + 1;
14+
end
15+
16+
String windowToString()
17+
String s = "";
18+
List<Int> l = window(this.m);
19+
while l != null do
20+
s = s ++ intToString(l.content) ++ " ";
21+
l = l.next;
22+
end
23+
return s;
24+
end
25+
end
26+
27+
main
28+
C o = new C(0, null);
29+
o.register();
30+
31+
clock Int i = 100;
32+
Int endAt = 200;
33+
34+
while i < endAt do
35+
o.doStream();
36+
String res = o.windowToString();
37+
print(">>" ++ intToString(i) ++ ": " ++ res);
38+
i = i + 1;
39+
end
40+
end
41+
42+
// Output:
43+
// >>100:
44+
// >>101:
45+
// >>102:
46+
// >>103: 6 = 1+2+3
47+
// >>104: 6
48+
// >>105: 6
49+
// >>106: 15 = 4+5+6
50+
// >>107: 15
51+
// >>108: 15
52+
// >>109: 24 = 7+8+9
53+
// ..
54+
55+
// Notes:
56+
// - External timestamp: clock variable increased by 1 second each iteration = timestamp increased by 1000 ms
57+
// - RANGE 3s TUMBLING = tumbling window of 3 seconds
58+
// - Similar output as in 01_physical_window.smol (3 seconds * 1 triple per second = 3 triples)
59+
// - First 3 windows are empty because the window size is 3 seconds
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
streamer class C(Int x, Monitor<Int> m)
2+
3+
Unit register()
4+
Monitor<Int> m = monitor("
5+
SELECT (SUM(?x) as ?sumX)
6+
FROM STREAM %1 [RANGE 5s STEP 2s]
7+
WHERE { ?s prog:C_x ?x }
8+
", this);
9+
this.m = m;
10+
end
11+
12+
Unit doStream() emits(this.x)
13+
this.x = this.x + 1;
14+
end
15+
16+
String windowToString()
17+
String s = "";
18+
List<Int> l = window(this.m);
19+
while l != null do
20+
s = s ++ intToString(l.content) ++ " ";
21+
l = l.next;
22+
end
23+
return s;
24+
end
25+
end
26+
27+
main
28+
C o = new C(0, null);
29+
o.register();
30+
31+
clock Int i = 100;
32+
Int endAt = 200;
33+
34+
while i < endAt do
35+
o.doStream();
36+
String res = o.windowToString();
37+
print(">>" ++ intToString(i) ++ ": " ++ res);
38+
i = i + 1;
39+
end
40+
end
41+
42+
// Output:
43+
// >>100:
44+
// >>101:
45+
// >>102: 3 = 1+2
46+
// >>103: 3
47+
// >>104: 10 = 1+2+3+4
48+
// >>105: 10
49+
// >>106: 20 = 2+3+4+5+6
50+
// >>107: 20
51+
// >>108: 30 = 4+5+6+7+8
52+
// >>109: 30
53+
// >>110: 40 = 6+7+8+9+10
54+
// ..
55+
56+
// Notes:
57+
// - Step 2 seconds = new window every 2 seconds
58+
// - Windows have {2, 4, 5, 5, 5, ...} elements
59+
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
streamer class C(Int x, Monitor<Int> m)
2+
3+
Unit register()
4+
Monitor<Int> m = monitor("
5+
SELECT ?x
6+
FROM STREAM %1 [RANGE 5s STEP 2s]
7+
WHERE { ?s prog:C_x ?x }
8+
", this);
9+
this.m = m;
10+
end
11+
12+
Unit doStream() emits(this.x)
13+
this.x = this.x + 1;
14+
end
15+
16+
String windowToString()
17+
String s = "";
18+
List<Int> l = window(this.m);
19+
while l != null do
20+
s = s ++ intToString(l.content) ++ " ";
21+
l = l.next;
22+
end
23+
return s;
24+
end
25+
end
26+
27+
main
28+
C o = new C(0, null);
29+
o.register();
30+
31+
clock Int i = 100;
32+
Int endAt = 200;
33+
34+
while i < endAt do
35+
o.doStream();
36+
String res = o.windowToString();
37+
print(">>" ++ intToString(i) ++ ": " ++ res);
38+
i = i + 1;
39+
end
40+
end
41+
42+
// Output:
43+
// >>100:
44+
// >>101:
45+
// >>102: 1 2
46+
// >>103: 1 2
47+
// >>104: 1 2 3 4
48+
// >>105: 1 2 3 4
49+
// >>106: 2 3 4 5 6
50+
// >>107: 2 3 4 5 6
51+
// >>108: 4 5 6 7 8
52+
// ..
53+
54+
// Notes:
55+
// - Multiple elements in the window because there is no aggregation function
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
streamer class C(Int x, Monitor<Int> m)
2+
3+
Unit register()
4+
Monitor<Int> m = monitor("
5+
SELECT (COUNT(?x) as ?countX)
6+
FROM STREAM %1 [RANGE 5s STEP 2s]
7+
WHERE { ?s prog:C_x ?x }
8+
", this);
9+
this.m = m;
10+
end
11+
12+
Unit doStream() emits(this.x)
13+
this.x = this.x + 1;
14+
end
15+
16+
String windowToString()
17+
String s = "";
18+
List<Int> l = window(this.m);
19+
while l != null do
20+
s = s ++ intToString(l.content) ++ " ";
21+
l = l.next;
22+
end
23+
return s;
24+
end
25+
end
26+
27+
main
28+
C o = new C(0, null);
29+
o.register();
30+
31+
clock Int i = 100;
32+
Int endAt = 200;
33+
34+
while i < endAt do
35+
o.doStream();
36+
String res = o.windowToString();
37+
print(">>" ++ intToString(i) ++ ": " ++ res);
38+
i = i + 1;
39+
end
40+
end
41+
42+
// Output:
43+
// >>100:
44+
// >>101:
45+
// >>102: 2
46+
// >>103: 2
47+
// >>104: 4
48+
// >>105: 4
49+
// >>106: 5
50+
// >>107: 5
51+
// >>108: 5
52+
// ..
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
streamer class C(Int x, Monitor<Double> m)
2+
3+
Unit register()
4+
Monitor<Double> m = monitor("
5+
SELECT (AVG(?x) as ?avgX)
6+
FROM STREAM %1 [RANGE 5s STEP 2s]
7+
WHERE { ?s prog:C_x ?x }
8+
", this);
9+
this.m = m;
10+
end
11+
12+
Unit doStream() emits(this.x)
13+
this.x = this.x + 1;
14+
end
15+
16+
String windowToString()
17+
String s = "";
18+
List<Double> l = window(this.m);
19+
while l != null do
20+
s = s ++ doubleToString(l.content) ++ " ";
21+
l = l.next;
22+
end
23+
return s;
24+
end
25+
end
26+
27+
main
28+
C o = new C(0, null);
29+
o.register();
30+
31+
clock Int i = 100;
32+
Int endAt = 200;
33+
34+
while i < endAt do
35+
o.doStream();
36+
String res = o.windowToString();
37+
print(">>" ++ intToString(i) ++ ": " ++ res);
38+
i = i + 1;
39+
end
40+
end
41+
42+
// Output:
43+
// >>100:
44+
// >>101:
45+
// >>102: 1.5 = (1+2) / 2
46+
// >>103: 1.5
47+
// >>104: 2.5 = (1+2+3+4) / 4
48+
// >>105: 2.5
49+
// >>106: 4.0 = (2+3+4+5+6) / 5
50+
// >>107: 4.0
51+
// >>108: 6.0 = (4+5+6+7+8) / 5
52+
// >>109: 6.0
53+
// >>110: 8.0 = (6+7+8+9+10) / 5
54+
// ..
55+
56+
// Notes:
57+
// - Average returns double values (not integer)

0 commit comments

Comments
 (0)