blob: 9bd04db3b5f045f753c9bcce633d7ddc74e5dcc3 [file] [log] [blame]
Ian Maxon305858c2015-10-01 19:00:14 -07001/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
genia.likes.science@gmail.com67605862013-10-04 05:43:57 -070019$(document).ready(function() {
20
21 var A = new AsterixDBConnection().dataverse("TinySocial");
22
23 function addResult(dom, res) {
24 for (i in res) {
25 $(dom).append(res[i] + "<br/>");
26 }
27 }
28
29 // 0A - Exact-Match Lookup
30 $('#run0a').click(function () {
31 $('#result0a').html('');
32
33 var expression0a = new FLWOGRExpression()
34 .ForClause("$user", new AExpression("dataset FacebookUsers"))
35 .WhereClause(new AExpression("$user.id = 8"))
36 .ReturnClause("$user");
37
38 var success0a = function(res) {
39 addResult('#result0a', res["results"]);
40 };
41
42 A.query(expression0a.val(), success0a);
43 });
44
45 // 0B - Range Scan
46 $("#run0b").click(function() {
47 $('#result0b').html('');
48
49 var expression0b = new FLWOGRExpression()
50 .ForClause("$user", new AExpression("dataset FacebookUsers"))
51 .WhereClause().and(new AExpression("$user.id >= 2"), new AExpression("$user.id <= 4"))
52 .ReturnClause("$user");
53
54 var success0b = function(res) {
55 addResult('#result0b', res["results"]);
56 };
57
58 A.query(expression0b.val(), success0b);
59 });
60
61 // 1 - Other Query Filters
62 $("#run1").click(function() {
63 $('#result1').html('');
64
65 var expression1 = new FLWOGRExpression()
66 .ForClause("$user", new AExpression("dataset FacebookUsers"))
67 .WhereClause().and(
68 new AExpression("$user.user-since >= datetime('2010-07-22T00:00:00')"),
69 new AExpression("$user.user-since <= datetime('2012-07-29T23:59:59')")
70 )
71 .ReturnClause("$user");
72
73 var success1 = function(res) {
74 addResult('#result1', res["results"]);
75 };
76 A.query(expression1.val(), success1);
77 });
78
79 // 2A - Equijoin
80 $("#run2a").click(function() {
81 $('#result2a').html('');
82
83 var expression2a = new FLWOGRExpression()
84 .ForClause ("$user", new AExpression("dataset FacebookUsers"))
85 .ForClause ("$message", new AExpression("dataset FacebookMessages"))
86 .WhereClause(new AExpression("$message.author-id = $user.id"))
87 .ReturnClause({
88 "uname" : "$user.name",
89 "message" : "$message.message"
90 });
91
92 var success2a = function(res) {
93 addResult('#result2a', res["results"]);
94 };
95 A.query(expression2a.val(), success2a);
96 });
97
98 // 2B - Index Join
99 $("#run2b").click(function() {
100 $('#result2b').html('');
101
102 var expression2b = new FLWOGRExpression()
103 .ForClause ("$user", new AExpression("dataset FacebookUsers"))
104 .ForClause ("$message", new AExpression("dataset FacebookMessages"))
105 .WhereClause(new AExpression("$message.author-id /*+ indexnl */ = $user.id"))
106 .ReturnClause({
107 "uname" : "$user.name",
108 "message" : "$message.message"
109 });
110
111 var success2b = function(res) {
112 addResult('#result2b', res["results"]);
113 };
114 A.query(expression2b.val(), success2b);
115 });
116
117 // 3 - Nested Outer Join
118 $("#run3").click(function() {
119 $('#result3').html('');
120
121 var expression3messages = new FLWOGRExpression()
122 .ForClause("$message", new AExpression("dataset FacebookMessages"))
123 .WhereClause(new AExpression("$message.author-id = $user.id"))
124 .ReturnClause("$message.message");
125
126 var expression3 = new FLWOGRExpression()
127 .ForClause ("$user", new AExpression("dataset FacebookUsers"))
128 .ReturnClause({
129 "uname": "$user.name",
130 "messages" : expression3messages
131 });
132
133 var success3 = function(res) {
134 addResult('#result3', res["results"]);
135 };
136 A.query(expression3.val(), success3);
137 });
138
139 // 4 - Theta Join
140 $("#run4").click(function() {
141 $('#result4').html('');
142
143 var expression4messages = new FLWOGRExpression()
144 .ForClause( "$t2", new AExpression("dataset TweetMessages"))
145 .WhereClause( new AExpression("spatial-distance($t.sender-location, $t2.sender-location) <= 1"))
146 .ReturnClause({ "msgtxt" : "$t2.message-text" });
147
148 var expression4 = new FLWOGRExpression()
149 .ForClause( "$t", new AExpression("dataset TweetMessages"))
150 .ReturnClause({
151 "message" : "$t.message-text",
152 "nearby-messages" : expression4messages
153 });
154
155 var success4 = function(res) {
156 addResult('#result4', res["results"]);
157 };
158 A.query(expression4.val(), success4);
159 });
160
161 // 5 - Fuzzy Join
162 $("#run5").click(function() {
163 $('#result5').html('');
164
165 var similarUsersExpression = new FLWOGRExpression()
166 .ForClause("$t", new AExpression("dataset TweetMessages"))
167 .LetClause ("$tu", new AExpression("$t.user"))
168 .WhereClause(new AExpression("$tu.name ~= $fbu.name"))
169 .ReturnClause({
170 "twitter-screenname": "$tu.screen-name",
171 "twitter-name": "$tu.name"
172 });
173
174 var expression5 = new FLWOGRExpression()
175 .ForClause ("$fbu", new AExpression("dataset FacebookUsers"))
176 .ReturnClause(
177 {
178 "id" : "$fbu.id",
179 "name" : "$fbu.name",
180 "similar-users" : similarUsersExpression
181 }
182 );
183
184 var success5 = function (res) {
185 addResult('#result5', res["results"]);
186 };
187
188 var simfunction = new SetStatement( "simfunction", "edit-distance" );
189 var simthreshold = new SetStatement( "simthreshold", "3");
190
191 A.query(
192 [ simfunction.val() , simthreshold.val() , expression5.val() ],
193 success5
194 );
195 });
196
197 // 6 - Existential Quantification
198 $("#run6").click(function() {
199 $('#result6').html('');
200
201 var expression6 = new FLWOGRExpression()
202 .ForClause ("$fbu", new AQLClause().set("dataset FacebookUsers"))
203 .WhereClause(
204 new QuantifiedExpression (
205 "some" ,
206 {"$e" : new AExpression("$fbu.employment") },
207 new FunctionExpression("is-null", new AExpression("$e.end-date"))
208 )
209 )
210 .ReturnClause("$fbu");
211
212 var success6 = function(res) {
213 addResult('#result6',res["results"]);
214 };
215
216 A.query(expression6.val(), success6);
217 });
218
219 // 7 - Universal Quantification
220 $("#run7").click(function() {
221 $('#result7').html('');
222
223 var expression7 = new FLWOGRExpression()
224 .ForClause("$fbu", new AExpression("dataset FacebookUsers"))
225 .WhereClause(
226 new QuantifiedExpression (
227 "every" ,
228 {"$e" : new AExpression("$fbu.employment") },
229 new FunctionExpression("not", new FunctionExpression("is-null", new AExpression("$e.end-date")))
230 )
231 )
232 .ReturnClause("$fbu");
233
234 var success7 = function(res) {
235 addResult('#result7', res["results"]);
236 };
237 A.query(expression7.val(), success7);
238 });
239
240 // 8 - Simple Aggregation
241 $('#run8').click(function () {
242
243 $('#result8').html('');
244
245 var expression8 = new FunctionExpression(
246 "count",
247 new FLWOGRExpression()
248 .ForClause("$fbu", new AExpression("dataset FacebookUsers"))
249 .ReturnClause("$fbu")
250 );
251
252 var success8 = function(res) {
253 addResult('#result8', res["results"]);
254 };
255 A.query(expression8.val(), success8);
256 });
257
258 // 9a - Grouping & Aggregation
259 $("#run9a").click(function() {
260 $('#result9a').html('');
261
262 var expression9a = new FLWOGRExpression()
263 .ForClause("$t", new AExpression("dataset TweetMessages"))
264 .GroupClause("$uid", new AExpression("$t.user.screen-name"), "with", "$t")
265 .ReturnClause(
266 {
267 "user" : "$uid",
268 "count" : new FunctionExpression("count", new AExpression("$t"))
269 }
270 );
271
272 var success9a = function(res) {
273 addResult('#result9a', res["results"]);
274 };
275 A.query(expression9a.val(), success9a);
276 });
277
278 // 9b - Hash-based Grouping & Aggregation
279 $("#run9b").click(function() {
280 $('#result9b').html('');
281
282 var expression9b = new FLWOGRExpression()
283 .ForClause("$t", new AExpression("dataset TweetMessages"))
284 .AQLClause("/*+ hash*/")
285 .GroupClause("$uid", new AExpression("$t.user.screen-name"), "with", "$t")
286 .ReturnClause(
287 {
288 "user" : "$uid",
289 "count" : new FunctionExpression("count", new AExpression("$t"))
290 }
291 );
292
293 var success9b = function(res) {
294 addResult('#result9b', res["results"]);
295 };
296 A.query(expression9b.val(), success9b);
297 });
298
299 // 10 - Grouping and Limits
300 $("#run10").click(function() {
301 $('#result10').html('');
302
303 var expression10 = new FLWOGRExpression()
304 .ForClause("$t", new AExpression("dataset TweetMessages"))
305 .GroupClause("$uid", new AExpression("$t.user.screen-name"), "with", "$t")
306 .LetClause("$c", new FunctionExpression("count", new AExpression("$t")))
307 .OrderbyClause( new AExpression("$c"), "desc" )
308 .LimitClause(new AExpression("3"))
309 .ReturnClause(
310 {
311 "user" : "$uid",
312 "count" : "$c"
313 }
314 );
315
316 var success10 = function(res) {
317 addResult('#result10', res["results"]);
318 };
319 A.query(expression10.val(), success10);
320 });
321
322 // 11 - Left Outer Fuzzy Join
323 $("#run11").click(function() {
324 $('#result11').html('');
325
326 var expression11 = new FLWOGRExpression()
327 .ForClause( "$t", new AExpression("dataset TweetMessages"))
328 .ReturnClause({
329 "tweet" : new AExpression("$t"),
330 "similar-tweets": new FLWOGRExpression()
331 .ForClause( "$t2", new AExpression("dataset TweetMessages"))
332 .WhereClause().and(
333 new AExpression("$t2.referred-topics ~= $t.referred-topics"),
334 new AExpression("$t2.tweetid != $t.tweetid")
335 )
336 .ReturnClause("$t2.referred-topics")
337 });
338
339 var success11 = function(res) {
340 addResult('#result11', res["results"]);
341 };
342
343 var simfunction = new SetStatement( "simfunction", "jaccard" );
344 var simthreshold = new SetStatement( "simthreshold", "0.3");
345 A.query(
346 [ simfunction.val(), simthreshold.val(), expression11.val()],
347 success11
348 );
349
350 });
351
352 /*$('#run0a').trigger('click');
353 $('#run0b').trigger('click');
354 $('#run1').trigger('click');
355 $('#run2a').trigger('click');
356 $('#run2b').trigger('click');
357 $('#run3').trigger('click');
358 $('#run4').trigger('click');
359 $('#run5').trigger('click');
360 $('#run6').trigger('click');
361 $('#run7').trigger('click');
362 $('#run8').trigger('click');
363 $('#run9a').trigger('click');
364 $('#run9b').trigger('click');
365 $('#run10').trigger('click');
366 $('#run11').trigger('click');*/
367});