Rewrites queries to cleaner syntax
diff --git a/asterix-app/src/main/resources/sdk/static/AdmAql101/demo.html b/asterix-app/src/main/resources/sdk/static/AdmAql101/demo.html
index 3afaaa4..7ad27ae 100644
--- a/asterix-app/src/main/resources/sdk/static/AdmAql101/demo.html
+++ b/asterix-app/src/main/resources/sdk/static/AdmAql101/demo.html
@@ -6,23 +6,25 @@
<style>
.pretty-printed {
- background-color: #eeeeee;
- margin-bottom: 1em;
+ background-color: #eeeeee;
+ margin-bottom: 1em;
}
.how-to-run {
- background-color: #c8c8c8;
- margin-bottom: 1em;
+ background-color: #c8c8c8;
+ margin-bottom: 1em;
}
.result-output {
- background-color: #BED8E5;
- margin-bottom: 1em;
+ background-color: #BED8E5;
+ margin-bottom: 1em;
+ overflow-x: scroll;
+ overflow-y: none;
}
body {
- font-family : "Helvetica";
- margin-bottom: 1em;
+ font-family : "Helvetica";
+ margin-bottom: 1em;
}
</style>
@@ -46,8 +48,8 @@
<div class="how-to-run"><pre><code class="javascript">
var expression0a = new FLWOGRExpression()
- .bind( new ForClause("user", new AExpression().set("dataset FacebookUsers")))
- .bind( new WhereClause(new AExpression().set("$user.id = 8")))
+ .ForClause("$user", new AExpression("dataset FacebookUsers"))
+ .WhereClause(new AExpression("$user.id = 8"))
.ReturnClause("$user");
</code></pre></div>
@@ -70,12 +72,9 @@
<div class="how-to-run"><pre><code class="javascript">
var expression0b = new FLWOGRExpression()
- .bind( new ForClause("user", new AExpression().set("dataset FacebookUsers")))
- .bind( new WhereClause().and(
- new AExpression().set("$user.id >= 2"),
- new AExpression().set("$user.id <= 4")
- ))
- .ReturnClause("$user");
+ .ForClause("$user", new AExpression("dataset FacebookUsers"))
+ .WhereClause().and(new AExpression("$user.id >= 2"), new AExpression("$user.id <= 4"))
+ .ReturnClause("$user");
</code></pre></div>
<div class="result-output" id="result0b">
@@ -98,11 +97,11 @@
<div class="how-to-run"><pre><code class="javascript">
var expression1 = new FLWOGRExpression()
- .bind( new ForClause("user", new AExpression().set("dataset FacebookUsers")))
- .bind( new WhereClause().and(
- new AExpression().set("$user.user-since >= datetime('2010-07-22T00:00:00')"),
- new AExpression().set("$user.user-since <= datetime('2012-07-29T23:59:59')")
- ))
+ .ForClause("$user", new AExpression("dataset FacebookUsers"))
+ .WhereClause().and(
+ new AExpression("$user.user-since >= datetime('2010-07-22T00:00:00')"),
+ new AExpression("$user.user-since <= datetime('2012-07-29T23:59:59')")
+ )
.ReturnClause("$user");
</code></pre></div>
@@ -129,13 +128,13 @@
<div class="how-to-run"><pre><code class="javascript">
var expression2a = new FLWOGRExpression()
- .bind( new ForClause ("user", new AQLClause().set("dataset FacebookUsers")))
- .bind( new ForClause ("message", new AQLClause().set("dataset FacebookMessages")))
- .bind( new WhereClause (new AExpression().set("$message.author-id = $user.id")))
+ .ForClause ("$user", new AExpression("dataset FacebookUsers"))
+ .ForClause ("$message", new AExpression("dataset FacebookMessages"))
+ .WhereClause(new AExpression("$message.author-id = $user.id"))
.ReturnClause({
- "uname" : "$user.name",
- "message" : "$message.message"
- });
+ "uname" : "$user.name",
+ "message" : "$message.message"
+ });
</code></pre></div>
<div class="result-output" id="result2a">
@@ -161,15 +160,13 @@
<div class="how-to-run"><pre><code class="javascript">
var expression2b = new FLWOGRExpression()
- .bind( new ForClause ("user", new AQLClause().set("dataset FacebookUsers")))
- .bind( new ForClause ("message", new AQLClause().set("dataset FacebookMessages")))
- .bind( new WhereClause (new AExpression().set("$message.author-id /*+ indexnl */ = $user.id")))
- .ReturnClause(
- {
+ .ForClause ("$user", new AExpression("dataset FacebookUsers"))
+ .ForClause ("$message", new AExpression("dataset FacebookMessages"))
+ .WhereClause(new AExpression("$message.author-id /*+ indexnl */ = $user.id"))
+ .ReturnClause({
"uname" : "$user.name",
"message" : "$message.message"
- }
- );
+ });
</code></pre></div>
<div class="result-output" id="result2b">
@@ -195,12 +192,12 @@
<div class="how-to-run"><pre><code class="javascript">
var expression3messages = new FLWOGRExpression()
- .bind( new ForClause("message", new AExpression().set("dataset FacebookMessages")))
- .bind( new WhereClause(new AExpression().set("$message.author-id = $user.id")))
+ .ForClause("$message", new AExpression("dataset FacebookMessages"))
+ .WhereClause(new AExpression("$message.author-id = $user.id"))
.ReturnClause("$message.message");
var expression3 = new FLWOGRExpression()
- .bind( new ForClause ("user", new AQLClause().set("dataset FacebookUsers")))
+ .ForClause ("$user", new AExpression("dataset FacebookUsers"))
.ReturnClause({
"uname": "$user.name",
"messages" : expression3messages
@@ -230,12 +227,12 @@
<div class="how-to-run"><pre><code class="javascript">
var expression4messages = new FLWOGRExpression()
- .bind( new ForClause( "t2", new AExpression().set("dataset TweetMessages")))
- .bind( new WhereClause( new AExpression().set("spatial-distance($t.sender-location, $t2.sender-location) <= 1")))
+ .ForClause( "$t2", new AExpression("dataset TweetMessages"))
+ .WhereClause( new AExpression("spatial-distance($t.sender-location, $t2.sender-location) <= 1"))
.ReturnClause({ "msgtxt" : "$t2.message-text" });
var expression4 = new FLWOGRExpression()
- .bind( new ForClause( "t", new AExpression().set("dataset TweetMessages") ))
+ .ForClause( "$t", new AExpression("dataset TweetMessages"))
.ReturnClause({
"message" : "$t.message-text",
"nearby-messages" : expression4messages
@@ -273,16 +270,16 @@
<div class="how-to-run"><pre><code class="javascript">
var similarUsersExpression = new FLWOGRExpression()
- .bind( new ForClause ("t", new AQLClause().set("dataset TweetMessages")))
- .bind( new LetClause ("tu", new AExpression().set("$t.user")))
- .bind( new WhereClause (new AExpression().set("$tu.name ~= $fbu.name")))
+ .ForClause("$t", new AExpression("dataset TweetMessages"))
+ .LetClause ("$tu", new AExpression("$t.user"))
+ .WhereClause(new AExpression("$tu.name ~= $fbu.name"))
.ReturnClause({
"twitter-screenname": "$tu.screen-name",
"twitter-name": "$tu.name"
});
-
+
var expression5 = new FLWOGRExpression()
- .bind( new ForClause ("fbu", new AQLClause().set("dataset FacebookUsers")))
+ .ForClause ("$fbu", new AExpression("dataset FacebookUsers"))
.ReturnClause(
{
"id" : "$fbu.id",
@@ -311,14 +308,14 @@
<div class="how-to-run"><pre><code class="javascript">
var expression6 = new FLWOGRExpression()
- .bind( new ForClause ("fbu", new AQLClause().set("dataset FacebookUsers")))
- .bind( new WhereClause (
+ .ForClause ("$fbu", new AQLClause().set("dataset FacebookUsers"))
+ .WhereClause(
new QuantifiedExpression (
"some" ,
- {"$e" : new AQLClause().set("$fbu.employment") },
- new AQLClause().set("is-null($e.end-date)")
+ {"$e" : new AExpression("$fbu.employment") },
+ new FunctionExpression("is-null", new AExpression("$e.end-date"))
)
- ))
+ )
.ReturnClause("$fbu");
</code></pre></div>
@@ -331,7 +328,7 @@
<h2>Query 7 - Universal Quantification</h2>
<div class="sample-query">
- <div class="pretty-printed"><pre><pre>
+ <div class="pretty-printed"><pre>
use dataverse TinySocial;
for $fbu in dataset FacebookUsers
@@ -341,18 +338,15 @@
<div class="how-to-run"><pre><code class="javascript">
var expression7 = new FLWOGRExpression()
- .bind( new ForClause (
- "fbu",
- new AQLClause().set("dataset FacebookUsers")
- ))
- .bind( new WhereClause (
- new QuantifiedExpression (
- "every" ,
- {"$e" : new AQLClause().set("$fbu.employment") },
- new AQLClause().set("not(is-null($e.end-date))")
+ .ForClause("$fbu", new AExpression("dataset FacebookUsers"))
+ .WhereClause(
+ new QuantifiedExpression (
+ "every" ,
+ {"$e" : new AExpression("$fbu.employment") },
+ new FunctionExpression("not", new FunctionExpression("is-null", new AExpression("$e.end-date")))
+ )
)
- ))
- .ReturnClause("$fbu");
+ .ReturnClause("$fbu");
</code></pre></div>
<div class="result-output" id="result7">
@@ -374,7 +368,7 @@
var expression8 = new FunctionExpression(
"count",
new FLWOGRExpression()
- .bind( new ForClause("fbu", new AQLClause().set("dataset FacebookUsers")))
+ .ForClause("$fbu", new AExpression("dataset FacebookUsers"))
.ReturnClause("$fbu")
);
</code></pre></div>
@@ -401,12 +395,12 @@
<div class="how-to-run"><pre><code class="javascript">
var expression9a = new FLWOGRExpression()
- .bind( new ForClause("t", new AExpression().set("dataset TweetMessages")))
- .bind( new GroupClause("uid", new AExpression().set("$t.user.screen-name"), "with", "t") )
+ .ForClause("$t", new AExpression("dataset TweetMessages"))
+ .GroupClause("$uid", new AExpression("$t.user.screen-name"), "with", "$t")
.ReturnClause(
{
"user" : "$uid",
- "count" : new FunctionExpression("count", new AExpression().set("$t"))
+ "count" : new FunctionExpression("count", new AExpression("$t"))
}
);
</code></pre></div>
@@ -434,13 +428,13 @@
<div class="how-to-run"><pre><code class="javascript">
var expression9b = new FLWOGRExpression()
- .bind( new ForClause("t", new AExpression().set("dataset TweetMessages")))
- .bind( new AQLClause().set("/*+ hash*/"))
- .bind( new GroupClause("uid", new AExpression().set("$t.user.screen-name"), "with", "t") )
+ .ForClause("$t", new AExpression("dataset TweetMessages"))
+ .AQLClause("/*+ hash*/")
+ .GroupClause("$uid", new AExpression("$t.user.screen-name"), "with", "$t")
.ReturnClause(
{
"user" : "$uid",
- "count" : new FunctionExpression("count", new AExpression().set("$t"))
+ "count" : new FunctionExpression("count", new AExpression("$t"))
}
);
</code></pre></div>
@@ -470,20 +464,17 @@
<div class="how-to-run"><pre><code class="javascript">
var expression10 = new FLWOGRExpression()
- .bind( new ForClause("t", new AExpression().set("dataset TweetMessages")))
- .bind( new GroupClause("uid", new AExpression().set("$t.user.screen-name"), "with", "t") )
- .bind( new LetClause(
- "c",
- new FunctionExpression("count", new AExpression().set("$t"))
- ))
- .bind( new OrderbyClause( new AExpression().set("$c"), "desc" ) )
- .bind( new LimitClause(new AExpression().set("3")) )
- .ReturnClause(
- {
- "user" : "$uid",
- "count" : "$c"
- }
- );
+ .ForClause("$t", new AExpression("dataset TweetMessages"))
+ .GroupClause("$uid", new AExpression("$t.user.screen-name"), "with", "$t")
+ .LetClause("$c", new FunctionExpression("count", new AExpression("$t")))
+ .OrderbyClause( new AExpression("$c"), "desc" )
+ .LimitClause(new AExpression("3"))
+ .ReturnClause(
+ {
+ "user" : "$uid",
+ "count" : "$c"
+ }
+ );
</code></pre></div>
<div class="result-output" id="result10">
@@ -512,18 +503,18 @@
</pre></div>
<div class="how-to-run"><pre><code class="javascript">
- var expression11 = new FLWOGRExpression()
- .bind( new ForClause( "t", new AExpression().set("dataset TweetMessages") ))
+ var expression11 = new FLWOGRExpression()
+ .ForClause( "$t", new AExpression("dataset TweetMessages"))
.ReturnClause({
- "tweet" : new AExpression().set("$t"),
+ "tweet" : new AExpression("$t"),
"similar-tweets": new FLWOGRExpression()
- .bind( new ForClause( "t2", new AExpression().set("dataset TweetMessages") ))
- .bind( new WhereClause().and(
- new AExpression().set("$t2.referred-topics ~= $t.referred-topics"),
- new AExpression().set("$t2.tweetid != $t.tweetid")
- ))
+ .ForClause( "$t2", new AExpression("dataset TweetMessages"))
+ .WhereClause().and(
+ new AExpression("$t2.referred-topics ~= $t.referred-topics"),
+ new AExpression("$t2.tweetid != $t.tweetid")
+ )
.ReturnClause("$t2.referred-topics")
- });
+ });
</code></pre></div>
<div class="result-output" id="result11">
diff --git a/asterix-app/src/main/resources/sdk/static/AdmAql101/js/demo.js b/asterix-app/src/main/resources/sdk/static/AdmAql101/js/demo.js
index b0b9ec1..4b0540a 100644
--- a/asterix-app/src/main/resources/sdk/static/AdmAql101/js/demo.js
+++ b/asterix-app/src/main/resources/sdk/static/AdmAql101/js/demo.js
@@ -1,18 +1,24 @@
$(document).ready(function() {
var A = new AsterixDBConnection().dataverse("TinySocial");
+
+ function addResult(dom, res) {
+ for (i in res) {
+ $(dom).append(res[i] + "\n");
+ }
+ }
// 0A - Exact-Match Lookup
$('#run0a').click(function () {
$('#result0a').html('');
var expression0a = new FLWOGRExpression()
- .bind(new ForClause("$user", new AExpression().set("dataset FacebookUsers")))
- .bind(new WhereClause(new AExpression().set("$user.id = 8")))
+ .ForClause("$user", new AExpression("dataset FacebookUsers"))
+ .WhereClause(new AExpression("$user.id = 8"))
.ReturnClause("$user");
var success0a = function(res) {
- $('#result0a').html(res["results"]);
+ addResult('#result0a', res["results"]);
};
A.query(expression0a.val(), success0a);
@@ -23,15 +29,12 @@
$('#result0b').html('');
var expression0b = new FLWOGRExpression()
- .bind( new ForClause("$user", new AExpression().set("dataset FacebookUsers")))
- .bind( new WhereClause().and(
- new AExpression().set("$user.id >= 2"),
- new AExpression().set("$user.id <= 4")
- ))
+ .ForClause("$user", new AExpression("dataset FacebookUsers"))
+ .WhereClause().and(new AExpression("$user.id >= 2"), new AExpression("$user.id <= 4"))
.ReturnClause("$user");
var success0b = function(res) {
- $('#result0b').html(res["results"]);
+ addResult('#result0b', res["results"]);
};
A.query(expression0b.val(), success0b);
@@ -42,15 +45,15 @@
$('#result1').html('');
var expression1 = new FLWOGRExpression()
- .bind( new ForClause("$user", new AExpression().set("dataset FacebookUsers")))
- .bind( new WhereClause().and(
- new AExpression().set("$user.user-since >= datetime('2010-07-22T00:00:00')"),
- new AExpression().set("$user.user-since <= datetime('2012-07-29T23:59:59')")
- ))
+ .ForClause("$user", new AExpression("dataset FacebookUsers"))
+ .WhereClause().and(
+ new AExpression("$user.user-since >= datetime('2010-07-22T00:00:00')"),
+ new AExpression("$user.user-since <= datetime('2012-07-29T23:59:59')")
+ )
.ReturnClause("$user");
var success1 = function(res) {
- $('#result1').html(res["results"]);
+ addResult('#result1', res["results"]);
};
A.query(expression1.val(), success1);
});
@@ -60,13 +63,13 @@
$('#result2a').html('');
var expression2a = new FLWOGRExpression()
- .bind( new ForClause ("$user", new AExpression().set("dataset FacebookUsers")))
- .bind( new ForClause ("$message", new AExpression().set("dataset FacebookMessages")))
- .bind( new WhereClause (new AExpression().set("$message.author-id = $user.id")))
+ .ForClause ("$user", new AExpression("dataset FacebookUsers"))
+ .ForClause ("$message", new AExpression("dataset FacebookMessages"))
+ .WhereClause(new AExpression("$message.author-id = $user.id"))
.ReturnClause({
- "uname" : "$user.name",
- "message" : "$message.message"
- });
+ "uname" : "$user.name",
+ "message" : "$message.message"
+ });
var success2a = function(res) {
$('#result2a').html(res["results"]);
@@ -79,15 +82,13 @@
$('#result2b').html('');
var expression2b = new FLWOGRExpression()
- .bind( new ForClause ("$user", new AExpression().set("dataset FacebookUsers")))
- .bind( new ForClause ("$message", new AExpression().set("dataset FacebookMessages")))
- .bind( new WhereClause (new AExpression().set("$message.author-id /*+ indexnl */ = $user.id")))
- .ReturnClause(
- {
+ .ForClause ("$user", new AExpression("dataset FacebookUsers"))
+ .ForClause ("$message", new AExpression("dataset FacebookMessages"))
+ .WhereClause(new AExpression("$message.author-id /*+ indexnl */ = $user.id"))
+ .ReturnClause({
"uname" : "$user.name",
"message" : "$message.message"
- }
- );
+ });
var success2b = function(res) {
$('#result2b').html(res["results"]);
@@ -100,12 +101,12 @@
$('#result3').html('');
var expression3messages = new FLWOGRExpression()
- .bind( new ForClause("$message", new AExpression().set("dataset FacebookMessages")))
- .bind( new WhereClause(new AExpression().set("$message.author-id = $user.id")))
+ .ForClause("$message", new AExpression("dataset FacebookMessages"))
+ .WhereClause(new AExpression("$message.author-id = $user.id"))
.ReturnClause("$message.message");
var expression3 = new FLWOGRExpression()
- .bind( new ForClause ("$user", new AExpression().set("dataset FacebookUsers")))
+ .ForClause ("$user", new AExpression("dataset FacebookUsers"))
.ReturnClause({
"uname": "$user.name",
"messages" : expression3messages
@@ -122,12 +123,12 @@
$('#result4').html('');
var expression4messages = new FLWOGRExpression()
- .bind( new ForClause( "$t2", new AExpression().set("dataset TweetMessages")))
- .bind( new WhereClause( new AExpression().set("spatial-distance($t.sender-location, $t2.sender-location) <= 1")))
+ .ForClause( "$t2", new AExpression("dataset TweetMessages"))
+ .WhereClause( new AExpression("spatial-distance($t.sender-location, $t2.sender-location) <= 1"))
.ReturnClause({ "msgtxt" : "$t2.message-text" });
var expression4 = new FLWOGRExpression()
- .bind( new ForClause( "$t", new AExpression().set("dataset TweetMessages") ))
+ .ForClause( "$t", new AExpression("dataset TweetMessages"))
.ReturnClause({
"message" : "$t.message-text",
"nearby-messages" : expression4messages
@@ -144,16 +145,16 @@
$('#result5').html('');
var similarUsersExpression = new FLWOGRExpression()
- .bind( new ForClause ("$t", new AExpression().set("dataset TweetMessages")))
- .bind( new LetClause ("$tu", new AExpression().set("$t.user")))
- .bind( new WhereClause (new AExpression().set("$tu.name ~= $fbu.name")))
+ .ForClause("$t", new AExpression("dataset TweetMessages"))
+ .LetClause ("$tu", new AExpression("$t.user"))
+ .WhereClause(new AExpression("$tu.name ~= $fbu.name"))
.ReturnClause({
"twitter-screenname": "$tu.screen-name",
"twitter-name": "$tu.name"
});
var expression5 = new FLWOGRExpression()
- .bind( new ForClause ("$fbu", new AExpression().set("dataset FacebookUsers")))
+ .ForClause ("$fbu", new AExpression("dataset FacebookUsers"))
.ReturnClause(
{
"id" : "$fbu.id",
@@ -180,14 +181,14 @@
$('#result6').html('');
var expression6 = new FLWOGRExpression()
- .bind( new ForClause ("$fbu", new AExpression().set("dataset FacebookUsers")))
- .bind( new WhereClause (
+ .ForClause ("$fbu", new AQLClause().set("dataset FacebookUsers"))
+ .WhereClause(
new QuantifiedExpression (
"some" ,
- {"$e" : new AExpression().set("$fbu.employment") },
- new AExpression().set("is-null($e.end-date)")
+ {"$e" : new AExpression("$fbu.employment") },
+ new FunctionExpression("is-null", new AExpression("$e.end-date"))
)
- ))
+ )
.ReturnClause("$fbu");
var success6 = function(res) {
@@ -202,18 +203,15 @@
$('#result7').html('');
var expression7 = new FLWOGRExpression()
- .bind( new ForClause (
- "$fbu",
- new AExpression().set("dataset FacebookUsers")
- ))
- .bind( new WhereClause (
- new QuantifiedExpression (
- "every" ,
- {"$e" : new AExpression().set("$fbu.employment") },
- new AExpression().set("not(is-null($e.end-date))")
+ .ForClause("$fbu", new AExpression("dataset FacebookUsers"))
+ .WhereClause(
+ new QuantifiedExpression (
+ "every" ,
+ {"$e" : new AExpression("$fbu.employment") },
+ new FunctionExpression("not", new FunctionExpression("is-null", new AExpression("$e.end-date")))
+ )
)
- ))
- .ReturnClause("$fbu");
+ .ReturnClause("$fbu");
var success7 = function(res) {
$('#result7').html(res["results"]);
@@ -229,7 +227,7 @@
var expression8 = new FunctionExpression(
"count",
new FLWOGRExpression()
- .bind( new ForClause("$fbu", new AExpression().set("dataset FacebookUsers")))
+ .ForClause("$fbu", new AExpression("dataset FacebookUsers"))
.ReturnClause("$fbu")
);
@@ -244,12 +242,12 @@
$('#result9a').html('');
var expression9a = new FLWOGRExpression()
- .bind( new ForClause("$t", new AExpression().set("dataset TweetMessages")))
- .bind( new GroupClause("$uid", new AExpression().set("$t.user.screen-name"), "with", "$t") )
+ .ForClause("$t", new AExpression("dataset TweetMessages"))
+ .GroupClause("$uid", new AExpression("$t.user.screen-name"), "with", "$t")
.ReturnClause(
{
"user" : "$uid",
- "count" : new FunctionExpression("count", new AExpression().set("$t"))
+ "count" : new FunctionExpression("count", new AExpression("$t"))
}
);
@@ -264,13 +262,13 @@
$('#result9b').html('');
var expression9b = new FLWOGRExpression()
- .bind( new ForClause("$t", new AExpression().set("dataset TweetMessages")))
- .bind( new AExpression().set("/*+ hash*/"))
- .bind( new GroupClause("$uid", new AExpression().set("$t.user.screen-name"), "with", "$t") )
+ .ForClause("$t", new AExpression("dataset TweetMessages"))
+ .AQLClause("/*+ hash*/")
+ .GroupClause("$uid", new AExpression("$t.user.screen-name"), "with", "$t")
.ReturnClause(
{
"user" : "$uid",
- "count" : new FunctionExpression("count", new AExpression().set("$t"))
+ "count" : new FunctionExpression("count", new AExpression("$t"))
}
);
@@ -285,14 +283,11 @@
$('#result10').html('');
var expression10 = new FLWOGRExpression()
- .bind( new ForClause("$t", new AExpression().set("dataset TweetMessages")))
- .bind( new GroupClause("$uid", new AExpression().set("$t.user.screen-name"), "with", "$t") )
- .bind( new LetClause(
- "$c",
- new FunctionExpression("count", new AExpression().set("$t"))
- ))
- .bind( new OrderbyClause( new AExpression().set("$c"), "desc" ) )
- .bind( new LimitClause(new AExpression().set("3")) )
+ .ForClause("$t", new AExpression("dataset TweetMessages"))
+ .GroupClause("$uid", new AExpression("$t.user.screen-name"), "with", "$t")
+ .LetClause("$c", new FunctionExpression("count", new AExpression("$t")))
+ .OrderbyClause( new AExpression("$c"), "desc" )
+ .LimitClause(new AExpression("3"))
.ReturnClause(
{
"user" : "$uid",
@@ -311,15 +306,15 @@
$('#result11').html('');
var expression11 = new FLWOGRExpression()
- .bind( new ForClause( "$t", new AExpression().set("dataset TweetMessages") ))
+ .ForClause( "$t", new AExpression("dataset TweetMessages"))
.ReturnClause({
- "tweet" : new AExpression().set("$t"),
+ "tweet" : new AExpression("$t"),
"similar-tweets": new FLWOGRExpression()
- .bind( new ForClause( "$t2", new AExpression().set("dataset TweetMessages") ))
- .bind( new WhereClause().and(
- new AExpression().set("$t2.referred-topics ~= $t.referred-topics"),
- new AExpression().set("$t2.tweetid != $t.tweetid")
- ))
+ .ForClause( "$t2", new AExpression("dataset TweetMessages"))
+ .WhereClause().and(
+ new AExpression("$t2.referred-topics ~= $t.referred-topics"),
+ new AExpression("$t2.tweetid != $t.tweetid")
+ )
.ReturnClause("$t2.referred-topics")
});
@@ -351,5 +346,4 @@
$('#run9b').trigger('click');
$('#run10').trigger('click');
$('#run11').trigger('click');
-
});
diff --git a/asterix-app/src/main/resources/sdk/static/js/asterix-sdk-stable.js b/asterix-app/src/main/resources/sdk/static/js/asterix-sdk-stable.js
index 6225aa7..eef557b 100644
--- a/asterix-app/src/main/resources/sdk/static/js/asterix-sdk-stable.js
+++ b/asterix-app/src/main/resources/sdk/static/js/asterix-sdk-stable.js
@@ -29,7 +29,7 @@
var m = typeof mode ? mode : "synchronous";
var query = "use dataverse " + this._properties["dataverse"] + ";\n" + statements.join("\n");
-
+
this._api(
{
"query" : query,
@@ -114,11 +114,15 @@
};
-// Asterix Expressions
function AExpression () {
+
this._properties = {};
this._success = function() {};
+ if (typeof arguments[0] == 'string') {
+ this._properties["value"] = arguments[0];
+ }
+
return this;
}
@@ -276,17 +280,69 @@
return value + clauseValues.join("\n");// + ";";
};
+// Pretty Expression Shorthand
FLWOGRExpression.prototype.ReturnClause = function(expression) {
return this.bind(new ReturnClause(expression));
};
+FLWOGRExpression.prototype.ForClause = function() {
+ return this.bind(new ForClause(Array.prototype.slice.call(arguments)));
+};
+
+FLWOGRExpression.prototype.LetClause = function() {
+ return this.bind(new LetClause(Array.prototype.slice.call(arguments)));
+};
+
+FLWOGRExpression.prototype.WhereClause = function() {
+ return this.bind(new WhereClause(Array.prototype.slice.call(arguments)));
+};
+
+FLWOGRExpression.prototype.and = function() {
+ var args = Array.prototype.slice.call(arguments);
+ args.push(true);
+ return this.bind(new WhereClause().and(args));
+};
+
+FLWOGRExpression.prototype.or = function() {
+ var args = Array.prototype.slice.call(arguments);
+ args.push(true);
+ return this.bind(new WhereClause().or(args));
+};
+
+FLWOGRExpression.prototype.OrderbyClause = function() {
+ return this.bind(new OrderbyClause(Array.prototype.slice.call(arguments)));
+};
+
+
+FLWOGRExpression.prototype.GroupClause = function() {
+ return this.bind(new GroupClause(Array.prototype.slice.call(arguments)));
+};
+
+FLWOGRExpression.prototype.LimitClause = function() {
+ return this.bind(new LimitClause(Array.prototype.slice.call(arguments)));
+};
+
+FLWOGRExpression.prototype.DistinctClause = function() {
+ return this.bind(new DistinctClause(Array.prototype.slice.call(arguments)));
+};
+
+FLWOGRExpression.prototype.AQLClause = function() {
+ return this.bind(new AQLClause(Array.prototype.slice.call(arguments)));
+};
+
+
// AQLClause
//
// Base Clause ::= ForClause | LetClause | WhereClause | OrderbyClause | GroupClause | LimitClause | DistinctClause
function AQLClause() {
this._properties = {};
this._properties["clause"] = "";
+ this._properties["stack"] = [];
+ if (typeof arguments[0] == 'string') {
+ this._properties["clause"] = arguments[0];
+ }
+ return this;
}
AQLClause.prototype.val = function() {
@@ -321,13 +377,20 @@
function ForClause(for_variable, at_variable, expression) {
AQLClause.call(this);
- this._properties["clause"] = "for " + arguments[0];
+ var parameters = [];
+ if (arguments[0] instanceof Array) {
+ parameters = arguments[0];
+ } else {
+ parameters = arguments;
+ }
+
+ this._properties["clause"] = "for " + parameters[0];
- if (arguments.length == 3) {
- this._properties["clause"] += " at " + arguments[1];
- this._properties["clause"] += " in " + arguments[2].val();
- } else if (arguments.length == 2) {
- this._properties["clause"] += " in " + arguments[1].val();
+ if (parameters.length == 3) {
+ this._properties["clause"] += " at " + parameters[1];
+ this._properties["clause"] += " in " + parameters[2].val();
+ } else if (parameters.length == 2) {
+ this._properties["clause"] += " in " + parameters[1].val();
}
return this;
@@ -349,8 +412,15 @@
function LetClause(let_variable, expression) {
AQLClause.call(this);
- this._properties["clause"] = "let " + let_variable + " := ";
- this._properties["clause"] += expression.val();
+ var parameters = [];
+ if (arguments[0] instanceof Array) {
+ parameters = arguments[0];
+ } else {
+ parameters = arguments;
+ }
+
+ this._properties["clause"] = "let " + parameters[0] + " := ";
+ this._properties["clause"] += parameters[1].val();
return this;
}
@@ -408,11 +478,15 @@
// @param expression [BooleanExpression], pushes this expression onto the stack
function WhereClause(expression) {
AQLClause.call(this);
-
+
this._properties["stack"] = [];
- this.bind(expression);
-
+ if (expression instanceof Array) {
+ this.bind(expression[0]);
+ } else {
+ this.bind(expression);
+ }
+
return this;
}
@@ -425,11 +499,16 @@
if (expression instanceof AExpression) {
this._properties["stack"].push(expression);
}
+ return this;
};
WhereClause.prototype.val = function() {
- var value = "where ";
+ var value = "";
+
+ if (this._properties["stack"].length == 0) {
+ return value;
+ }
var count = this._properties["stack"].length - 1;
while (count >= 0) {
@@ -437,17 +516,24 @@
count -= 1;
}
- return value;
+ return "where " + value;
};
WhereClause.prototype.and = function() {
+ var parameters = [];
+ if (arguments[0] instanceof Array) {
+ parameters = arguments[0];
+ } else {
+ parameters = arguments;
+ }
+
var andClauses = [];
- for (var expression in arguments) {
+ for (var expression in parameters) {
- if (arguments[expression] instanceof AExpression) {
- andClauses.push(arguments[expression].val());
+ if (parameters[expression] instanceof AExpression) {
+ andClauses.push(parameters[expression].val());
}
}
@@ -460,11 +546,19 @@
WhereClause.prototype.or = function() {
+
+ var parameters = [];
+ if (arguments[0] instanceof Array) {
+ parameters = arguments[0];
+ } else {
+ parameters = arguments;
+ }
+
var orClauses = [];
- for (var expression in arguments) {
+ for (var expression in parameters) {
- if (arguments[expression] instanceof AExpression) {
- orClauses.push(arguments[expression].val());
+ if (parameters[expression] instanceof AExpression) {
+ orClauses.push(parameters[expression].val());
}
}
@@ -484,14 +578,20 @@
function LimitClause(limitExpression, offsetExpression) {
AQLClause.call(this);
+
+ var parameters = [];
+ if (arguments[0] instanceof Array) {
+ parameters = arguments[0];
+ } else {
+ parameters = arguments;
+ }
// limitExpression required
- this._properties["clause"] = "limit " + limitExpression.val();
+ this._properties["clause"] = "limit " + parameters[0].val();
// Optional: Offset
- var offset = typeof offsetExpression ? offsetExpression : null;
- if (offset != null) {
- this._properties["clause"] += " offset " + offsetExpression.val();
+ if (parameters.length == 2) {
+ this._properties["clause"] += " offset " + parameters[1].val();
}
return this;
@@ -512,29 +612,35 @@
AQLClause.call(this);
// At least one argument expression is required, and first should be expression
- if (arguments.length == 0 || !(arguments[0] instanceof AExpression)) {
+ if (arguments.length == 0) {
- // TODO Not sure which error to throw for an empty OrderBy but this should fail.
alert("Order By Error");
this._properties["clause"] = null;
return this;
- }
+ }
+
+ var parameters = [];
+ if (arguments[0] instanceof Array) {
+ parameters = arguments[0];
+ } else {
+ parameters = arguments;
+ }
var expc = 0;
var expressions = [];
- while (expc < arguments.length) {
+ while (expc < parameters.length) {
var expression = "";
- if (arguments[expc] instanceof AExpression) {
- expression += arguments[expc].val();
+ if (parameters[expc] instanceof AExpression) {
+ expression += parameters[expc].val();
}
var next = expc + 1;
- if (next < arguments.length && (arguments[next] == "asc" || arguments[next] == "desc")) {
+ if (next < parameters.length && (parameters[next] == "asc" || parameters[next] == "desc")) {
expc++;
- expression += " " + arguments[expc];
+ expression += " " + parameters[expc];
}
expressions.push(expression);
@@ -563,29 +669,36 @@
this._properties["clause"] = null;
return this;
}
+
+ var parameters = [];
+ if (arguments[0] instanceof Array) {
+ parameters = arguments[0];
+ } else {
+ parameters = arguments;
+ }
var expc = 0;
var expressions = [];
var variableRefs = [];
var isDecor = false;
- while (expc < arguments.length) {
+ while (expc < parameters.length) {
- if (arguments[expc] instanceof AExpression) {
+ if (parameters[expc] instanceof AExpression) {
isDecor = false;
- expressions.push(arguments[expc].val());
+ expressions.push(parameters[expc].val());
- } else if (typeof arguments[expc] == "string") {
+ } else if (typeof parameters[expc] == "string") {
// Special keywords, decor & with
- if (arguments[expc] == "decor") {
+ if (parameters[expc] == "decor") {
isDecor = true;
- } else if (arguments[expc] == "with") {
+ } else if (parameters[expc] == "with") {
isDecor = false;
expc++;
- while (expc < arguments.length) {
- variableRefs.push(arguments[expc]);
+ while (expc < parameters.length) {
+ variableRefs.push(parameters[expc]);
expc++;
}
@@ -600,7 +713,7 @@
isDecor = false;
}
- expression += arguments[expc] + " := " + arguments[nextc].val();
+ expression += parameters[expc] + " := " + parameters[nextc].val();
expressions.push(expression);
expc++;
}