blob: 3e1537a84cb307a660554a7ea5f57c658857d0af [file] [log] [blame]
genia.likes.science@gmail.com67605862013-10-04 05:43:57 -07001<!DOCTYPE html>
2
3<html>
4<head>
5 <title>AsterixDB TinySocial Demo</title>
6
7 <style>
8 .pretty-printed {
9 background-color: #eeeeee;
10 margin-bottom: 1em;
11 }
12
13 .how-to-run {
14 background-color: #c8c8c8;
15 margin-bottom: 1em;
16 }
17
18 .result-output {
19 background-color: #BED8E5;
20 margin-bottom: 1em;
21 overflow-x: scroll;
22 overflow-y: none;
23 }
24
25 body {
26 font-family : "Helvetica";
27 margin-bottom: 1em;
28 }
29 </style>
30
31 <link href="static/css/bootstrap.min.css" rel="stylesheet">
32
33 <script src="static/js/jquery.min.js"></script>
34 <script src="static/js/bootstrap.min.js"></script>
35 <script src="static/js/asterix-sdk-stable.js"></script>
36 <script src="static/js/demo.js"></script>
37</head>
38<body>
39 <div class="container">
40 <h1>AQL: Querying TinySocial AsterixDB</h1>
41
42 <h2>Query 0-A - Exact-Match Lookup</h2>
43 <div class="sample-query">
44
45 <div class="pretty-printed"><pre>
46 use dataverse TinySocial;
47
48 for $user in dataset FacebookUsers
49 where $user.id = 8
50 return $user;
51 </pre></div>
52
53 <div class="how-to-run"><pre><code class="javascript">
54 var expression0a = new FLWOGRExpression()
55 .ForClause("$user", new AExpression("dataset FacebookUsers"))
56 .WhereClause(new AExpression("$user.id = 8"))
57 .ReturnClause("$user");
58 </code></pre></div>
59
60 <div class="result-output" id="result0a">
61 </div>
62
63 <button id="run0a">Run #0-A</button>
64 </div>
65 <hr/>
66 <h2>Query 0-B - Range Scan</h2>
67 <div class="sample-query">
68
69 <div class="pretty-printed"><pre>
70 use dataverse TinySocial;
71
72 for $user in dataset FacebookUsers
73 where $user.id >= 2 and $user.id <= 4
74 return $user;
75 </pre></div>
76
77 <div class="how-to-run"><pre><code class="javascript">
78 var expression0b = new FLWOGRExpression()
79 .ForClause("$user", new AExpression("dataset FacebookUsers"))
80 .WhereClause().and(new AExpression("$user.id >= 2"), new AExpression("$user.id <= 4"))
81 .ReturnClause("$user");
82 </code></pre></div>
83
84 <div class="result-output" id="result0b">
85 </div>
86
87 <button id="run0b">Run #0-B</button>
88 </div>
89 <hr/>
90
91 <h2>Query 1 - Other Query Filters</h2>
92 <div class="sample-query">
93 <div class="pretty-printed"><pre>
94 use dataverse TinySocial;
95
96 for $user in dataset FacebookUsers
97 where $user.user-since >= datetime('2010-07-22T00:00:00')
98 and $user.user-since <= datetime('2012-07-29T23:59:59')
99 return $user;
100 </pre></div>
101
102 <div class="how-to-run"><pre><code class="javascript">
103 var expression1 = new FLWOGRExpression()
104 .ForClause("$user", new AExpression("dataset FacebookUsers"))
105 .WhereClause().and(
106 new AExpression("$user.user-since >= datetime('2010-07-22T00:00:00')"),
107 new AExpression("$user.user-since <= datetime('2012-07-29T23:59:59')")
108 )
109 .ReturnClause("$user");
110 </code></pre></div>
111
112 <div class="result-output" id="result1">
113 </div>
114
115 <button id="run1">Run #1</button>
116 </div>
117 <hr/>
118
119 <h2>Query 2-A - Equijoin</h2>
120 <div class="sample-query">
121 <div class="pretty-printed"><pre>
122 use dataverse TinySocial;
123
124 for $user in dataset FacebookUsers
125 for $message in dataset FacebookMessages
126 where $message.author-id = $user.id
127 return {
128 "uname": $user.name,
129 "message": $message.message
130 };
131 </pre></div>
132
133 <div class="how-to-run"><pre><code class="javascript">
134 var expression2a = new FLWOGRExpression()
135 .ForClause ("$user", new AExpression("dataset FacebookUsers"))
136 .ForClause ("$message", new AExpression("dataset FacebookMessages"))
137 .WhereClause(new AExpression("$message.author-id = $user.id"))
138 .ReturnClause({
139 "uname" : "$user.name",
140 "message" : "$message.message"
141 });
142 </code></pre></div>
143
144 <div class="result-output" id="result2a">
145 </div>
146
147 <button id="run2a">Run #2-A</button>
148 </div>
149 <hr/>
150
151 <h2>Query 2-B - Index join</h2>
152 <div class="sample-query">
153 <div class="pretty-printed"><pre>
154 use dataverse TinySocial;
155
156 for $user in dataset FacebookUsers
157 for $message in dataset FacebookMessages
158 where $message.author-id /*+ indexnl */ = $user.id
159 return {
160 "uname": $user.name,
161 "message": $message.message
162 };
163 </pre></div>
164
165 <div class="how-to-run"><pre><code class="javascript">
166 var expression2b = new FLWOGRExpression()
167 .ForClause ("$user", new AExpression("dataset FacebookUsers"))
168 .ForClause ("$message", new AExpression("dataset FacebookMessages"))
169 .WhereClause(new AExpression("$message.author-id /*+ indexnl */ = $user.id"))
170 .ReturnClause({
171 "uname" : "$user.name",
172 "message" : "$message.message"
173 });
174 </code></pre></div>
175
176 <div class="result-output" id="result2b">
177 </div>
178
179 <button id="run2b">Run #2-B</button>
180 </div>
181 <hr/>
182
183 <h2>Query 3 - Nested Outer Join</h2>
184 <div class="sample-query">
185 <div class="pretty-printed"><pre>
186 use dataverse TinySocial;
187
188 for $user in dataset FacebookUsers
189 return {
190 "uname": $user.name,
191 "messages": for $message in dataset FacebookMessages
192 where $message.author-id = $user.id
193 return $message.message
194 };
195 </pre></div>
196
197 <div class="how-to-run"><pre><code class="javascript">
198 var expression3messages = new FLWOGRExpression()
199 .ForClause("$message", new AExpression("dataset FacebookMessages"))
200 .WhereClause(new AExpression("$message.author-id = $user.id"))
201 .ReturnClause("$message.message");
202
203 var expression3 = new FLWOGRExpression()
204 .ForClause ("$user", new AExpression("dataset FacebookUsers"))
205 .ReturnClause({
206 "uname": "$user.name",
207 "messages" : expression3messages
208 });
209 </code></pre></div>
210
211 <div class="result-output" id="result3">
212 </div>
213
214 <button id="run3">Run #3</button>
215 </div>
216 <hr/>
217
218 <h2>Query 4 - Theta Join</h2>
219 <div class="sample-query">
220 <div class="pretty-printed"><pre>
221 use dataverse TinySocial;
222
223 for $t in dataset TweetMessages
224 return {
225 "message": $t.message-text,
226 "nearby-messages": for $t2 in dataset TweetMessages
227 where spatial-distance($t.sender-location, $t2.sender-location) <= 1
228 return { "msgtxt":$t2.message-text}
229 };
230 </pre></div>
231
232 <div class="how-to-run"><pre><code class="javascript">
233 var expression4messages = new FLWOGRExpression()
234 .ForClause( "$t2", new AExpression("dataset TweetMessages"))
235 .WhereClause( new AExpression("spatial-distance($t.sender-location, $t2.sender-location) <= 1"))
236 .ReturnClause({ "msgtxt" : "$t2.message-text" });
237
238 var expression4 = new FLWOGRExpression()
239 .ForClause( "$t", new AExpression("dataset TweetMessages"))
240 .ReturnClause({
241 "message" : "$t.message-text",
242 "nearby-messages" : expression4messages
243 });
244 </code></pre></div>
245
246 <div class="result-output" id="result4">
247 </div>
248
249 <button id="run4">Run #4</button>
250 </div>
251 <hr/>
252
253 <h2>Query 5 - Fuzzy Join</h2>
254 <div class="sample-query">
255 <div class="pretty-printed"><pre>
256 use dataverse TinySocial;
257
258 set simfunction "edit-distance";
259 set simthreshold "3";
260
261 for $fbu in dataset FacebookUsers
262 return {
263 "id": $fbu.id,
264 "name": $fbu.name,
265 "similar-users": for $t in dataset TweetMessages
266 let $tu := $t.user
267 where $tu.name ~= $fbu.name
268 return {
269 "twitter-screenname": $tu.screen-name,
270 "twitter-name": $tu.name
271 }
272 };
273 </pre></div>
274
275 <div class="how-to-run"><pre><code class="javascript">
276 var similarUsersExpression = new FLWOGRExpression()
277 .ForClause("$t", new AExpression("dataset TweetMessages"))
278 .LetClause ("$tu", new AExpression("$t.user"))
279 .WhereClause(new AExpression("$tu.name ~= $fbu.name"))
280 .ReturnClause({
281 "twitter-screenname": "$tu.screen-name",
282 "twitter-name": "$tu.name"
283 });
284
285 var expression5 = new FLWOGRExpression()
286 .ForClause ("$fbu", new AExpression("dataset FacebookUsers"))
287 .ReturnClause(
288 {
289 "id" : "$fbu.id",
290 "name" : "$fbu.name",
291 "similar-users" : similarUsersExpression
292 }
293 );
294 </code></pre></div>
295
296 <div class="result-output" id="result5">
297 </div>
298
299 <button id="run5">Run #5</button>
300 </div>
301 <hr/>
302
303 <h2>Query 6 - Existential Quantification</h2>
304 <div class="sample-query">
305 <div class="pretty-printed"><pre>
306 use dataverse TinySocial;
307
308 for $fbu in dataset FacebookUsers
309 where (some $e in $fbu.employment satisfies is-null($e.end-date))
310 return $fbu;
311 </pre></div>
312
313 <div class="how-to-run"><pre><code class="javascript">
314 var expression6 = new FLWOGRExpression()
315 .ForClause ("$fbu", new AQLClause().set("dataset FacebookUsers"))
316 .WhereClause(
317 new QuantifiedExpression (
318 "some" ,
319 {"$e" : new AExpression("$fbu.employment") },
320 new FunctionExpression("is-null", new AExpression("$e.end-date"))
321 )
322 )
323 .ReturnClause("$fbu");
324 </code></pre></div>
325
326 <div class="result-output" id="result6">
327 </div>
328
329 <button id="run6">Run #6</button>
330 </div>
331 <hr/>
332
333 <h2>Query 7 - Universal Quantification</h2>
334 <div class="sample-query">
335 <div class="pretty-printed"><pre>
336 use dataverse TinySocial;
337
338 for $fbu in dataset FacebookUsers
339 where (every $e in $fbu.employment satisfies not(is-null($e.end-date)))
340 return $fbu;
341 </pre></div>
342
343 <div class="how-to-run"><pre><code class="javascript">
344 var expression7 = new FLWOGRExpression()
345 .ForClause("$fbu", new AExpression("dataset FacebookUsers"))
346 .WhereClause(
347 new QuantifiedExpression (
348 "every" ,
349 {"$e" : new AExpression("$fbu.employment") },
350 new FunctionExpression("not", new FunctionExpression("is-null", new AExpression("$e.end-date")))
351 )
352 )
353 .ReturnClause("$fbu");
354 </code></pre></div>
355
356 <div class="result-output" id="result7">
357 </div>
358
359 <button id="run7">Run #7</button>
360 </div>
361 <hr/>
362
363 <h2>Query 8 - Simple Aggregation</h2>
364 <div class="sample-query">
365 <div class="pretty-printed"><pre>
366 use dataverse TinySocial;
367
368 count(for $fbu in dataset FacebookUsers return $fbu);
369 </pre></div>
370
371 <div class="how-to-run"><pre><code class="javascript">
372 var expression8 = new FunctionExpression(
373 "count",
374 new FLWOGRExpression()
375 .ForClause("$fbu", new AExpression("dataset FacebookUsers"))
376 .ReturnClause("$fbu")
377 );
378 </code></pre></div>
379
380 <div class="result-output" id="result8">
381 </div>
382
383 <button id="run8">Run #8</button>
384 </div>
385 <hr/>
386
387 <h2>Query 9-A - Grouping and Aggregation</h2>
388 <div class="sample-query">
389 <div class="pretty-printed"><pre>
390 use dataverse TinySocial;
391
392 for $t in dataset TweetMessages
393 group by $uid := $t.user.screen-name with $t
394 return {
395 "user": $uid,
396 "count": count($t)
397 };
398 </pre></div>
399
400 <div class="how-to-run"><pre><code class="javascript">
401 var expression9a = new FLWOGRExpression()
402 .ForClause("$t", new AExpression("dataset TweetMessages"))
403 .GroupClause("$uid", new AExpression("$t.user.screen-name"), "with", "$t")
404 .ReturnClause(
405 {
406 "user" : "$uid",
407 "count" : new FunctionExpression("count", new AExpression("$t"))
408 }
409 );
410 </code></pre></div>
411
412 <div class="result-output" id="result9a">
413 </div>
414
415 <button id="run9a">Run #9-A</button>
416 </div>
417 <hr/>
418
419 <h2>Query 9-B - (Hash-Based) Grouping and Aggregation</h2>
420 <div class="sample-query">
421 <div class="pretty-printed"><pre>
422 use dataverse TinySocial;
423
424 for $t in dataset TweetMessages
425 /*+ hash*/
426 group by $uid := $t.user.screen-name with $t
427 return {
428 "user": $uid,
429 "count": count($t)
430 };
431 </pre></div>
432
433 <div class="how-to-run"><pre><code class="javascript">
434 var expression9b = new FLWOGRExpression()
435 .ForClause("$t", new AExpression("dataset TweetMessages"))
436 .AQLClause("/*+ hash*/")
437 .GroupClause("$uid", new AExpression("$t.user.screen-name"), "with", "$t")
438 .ReturnClause(
439 {
440 "user" : "$uid",
441 "count" : new FunctionExpression("count", new AExpression("$t"))
442 }
443 );
444 </code></pre></div>
445
446 <div class="result-output" id="result9b">
447 </div>
448
449 <button id="run9b">Run #9-B</button>
450 </div>
451 <hr/>
452
453 <h2>Query 10 - Grouping and Limits</h2>
454 <div class="sample-query">
455 <div class="pretty-printed"><pre>
456 use dataverse TinySocial;
457
458 for $t in dataset TweetMessages
459 group by $uid := $t.user.screen-name with $t
460 let $c := count($t)
461 order by $c desc
462 limit 3
463 return {
464 "user": $uid,
465 "count": $c
466 };
467 </pre></div>
468
469 <div class="how-to-run"><pre><code class="javascript">
470 var expression10 = new FLWOGRExpression()
471 .ForClause("$t", new AExpression("dataset TweetMessages"))
472 .GroupClause("$uid", new AExpression("$t.user.screen-name"), "with", "$t")
473 .LetClause("$c", new FunctionExpression("count", new AExpression("$t")))
474 .OrderbyClause( new AExpression("$c"), "desc" )
475 .LimitClause(new AExpression("3"))
476 .ReturnClause(
477 {
478 "user" : "$uid",
479 "count" : "$c"
480 }
481 );
482 </code></pre></div>
483
484 <div class="result-output" id="result10">
485 </div>
486
487 <button id="run10">Run #10</button>
488 </div>
489 <hr/>
490
491 <h2>Query 11 - Left Outer Fuzzy Join</h2>
492 <div class="sample-query">
493 <div class="pretty-printed"><pre>
494 use dataverse TinySocial;
495
496 set simfunction "jaccard";
497 set simthreshold "0.3";
498
499 for $t in dataset TweetMessages
500 return {
501 "tweet": $t,
502 "similar-tweets": for $t2 in dataset TweetMessages
503 where $t2.referred-topics ~= $t.referred-topics
504 and $t2.tweetid != $t.tweetid
505 return $t2.referred-topics
506 };
507 </pre></div>
508
509 <div class="how-to-run"><pre><code class="javascript">
510 var expression11 = new FLWOGRExpression()
511 .ForClause( "$t", new AExpression("dataset TweetMessages"))
512 .ReturnClause({
513 "tweet" : new AExpression("$t"),
514 "similar-tweets": new FLWOGRExpression()
515 .ForClause( "$t2", new AExpression("dataset TweetMessages"))
516 .WhereClause().and(
517 new AExpression("$t2.referred-topics ~= $t.referred-topics"),
518 new AExpression("$t2.tweetid != $t.tweetid")
519 )
520 .ReturnClause("$t2.referred-topics")
521 });
522 </code></pre></div>
523
524 <div class="result-output" id="result11">
525 </div>
526
527 <button id="run11">Run #11</button>
528 </div>
529 </div>
530</body>
531</html>