Merge branch 'eugenia/asterix_sdk_stable' of https://code.google.com/p/asterixdb into eugenia/asterix_sdk_stable
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 aafb6ae..0cca153 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
@@ -9,9 +9,9 @@
$('#result0a').html(res["results"]);
}
})
- .bind( new ForClause("user", null, new AsterixExpression().set(["dataset FacebookUsers"])) )
+ .bind( new ForClause("user", null, new AExpression().set("dataset FacebookUsers")) )
.bind( new WhereClause(new BooleanExpression("$user.id = 8")) )
- .bind({ "return" : new AsterixExpression().set(["$user"]) });
+ .bind({ "return" : new AExpression().set("$user") });
expression0a.run();
});
@@ -27,7 +27,7 @@
$('#result0b').html(res["results"]);
},
})
- .bind( new ForClause("user", null, new AsterixExpression().set(["dataset FacebookUsers"])) )
+ .bind( new ForClause("user", null, new AExpression().set("dataset FacebookUsers")) )
.bind( new WhereClause( new BooleanExpression("AND", new BooleanExpression(">=", "$user.id", 2), new BooleanExpression("<=", "$user.id", 4)) ) )
.bind( new ReturnClause("$user") );
alert(expression0b.val());
@@ -201,7 +201,7 @@
$('#result9a').html(res["results"]);
}
})
- .bind( new ForClause("t", null, new AsterixExpression().set(["dataset TweetMessages"])))
+ .bind( new ForClause("t", null, new AExpression().set("dataset TweetMessages")))
.bind( new GroupClause("uid", new AExpression().set("$t.user.screen-name"), "with", "t") )
.bind( new ReturnClause(
{
@@ -209,7 +209,7 @@
"count" : new FunctionExpression(
{
"function" : "count",
- "expression" : new AsterixExpression().set(["$t"])
+ "expression" : new AExpression().set("$t")
}
)
}
@@ -228,7 +228,7 @@
$('#result9b').html(res["results"]);
}
})
- .bind( new ForClause("t", null, new AsterixExpression().set(["dataset TweetMessages"])))
+ .bind( new ForClause("t", null, new AExpression().set("dataset TweetMessages")))
.bind( new AQLClause().set("/*+ hash*/"))
.bind( new GroupClause("uid", new AExpression().set("$t.user.screen-name"), "with", "t") )
.bind( new ReturnClause(
@@ -237,7 +237,7 @@
"count" : new FunctionExpression(
{
"function" : "count",
- "expression" : new AsterixExpression().set(["$t"])
+ "expression" : new AExpression().set("$t")
}
)
}
@@ -256,19 +256,19 @@
$('#result10').html(res["results"]);
}
})
- .bind( new ForClause("t", null, new AsterixExpression().set(["dataset TweetMessages"])))
+ .bind( new ForClause("t", null, new AExpression().set("dataset TweetMessages")))
.bind( new GroupClause("uid", new AExpression().set("$t.user.screen-name"), "with", "t") )
.bind( new LetClause(
"c",
new FunctionExpression(
{
"function" : "count",
- "expression" : new AsterixExpression().set(["$t"])
+ "expression" : new AExpression().set("$t")
}
)
))
.bind( new OrderbyClause( new AExpression().set("$c"), "desc" ) )
- .bind( new LimitClause(new AsterixExpression().set(["3"])) )
+ .bind( new LimitClause(new AExpression().set("3")) )
.bind( new ReturnClause(
{
"user" : "$uid",
@@ -291,7 +291,7 @@
})
.bind( new SetStatement( "simfunction", "jaccard" ))
.bind( new SetStatement( "simthreshold", "0.3"))
- .bind( new ForClause( "t", null, new AsterixExpression().set(["dataset TweetMessages"]) ))
+ .bind( new ForClause( "t", null, new AExpression().set("dataset TweetMessages") ))
.bind( new ReturnClause({
"tweet" : new AExpression().set("$t"),
"similar-tweets": new FLWOGRExpression()
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 d24bca3..7989a9e 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
@@ -1,171 +1,3 @@
-function AsterixSDK() {
-
- // Asterix SDK => send
- // Posts a message containing an API endpoint, json data,
- // and a UI callback function.
- //
- // @param handler [Asterix REST Controller], a handler object
- // that provides REST request information.
- //
- // Anticipated Usage:
- //
- // var a = AsterixSDK();
- // var e = Expression;
- // var h = AsterixRestController.bind(e);
- // a.send(h);
- myThis = this;
- this.callbacks = {
- "sync" : function() { alert("default sync"); },
- "async" : function() {}
- };
- this.send = function(handler, cb) {
- myThis.callbacks = cb;
- this.handler = handler;
- this.extras = handler["extras"];
- this.xhr.post(
- handler["endpoint"],
- handler["apiData"],
- this.branch
- );
- };
-
- this.branch = function(response) {
- if (response && response["error-code"]) {
-
- alert("Error [Code" + response["error-code"][0] + "]: " + response["error-code"][1]);
-
- } else if (response && response["results"]) {
- var fn_callback = myThis.callbacks["sync"];
- fn_callback(response, myThis.extras);
-
- } else if (response["handle"]) {
-
- var fn_callback = this.callbacks["async"];
- fn_callback(response, extra);
-
- } else if (response["status"]) {
-
- var fn_callback = this.callbacks["sync"];
- fn_callback(response, extra);
- }
- }
-
- // Asterix SDK => bindingHandler
- // AsterixExpression form handler where a new REST API point is bound. Takes as input any
- // AsterixExpression, each of which is bindable.
- this.bindingHandler = new AsterixExpression();
- this.bind = this.bindingHandler.bind;
-}
-
-function AsterixExpression() {
- this.init();
- return this;
-}
-
-AsterixExpression.prototype.init = function () {
- this.dataverse = ""; // TODO This shouldn't make it to send
- this.boundTo = {};
- this.clauses = [];
- this.ui_callback_on_success = function() {};
- this.ui_callback_on_success_async = function() {};
-};
-
-AsterixExpression.prototype.bind = function(expression) {
- // If expression is an AsterixExpression, it becomes base
- if (expression instanceof AsterixExpression) {
- this.boundTo = expression;
- } else if (expression instanceof AsterixClause) {
- this.clauses.push(expression.val());
- }
- return this;
-};
-
-AsterixExpression.prototype.send = function(arc) {
- // Hackiest of hacks
- var g = new AsterixSDK();
- g.send(arc, arc["callback"]);
-};
-
-AsterixExpression.prototype.clear = function() {
- this.clauses.length = 0;
- return this;
-};
-
-AsterixExpression.prototype.val = function() {
- return this.clauses.join("\n");
-};
-
-AsterixExpression.prototype.success = function(fn, isSync) {
- if (isSync) {
- this.ui_callback_on_success = fn;
- } else {
- this.ui_callback_on_success_async = fn;
- }
- return this;
-};
-
-AsterixExpression.prototype.set = function(statements_arr) {
- for (var i = 0; i < statements_arr.length; i++) {
- this.clauses.push(statements_arr[i]);
- }
- return this;
-};
-
-AsterixExpression.prototype.use_dataverse = function(dv) {
- this.dataverse = dv;
- this.clauses.push("use dataverse " + dv + ";");
- return this;
-};
-
-AsterixExpression.prototype.return = function(return_object) {
- var components = [];
- for (var key in return_object) {
- components.push('"' + key + '" : ' + return_object[key]);
- }
-
- var return_expression = 'return { ' + components.join(', ') + ' }';
- this.clauses.push(return_expression);
- return this;
-};
-
-
-// Functions that can be used to call core expressions/clauses more cleanly
-function AFLWOGR () {
-
-}
-
-function AClause () {
-
-}
-
-function ALetClause () {
-
-}
-
-function AWhereClause () {
-
-}
-
-function AOrderbyClause () {
-
-}
-
-function AGroupClause () {
-
-}
-
-function ALimitClause () {
-
-}
-
-function ADistinctClause () {
-
-}
-
-function AVariable () {
-
-}
-
// Temporary AsterixExpression Placeholder
function AExpression () {
this._properties = {};
@@ -461,7 +293,7 @@
this._properties["clause"] += "}";
} else {
- this._properties["clause"] += new AsterixExpression().set([expression]).val();
+ this._properties["clause"] += new AExpression().set(expression).val();
}
return this;
@@ -718,3 +550,41 @@
var value = AExpression.prototype.val.call(this);
return "(" + value + ")";
};
+
+
+// Functions that can be used to call core expressions/clauses more cleanly
+function AFLWOGR () {
+
+}
+
+function AClause () {
+
+}
+
+function ALetClause () {
+
+}
+
+function AWhereClause () {
+
+}
+
+function AOrderbyClause () {
+
+}
+
+function AGroupClause () {
+
+}
+
+function ALimitClause () {
+
+}
+
+function ADistinctClause () {
+
+}
+
+function AVariable () {
+
+}