Exact match query works correctly, fixed return bug, added some clauses
diff --git a/asterix-app/src/main/resources/sdk/static/example/demo.html b/asterix-app/src/main/resources/sdk/static/example/demo.html
index 64044ca..d9c21a0 100644
--- a/asterix-app/src/main/resources/sdk/static/example/demo.html
+++ b/asterix-app/src/main/resources/sdk/static/example/demo.html
@@ -48,7 +48,7 @@
javascript here
</div>
- <div class="result-output" id="result0A">
+ <div class="result-output" id="result0a">
</div>
<button id="run0a">Run #0-A</button>
@@ -68,7 +68,7 @@
<div class="how-to-run">
</div>
- <div class="result-output" id="result0B">
+ <div class="result-output" id="result0b">
</div>
<button id="run0b">Run #0-B</button>
diff --git a/asterix-app/src/main/resources/sdk/static/example/js/demo.js b/asterix-app/src/main/resources/sdk/static/example/js/demo.js
index 888f904..ba827b4 100644
--- a/asterix-app/src/main/resources/sdk/static/example/js/demo.js
+++ b/asterix-app/src/main/resources/sdk/static/example/js/demo.js
@@ -6,9 +6,14 @@
var expression0a = new FLWOGRExpression({
"dataverse" : "TinySocial",
"success" : function(res) {
+ alert(JSON.stringify(res));
$('#result0a').html(res["results"]);
- }
- });
+ }
+ })
+ .bind( new ForClause("user", null, new AsterixExpression().set(["dataset FacebookUsers"])) )
+ .bind( new WhereClause(new BooleanExpression("$user.id = 8")) )
+ .bind({ "return" : new AsterixExpression().set(["$user"]) });
+ alert(expression0a.val());
expression0a.run();
});
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 70815de..c5ef91c 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
@@ -156,6 +156,10 @@
if (options.hasOwnProperty("success")) {
this._success = options["success"];
}
+
+ if (options.hasOwnProperty("return")) {
+ this._properties["return"] = " return " + options["return"].val();
+ }
};
@@ -184,7 +188,19 @@
} else {
return this.error("Missing dataverse.");
}
-}
+};
+
+
+AExpression.prototype.onReturn = function() {
+ var ret = "";
+
+ if (this._properties.hasOwnProperty("return")) {
+ ret += this._properties["return"] + ";";
+ }
+
+ return ret;
+};
+
AExpression.prototype.error = function(msg) {
return "Asterix FunctionExpression Error: " + msg;
@@ -235,33 +251,69 @@
var value = AExpression.prototype.val.call(this);
- return value + this._properties["function"] + "(" + this._properties["expression"].val() + ");";
+ return value + this._properties["function"] + "(" + this._properties["expression"].val() + ");" + AExpression.prototype.onReturn.call(this);
};
-// FLOWGR Expression
// FLWOGR ::= ( ForClause | LetClause ) ( Clause )* "return" Expression
// Clause ::= ForClause | LetClause | WhereClause | OrderbyClause | GroupClause | LimitClause | DistinctClause
-// ForClause ::= "for" Variable ( "at" Variable )? "in" ( Expression )
-// LetClause ::= "let" Variable ":=" Expression
+//
// WhereClause ::= "where" Expression
// OrderbyClause ::= "order" "by" Expression ( ( "asc" ) | ( "desc" ) )? ( "," Expression ( ( "asc" ) | ( "desc" ) )? )*
// GroupClause ::= "group" "by" ( Variable ":=" )? Expression ( "," ( Variable ":=" )? Expression )* ( "decor" Variable ":=" Expression ( "," "decor" Variable ":=" Expression )* )? "with" VariableRef ( "," VariableRef )*
// LimitClause ::= "limit" Expression ( "offset" Expression )?
// DistinctClause ::= "distinct" "by" Expression ( "," Expression )*
-// Variable ::= <VARIABLE>
-
-
-// FLWOGR
+// FLWOGRExpression
//
// FLWOGRExpression ::= ( ForClause | LetClause ) ( Clause )* "return" Expression
-function FLWOGRExpression () {
+function FLWOGRExpression (options) {
+ // Initialize superclass
+ AExpression.call(this);
+ this._properties["clauses"] = [];
+
+ // Bind options and return
+ this.bind(options);
+ return this;
}
+FLWOGRExpression.prototype = Object.create(AExpression.prototype);
+FLWOGRExpression.prototype.constructor = FLWOGRExpression;
+
+
+FLWOGRExpression.prototype.bind = function(options) {
+ AExpression.prototype.bind.call(this, options);
+
+ var options = options || {};
+
+ if (this._properties["clauses"].length == 0) {
+ // Needs to start with for or let clause
+ if (options instanceof ForClause || options instanceof LetClause) {
+ this._properties["clauses"].push(options);
+ }
+ } else {
+ if (options instanceof AQLClause) {
+ this._properties["clauses"].push(options);
+ }
+ }
+
+ return this;
+};
+
+
+FLWOGRExpression.prototype.val = function() {
+ var value = AExpression.prototype.val.call(this);
+
+ for (var c in this._properties["clauses"]) {
+ value += this._properties["clauses"][c].val() + " ";
+ }
+
+ return value + AExpression.prototype.onReturn.call(this);
+};
+
// AQLClause
//
// Base Clause ::= ForClause | LetClause | WhereClause | OrderbyClause | GroupClause | LimitClause | DistinctClause
@@ -318,3 +370,80 @@
ForClause.prototype = Object.create(AQLClause.prototype);
ForClause.prototype.constructor = ForClause;
+
+
+// LetClause
+//
+// Grammar:
+// LetClause ::= "let" Variable ":=" Expression
+//
+// @param let_variable [String]
+// @param expression [AExpression]
+//
+// TODO Vigorous error checking
+function LetClause(let_variable, expression) {
+ AQLClause.call(this);
+
+ this._properties["clause"] = "let $" + let_variable + " := ";
+ this._properties["clause"] += expression.val();
+
+ return this;
+}
+
+LetClause.prototype = Object.create(AQLClause.prototype);
+LetClause.prototype.constructor = LetClause;
+
+
+// WhereClause
+//
+// Grammar:
+// ::= "where" Expression
+//
+// @param expression [BooleanExpression], pushes this expression onto the stack
+//
+// TODO Error fixing
+function WhereClause(expression) {
+ AQLClause.call(this);
+
+ this._properties["stack"] = [];
+
+ this.bind(expression);
+
+ return this;
+}
+
+
+WhereClause.prototype = Object.create(AQLClause.prototype);
+WhereClause.prototype.constructor = WhereClause;
+
+
+WhereClause.prototype.bind = function(expression) {
+ if (expression instanceof BooleanExpression) {
+ this._properties["stack"].push(expression);
+ }
+};
+
+
+WhereClause.prototype.val = function() {
+ var value = "where ";
+
+ var count = this._properties["stack"].length - 1;
+ while (count >= 0) {
+ value += this._properties["stack"][count].val() + " ";
+ count -= 1;
+ }
+
+ return value;
+}
+
+
+// BooleanExpression
+//
+// TODO
+function BooleanExpression(expression) {
+ this.value = expression;
+}
+
+BooleanExpression.prototype.val = function() {
+ return this.value;
+}