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