You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by sb...@apache.org on 2015/06/26 18:46:56 UTC

[1/7] incubator-ignite git commit: #ignite-964: Query "select * from String" works for nodejs.

Repository: incubator-ignite
Updated Branches:
  refs/heads/ignite-964 fb182ab17 -> ed7dd30ed


#ignite-964: Query "select * from String" works for nodejs.


Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/967ea548
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/967ea548
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/967ea548

Branch: refs/heads/ignite-964
Commit: 967ea5488fa8ff096a86f534fbb875fc434dba24
Parents: fb182ab
Author: ivasilinets <iv...@gridgain.com>
Authored: Fri Jun 26 16:39:00 2015 +0300
Committer: ivasilinets <iv...@gridgain.com>
Committed: Fri Jun 26 16:39:00 2015 +0300

----------------------------------------------------------------------
 .../processors/rest/GridRestProcessor.java      |  2 +
 .../handlers/query/QueryCommandHandler.java     | 13 +++-
 .../rest/request/RestSqlQueryRequest.java       | 40 +++++++++++-
 modules/nodejs/pom.xml                          |  6 ++
 modules/nodejs/src/main/js/apache-ignite.js     |  3 +-
 modules/nodejs/src/main/js/cache.js             | 22 +++++--
 modules/nodejs/src/main/js/compute.js           | 20 ++----
 modules/nodejs/src/main/js/server.js            | 64 +++++++++++--------
 modules/nodejs/src/main/js/sql-query.js         | 65 ++++++++++++++++++++
 .../ignite/internal/NodeJsAbstractTest.java     |  1 +
 .../apache/ignite/internal/NodeJsSqlQuery.java  | 47 ++++++++++++++
 modules/nodejs/src/test/js/test-query.js        | 53 ++++++++++++++++
 .../http/jetty/GridJettyRestHandler.java        |  4 +-
 13 files changed, 288 insertions(+), 52 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/967ea548/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/GridRestProcessor.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/GridRestProcessor.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/GridRestProcessor.java
index 5d886fc..bcc6496 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/GridRestProcessor.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/GridRestProcessor.java
@@ -24,6 +24,7 @@ import org.apache.ignite.internal.processors.*;
 import org.apache.ignite.internal.processors.rest.client.message.*;
 import org.apache.ignite.internal.processors.rest.handlers.*;
 import org.apache.ignite.internal.processors.rest.handlers.cache.*;
+import org.apache.ignite.internal.processors.rest.handlers.query.*;
 import org.apache.ignite.internal.processors.rest.handlers.scripting.*;
 import org.apache.ignite.internal.processors.rest.handlers.datastructures.*;
 import org.apache.ignite.internal.processors.rest.handlers.task.*;
@@ -290,6 +291,7 @@ public class GridRestProcessor extends GridProcessorAdapter {
             addHandler(new GridVersionCommandHandler(ctx));
             addHandler(new DataStructuresCommandHandler(ctx));
             addHandler(new IgniteScriptingCommandHandler(ctx));
+            addHandler(new QueryCommandHandler(ctx));
         }
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/967ea548/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/query/QueryCommandHandler.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/query/QueryCommandHandler.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/query/QueryCommandHandler.java
index 3f5c8bb..c866933 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/query/QueryCommandHandler.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/query/QueryCommandHandler.java
@@ -17,6 +17,8 @@
 
 package org.apache.ignite.internal.processors.rest.handlers.query;
 
+import org.apache.ignite.*;
+import org.apache.ignite.cache.query.*;
 import org.apache.ignite.internal.*;
 import org.apache.ignite.internal.processors.rest.*;
 import org.apache.ignite.internal.processors.rest.handlers.*;
@@ -25,6 +27,7 @@ import org.apache.ignite.internal.util.future.*;
 import org.apache.ignite.internal.util.typedef.internal.*;
 import org.apache.ignite.lang.*;
 
+import javax.cache.*;
 import java.util.*;
 
 import static org.apache.ignite.internal.processors.rest.GridRestCommand.*;
@@ -59,9 +62,15 @@ public class QueryCommandHandler extends GridRestCommandHandlerAdapter {
                 assert req instanceof RestSqlQueryRequest : "Invalid type of query request.";
 
                 return ctx.closure().callAsync(new IgniteClosure<RestSqlQueryRequest, GridRestResponse>() {
-                    @Override public GridRestResponse apply(RestSqlQueryRequest req) {
+                    @Override public GridRestResponse apply(RestSqlQueryRequest req0) {
                         try {
-                            return new GridRestResponse(); //TODO
+                            SqlQuery<String, String> qry = new SqlQuery(String.class, req0.sqlQuery());
+
+                            IgniteCache<Object, Object> cache = ctx.grid().cache(req0.cacheName());
+
+                            List<Cache.Entry<String, String>> res = cache.query(qry).getAll();
+
+                            return new GridRestResponse("Page size " + res);
                         }
                         catch (Exception e) {
                             return new GridRestResponse(GridRestResponse.STATUS_FAILED, e.getMessage());

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/967ea548/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/request/RestSqlQueryRequest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/request/RestSqlQueryRequest.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/request/RestSqlQueryRequest.java
index 4d74626..5731a03 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/request/RestSqlQueryRequest.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/request/RestSqlQueryRequest.java
@@ -25,7 +25,13 @@ public class RestSqlQueryRequest extends GridRestRequest {
     private String sqlQry;
 
     /** Sql query arguments. */
-    private Object[] args;
+    private Object args;
+
+    /** Page size. */
+    private Integer pageSz;
+
+    /** Cache name. */
+    private String cacheName;
 
     /**
      * @param sqlQry Sql query.
@@ -44,14 +50,42 @@ public class RestSqlQueryRequest extends GridRestRequest {
     /**
      * @param args Sql query arguments.
      */
-    public void arguments(Object[] args) {
+    public void arguments(Object args) {
         this.args = args;
     }
 
     /**
      * @return Sql query arguments.
      */
-    public Object[] arguments() {
+    public Object arguments() {
         return args;
     }
+
+    /**
+     * @param pageSz Page size.
+     */
+    public void pageSize(Integer pageSz) {
+        this.pageSz = pageSz;
+    }
+
+    /**
+     * @return Page size.
+     */
+    public int pageSize() {
+        return pageSz;
+    }
+
+    /**
+     * @param cacheName Cache name.
+     */
+    public void cacheName(String cacheName) {
+        this.cacheName = cacheName;
+    }
+
+    /**
+     * @return Cache name.
+     */
+    public String cacheName() {
+        return cacheName;
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/967ea548/modules/nodejs/pom.xml
----------------------------------------------------------------------
diff --git a/modules/nodejs/pom.xml b/modules/nodejs/pom.xml
index dcd3471..c9752b1 100644
--- a/modules/nodejs/pom.xml
+++ b/modules/nodejs/pom.xml
@@ -54,6 +54,12 @@
 
         <dependency>
             <groupId>org.apache.ignite</groupId>
+            <artifactId>ignite-indexing</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.ignite</groupId>
             <artifactId>ignite-rest-http</artifactId>
             <version>${project.version}</version>
         </dependency>

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/967ea548/modules/nodejs/src/main/js/apache-ignite.js
----------------------------------------------------------------------
diff --git a/modules/nodejs/src/main/js/apache-ignite.js b/modules/nodejs/src/main/js/apache-ignite.js
index e8252fc..c65c49d 100644
--- a/modules/nodejs/src/main/js/apache-ignite.js
+++ b/modules/nodejs/src/main/js/apache-ignite.js
@@ -20,5 +20,6 @@ module.exports = {
     Ignition : require('./ignition.js').Ignition,
     Server : require('./server.js').Server,
     Ignite : require('./ignite.js').Ignite,
-    Compute : require('./compute.js').Compute
+    Compute : require('./compute.js').Compute,
+    SqlQuery : require('./sql-query.js').SqlQuery
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/967ea548/modules/nodejs/src/main/js/cache.js
----------------------------------------------------------------------
diff --git a/modules/nodejs/src/main/js/cache.js b/modules/nodejs/src/main/js/cache.js
index 9333254..fcb3d49 100644
--- a/modules/nodejs/src/main/js/cache.js
+++ b/modules/nodejs/src/main/js/cache.js
@@ -131,12 +131,24 @@ Cache.prototype.getAll = function(keys, callback) {
 /**
  * Execute sql query
  *
- * @param {string} qry Query
- * @param {string[]} arg Arguments
- * @param {onGet} callback Callback.
+ * @param {SqlQuery} qry Query
  */
-Cache.prototype.query = function(qry, arg, callback) {
-    this._server.runCommand("sqlqry", [Server.pair("qry", qry), Server.pair("arg", arg)], callback);
+Cache.prototype.query = function(qry) {
+    function onQuery(qry, error, res) {
+        if (error) {
+            qry.error(error);
+
+            return;
+        }
+
+        qry.end(res);
+    }
+
+    this._server.runCommand("sqlqry", [
+        Server.pair("cacheName", this._cacheName),
+        Server.pair("qry", qry.query()),
+        Server.pair("arg", qry.arguments()),
+        Server.pair("psz", qry.pageSize())], onQuery.bind(null, qry));
 }
 
 /**

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/967ea548/modules/nodejs/src/main/js/compute.js
----------------------------------------------------------------------
diff --git a/modules/nodejs/src/main/js/compute.js b/modules/nodejs/src/main/js/compute.js
index 9aef39e..5789528 100644
--- a/modules/nodejs/src/main/js/compute.js
+++ b/modules/nodejs/src/main/js/compute.js
@@ -33,8 +33,8 @@ function Compute(server) {
  * @param {onGet} callback Callback
  */
 Compute.prototype.runScript = function(runnable, args, callback) {
-    this._server.runCommand("runscript", [Server.pair("func", this._escape(runnable)),
-        Server.pair("arg", this._escape(args))], callback);
+    this._server.runCommand("runscript", [Server.pair("func", runnable),
+        Server.pair("arg", args)], callback);
 }
 
 /**
@@ -47,24 +47,14 @@ Compute.prototype.runScript = function(runnable, args, callback) {
 Compute.prototype.execute = function(map, reduce, arg, callback) {
     var params = [];
 
-    params.push(Server.pair("map", this._escape(map)));
-    params.push(Server.pair("reduce", this._escape(reduce)));
-    params.push(Server.pair("arg", this._escape(arg)));
+    params.push(Server.pair("map", map));
+    params.push(Server.pair("reduce", reduce));
+    params.push(Server.pair("arg", arg));
 
     this._server.runCommand("excmapreduce", params, callback);
 }
 
 /**
- * @param {noValue} f Function
- * @returns {string} Encoding function
- */
-Compute.prototype._escape = function(f) {
-    var qs = require('querystring');
-
-    return qs.escape(f.toString());
-}
-
-/**
  * @name EmitFunction
  * @function
  * @param {function} func Remote job

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/967ea548/modules/nodejs/src/main/js/server.js
----------------------------------------------------------------------
diff --git a/modules/nodejs/src/main/js/server.js b/modules/nodejs/src/main/js/server.js
index 2bd0b4e..376e981 100644
--- a/modules/nodejs/src/main/js/server.js
+++ b/modules/nodejs/src/main/js/server.js
@@ -87,33 +87,37 @@ Server.prototype.runCommand = function(cmdName, params, callback) {
         });
 
         response.on('end', function () {
-        if (response.statusCode !== 200) {
-            if (response.statusCode === 401) {
-                callback.call(null, "Authentication failed. Status code 401.");
+            console.log("END " + response);
+            console.log("End status code " + response.statusCode);
+            console.log("Full response " + fullResponseString);
+
+            if (response.statusCode !== 200) {
+                if (response.statusCode === 401) {
+                    callback.call(null, "Authentication failed. Status code 401.");
+                }
+                else {
+                    callback.call(null, "Request failed. Status code " + response.statusCode);
+                }
+
+                return;
             }
-            else {
-                callback.call(null, "Request failed. Status code " + response.statusCode);
+
+            var igniteResponse;
+
+            try {
+                igniteResponse = JSON.parse(fullResponseString);
+            }
+            catch (e) {
+                callback.call(null, e, null);
+                return;
             }
 
-            return;
-        }
-
-        var igniteResponse;
-
-        try {
-            igniteResponse = JSON.parse(fullResponseString);
-        }
-        catch (e) {
-            callback.call(null, e, null);
-            return;
-        }
-
-        if (igniteResponse.successStatus) {
-            callback.call(null, igniteResponse.error, null)
-        }
-        else {
-            callback.call(null, null, igniteResponse.response);
-        }
+            if (igniteResponse.successStatus) {
+                callback.call(null, igniteResponse.error, null)
+            }
+            else {
+                callback.call(null, null, igniteResponse.response);
+            }
         });
     }
 
@@ -144,7 +148,7 @@ Server.prototype.checkConnection = function(callback) {
  * @returns Pair of strings
  */
 Server.pair = function(key, value) {
-    return {key: key, value: value}
+    return {key: Server._escape(key), value: Server._escape(value)}
 }
 
 /**
@@ -175,4 +179,14 @@ Server.prototype._signature = function() {
     return {"X-Signature" : key};
 }
 
+/**
+ * @param {noValue} f Function
+ * @returns {string} Encoding function
+ */
+Server._escape = function(f) {
+    var qs = require('querystring');
+
+    return qs.escape(f.toString());
+}
+
 exports.Server = Server;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/967ea548/modules/nodejs/src/main/js/sql-query.js
----------------------------------------------------------------------
diff --git a/modules/nodejs/src/main/js/sql-query.js b/modules/nodejs/src/main/js/sql-query.js
new file mode 100644
index 0000000..ea3b23b
--- /dev/null
+++ b/modules/nodejs/src/main/js/sql-query.js
@@ -0,0 +1,65 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * @this {SqlQuery}
+ * @param {string} Sql query
+ */
+function SqlQuery(sql) {
+    this._sql = sql;
+    this._arg = [];
+    this._pageSz = 0;
+    this._endFunc = function(res) {console.log("Empty end function is called [res=" + res + "]")};
+    this._errFunc = function(err) {console.log("Empty error function is called [err=" + err + "]")}
+}
+
+SqlQuery.prototype.on = function(code, f) {
+    switch(code) {
+        case "end":
+            this._endFunc = f;
+
+            break;
+        case "error" :
+            this._errFunc = f;
+
+            break;
+        default :
+            throw "Sql do not have method " + code;
+    }
+}
+
+SqlQuery.prototype.end = function(res) {
+    return this._endFunc(res);
+}
+
+SqlQuery.prototype.error = function(err) {
+    return this._errFunc(err);
+}
+
+SqlQuery.prototype.query = function() {
+    return this._sql;
+}
+
+SqlQuery.prototype.arguments = function() {
+    return this._arg;
+}
+
+SqlQuery.prototype.pageSize = function() {
+    return this._pageSz;
+}
+
+exports.SqlQuery = SqlQuery;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/967ea548/modules/nodejs/src/test/java/org/apache/ignite/internal/NodeJsAbstractTest.java
----------------------------------------------------------------------
diff --git a/modules/nodejs/src/test/java/org/apache/ignite/internal/NodeJsAbstractTest.java b/modules/nodejs/src/test/java/org/apache/ignite/internal/NodeJsAbstractTest.java
index 79ae908..47152e9 100644
--- a/modules/nodejs/src/test/java/org/apache/ignite/internal/NodeJsAbstractTest.java
+++ b/modules/nodejs/src/test/java/org/apache/ignite/internal/NodeJsAbstractTest.java
@@ -87,6 +87,7 @@ public class NodeJsAbstractTest extends GridCommonAbstractTest {
 
         ccfg.setName(CACHE_NAME);
         ccfg.setAtomicityMode(CacheAtomicityMode.ATOMIC);
+        ccfg.setIndexedTypes(String.class, String.class);
 
         return ccfg;
     }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/967ea548/modules/nodejs/src/test/java/org/apache/ignite/internal/NodeJsSqlQuery.java
----------------------------------------------------------------------
diff --git a/modules/nodejs/src/test/java/org/apache/ignite/internal/NodeJsSqlQuery.java b/modules/nodejs/src/test/java/org/apache/ignite/internal/NodeJsSqlQuery.java
new file mode 100644
index 0000000..54d6395
--- /dev/null
+++ b/modules/nodejs/src/test/java/org/apache/ignite/internal/NodeJsSqlQuery.java
@@ -0,0 +1,47 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal;
+
+/**
+ * Node js sql query test.
+ */
+public class NodeJsSqlQuery  extends NodeJsAbstractTest {
+    /**
+     * Constructor.
+     */
+    public NodeJsSqlQuery() {
+        super("test-query.js");
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void beforeTestsStarted() throws Exception {
+        startGrid(0);
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTestsStopped() throws Exception {
+        stopAllGrids();
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testSqlQuery() throws Exception {
+        runJsScript("testSqlQuery");
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/967ea548/modules/nodejs/src/test/js/test-query.js
----------------------------------------------------------------------
diff --git a/modules/nodejs/src/test/js/test-query.js b/modules/nodejs/src/test/js/test-query.js
new file mode 100644
index 0000000..cb861fc
--- /dev/null
+++ b/modules/nodejs/src/test/js/test-query.js
@@ -0,0 +1,53 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+var TestUtils = require("./test-utils").TestUtils;
+
+var assert = require("assert");
+
+var Ignite = require(TestUtils.scriptPath());
+var SqlQuery = Ignite.SqlQuery;
+
+testSqlQuery = function() {
+    function sqlQuery(ignite, error) {
+        assert(error == null, "error on sql query [err=" + error + "]");
+
+        var qry = new SqlQuery("select * from String");
+
+        qry.on("error", function(err) {
+                console.log("!!!!!!!!!!!!Error: " + err);
+
+                TestUtils.testFails();
+            });
+
+        qry.on("end", function(res) {
+                console.log("!!!!!!!!!!!Result: " + res);
+
+                TestUtils.testDone();
+            });
+
+        ignite.cache("mycache").query(qry);
+    }
+
+    function put(error, ignite) {
+        assert(error == null, "error on put [err=" + error + "]");
+
+        ignite.cache("mycache").put("key", "val", sqlQuery.bind(null, ignite))
+    }
+
+    TestUtils.startIgniteNode(put);
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/967ea548/modules/rest-http/src/main/java/org/apache/ignite/internal/processors/rest/protocols/http/jetty/GridJettyRestHandler.java
----------------------------------------------------------------------
diff --git a/modules/rest-http/src/main/java/org/apache/ignite/internal/processors/rest/protocols/http/jetty/GridJettyRestHandler.java b/modules/rest-http/src/main/java/org/apache/ignite/internal/processors/rest/protocols/http/jetty/GridJettyRestHandler.java
index 65eaa3c..c188439 100644
--- a/modules/rest-http/src/main/java/org/apache/ignite/internal/processors/rest/protocols/http/jetty/GridJettyRestHandler.java
+++ b/modules/rest-http/src/main/java/org/apache/ignite/internal/processors/rest/protocols/http/jetty/GridJettyRestHandler.java
@@ -475,7 +475,9 @@ public class GridJettyRestHandler extends AbstractHandler {
                 RestSqlQueryRequest restReq0 = new RestSqlQueryRequest();
 
                 restReq0.sqlQuery((String)params.get("qry"));
-                restReq0.arguments((Object[]) params.get("arg"));
+                restReq0.arguments(params.get("arg"));
+                restReq0.pageSize(Integer.parseInt((String) params.get("psz")));
+                restReq0.cacheName((String)params.get("cacheName"));
 
                 restReq = restReq0;
 


[4/7] incubator-ignite git commit: #ignite-961: fix handleAsync in IgniteScriptingCommandHandler.

Posted by sb...@apache.org.
#ignite-961: fix handleAsync in IgniteScriptingCommandHandler.


Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/8379cd75
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/8379cd75
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/8379cd75

Branch: refs/heads/ignite-964
Commit: 8379cd755aebf3aee98a2a9cf74e4fdca0829eaa
Parents: 04459d2
Author: ivasilinets <iv...@gridgain.com>
Authored: Fri Jun 26 18:19:07 2015 +0300
Committer: ivasilinets <iv...@gridgain.com>
Committed: Fri Jun 26 18:19:07 2015 +0300

----------------------------------------------------------------------
 .../IgniteScriptingCommandHandler.java          | 97 +++++++++++++++-----
 1 file changed, 72 insertions(+), 25 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/8379cd75/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/scripting/IgniteScriptingCommandHandler.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/scripting/IgniteScriptingCommandHandler.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/scripting/IgniteScriptingCommandHandler.java
index 98ca7b1..2d65016 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/scripting/IgniteScriptingCommandHandler.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/scripting/IgniteScriptingCommandHandler.java
@@ -33,6 +33,7 @@ import org.apache.ignite.resources.*;
 import org.jetbrains.annotations.*;
 
 import java.util.*;
+import java.util.concurrent.*;
 
 import static org.apache.ignite.internal.processors.rest.GridRestCommand.*;
 
@@ -86,37 +87,15 @@ public class IgniteScriptingCommandHandler extends GridRestCommandHandlerAdapter
             case RUN_SCRIPT: {
                 assert req instanceof RestRunScriptRequest : "Invalid type of run script request.";
 
-                return ctx.closure().callAsync(new IgniteClosure<RestRunScriptRequest, GridRestResponse>() {
-                    @Override public GridRestResponse apply(RestRunScriptRequest req) {
-                        try {
-                            return new GridRestResponse(ctx.grid().compute().call(
-                                new JsFunctionCallable(req.script(), req.argument())));
-                        }
-                        catch (Exception e) {
-                            return new GridRestResponse(GridRestResponse.STATUS_FAILED, e.getMessage());
-                        }
-                    }
-                }, (RestRunScriptRequest)req, Collections.singleton(ctx.grid().localNode()));
+                return ctx.closure().callLocalSafe(new RunScriptCallable(ctx, (RestRunScriptRequest) req), false);
             }
 
             case EXECUTE_MAP_REDUCE_SCRIPT: {
                 assert req instanceof RestMapReduceScriptRequest :
                     "Invalid type of execute map reduce script request.";
 
-                assert SUPPORTED_COMMANDS.contains(req.command());
-
-                return ctx.closure().callAsync(new IgniteClosure<RestMapReduceScriptRequest, GridRestResponse>() {
-                    @Override public GridRestResponse apply(RestMapReduceScriptRequest req0) {
-                        try {
-                            return new GridRestResponse(ctx.grid().compute().execute(
-                                new JsTask(req0.mapFunction(), req0.argument(), req0.reduceFunction(), ctx, emitRes),
-                                null));
-                        }
-                        catch (Exception e) {
-                            return new GridRestResponse(GridRestResponse.STATUS_FAILED, e.getMessage());
-                        }
-                }
-                }, (RestMapReduceScriptRequest)req, Collections.singleton(ctx.grid().localNode()));
+                return ctx.closure().callLocalSafe(
+                    new MapReduceCallable(ctx, (RestMapReduceScriptRequest)req, emitRes));
             }
         }
 
@@ -276,4 +255,72 @@ public class IgniteScriptingCommandHandler extends GridRestCommandHandlerAdapter
             }
         }
     }
+
+    /**
+     * Run script callable.
+     */
+    private static class RunScriptCallable implements Callable<GridRestResponse> {
+        /** Kernal context. */
+        private GridKernalContext ctx;
+
+        /** Run script request. */
+        private RestRunScriptRequest req;
+
+        /**
+         * @param ctx Kernal context.
+         * @param req Run script request.
+         */
+        public RunScriptCallable(GridKernalContext ctx, RestRunScriptRequest req) {
+            this.ctx = ctx;
+            this.req = req;
+        }
+
+        /** {@inheritDoc} */
+        @Override public GridRestResponse call() throws Exception {
+            try {
+                return new GridRestResponse(ctx.grid().compute().call(
+                    new JsFunctionCallable(req.script(), req.argument())));
+            }
+            catch (Exception e) {
+                return new GridRestResponse(GridRestResponse.STATUS_FAILED, e.getMessage());
+            }
+        }
+    }
+
+    /**
+     * Map reduce callable.
+     */
+    private static class MapReduceCallable implements Callable<GridRestResponse> {
+        /** Kernal context. */
+        private GridKernalContext ctx;
+
+        /** Run script request. */
+        private RestMapReduceScriptRequest req;
+
+        /** Emit results. */
+        IgniteJsEmitResult emitRes;
+
+        /**
+         * @param ctx Kernal context.
+         * @param req Run script request.
+         * @param emitRes Emit function results.
+         */
+        public MapReduceCallable(GridKernalContext ctx, RestMapReduceScriptRequest req,IgniteJsEmitResult emitRes) {
+            this.ctx = ctx;
+            this.req = req;
+            this.emitRes = emitRes;
+        }
+
+        /** {@inheritDoc} */
+        @Override public GridRestResponse call() throws Exception {
+            try {
+                return new GridRestResponse(ctx.grid().compute().execute(
+                    new JsTask(req.mapFunction(), req.argument(), req.reduceFunction(), ctx, emitRes),
+                    null));
+            }
+            catch (Exception e) {
+                return new GridRestResponse(GridRestResponse.STATUS_FAILED, e.getMessage());
+            }
+        }
+    }
 }


[3/7] incubator-ignite git commit: #ignite-964: Add CacheQueryResult.

Posted by sb...@apache.org.
#ignite-964: Add CacheQueryResult.


Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/1e61b51f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/1e61b51f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/1e61b51f

Branch: refs/heads/ignite-964
Commit: 1e61b51f6dbde16b12080e241deba49bd2070dc6
Parents: 10d3229
Author: ivasilinets <iv...@gridgain.com>
Authored: Fri Jun 26 18:00:33 2015 +0300
Committer: ivasilinets <iv...@gridgain.com>
Committed: Fri Jun 26 18:00:33 2015 +0300

----------------------------------------------------------------------
 .../processors/rest/GridRestCommand.java        |   5 +-
 .../rest/handlers/query/CacheQueryResult.java   | 115 +++++++++++++++++++
 modules/nodejs/src/main/js/cache.js             |   2 +-
 3 files changed, 120 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/1e61b51f/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/GridRestCommand.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/GridRestCommand.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/GridRestCommand.java
index dcc1699..3893eea 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/GridRestCommand.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/GridRestCommand.java
@@ -106,7 +106,10 @@ public enum GridRestCommand {
     EXECUTE_MAP_REDUCE_SCRIPT("excmapreduce"),
 
     /** Execute sql query. */
-    EXECUTE_SQL_QUERY("sqlqry");
+    EXECUTE_SQL_QUERY("qryexecute"),
+
+    /** Fetch query results. */
+    FETCH_SQL_QUERY("qryfetch");
 
     /** Enum values. */
     private static final GridRestCommand[] VALS = values();

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/1e61b51f/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/query/CacheQueryResult.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/query/CacheQueryResult.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/query/CacheQueryResult.java
new file mode 100644
index 0000000..ede8a45
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/query/CacheQueryResult.java
@@ -0,0 +1,115 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.rest.handlers.query;
+
+import org.apache.ignite.internal.util.typedef.internal.*;
+
+import java.io.*;
+import java.util.*;
+
+/**
+ * Client query result.
+ */
+public class CacheQueryResult implements Externalizable {
+    /** */
+    private static final long serialVersionUID = 0L;
+
+    /** Query ID. */
+    private long qryId;
+
+    /** Result items. */
+    private Collection<?> items;
+
+    /** Last flag. */
+    private boolean last;
+
+    /** Node ID. */
+    private UUID nodeId;
+
+    /**
+     * @return Query ID.
+     */
+    public long queryId() {
+        return qryId;
+    }
+
+    /**
+     * @param qryId Query ID.
+     */
+    public void queryId(long qryId) {
+        this.qryId = qryId;
+    }
+
+    /**
+     * @return Items.
+     */
+    public Collection<?> items() {
+        return items;
+    }
+
+    /**
+     * @param items Items.
+     */
+    public void items(Collection<?> items) {
+        this.items = items;
+    }
+
+    /**
+     * @return Last flag.
+     */
+    public boolean last() {
+        return last;
+    }
+
+    /**
+     * @param last Last flag.
+     */
+    public void last(boolean last) {
+        this.last = last;
+    }
+
+    /**
+     * @return Node ID.
+     */
+    public UUID nodeId() {
+        return nodeId;
+    }
+
+    /**
+     * @param nodeId Node ID.
+     */
+    public void nodeId(UUID nodeId) {
+        this.nodeId = nodeId;
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeExternal(ObjectOutput out) throws IOException {
+        out.writeBoolean(last);
+        out.writeLong(qryId);
+        U.writeUuid(out, nodeId);
+        U.writeCollection(out, items);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
+        last = in.readBoolean();
+        qryId = in.readLong();
+        nodeId = U.readUuid(in);
+        items = U.readCollection(in);
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/1e61b51f/modules/nodejs/src/main/js/cache.js
----------------------------------------------------------------------
diff --git a/modules/nodejs/src/main/js/cache.js b/modules/nodejs/src/main/js/cache.js
index fcb3d49..cdbd6d4 100644
--- a/modules/nodejs/src/main/js/cache.js
+++ b/modules/nodejs/src/main/js/cache.js
@@ -144,7 +144,7 @@ Cache.prototype.query = function(qry) {
         qry.end(res);
     }
 
-    this._server.runCommand("sqlqry", [
+    this._server.runCommand("qryexecute", [
         Server.pair("cacheName", this._cacheName),
         Server.pair("qry", qry.query()),
         Server.pair("arg", qry.arguments()),


[6/7] incubator-ignite git commit: #ignite-961: fix handleAsync in QueryCommandHandler.

Posted by sb...@apache.org.
#ignite-961: fix handleAsync in QueryCommandHandler.


Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/1d03ca2d
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/1d03ca2d
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/1d03ca2d

Branch: refs/heads/ignite-964
Commit: 1d03ca2d5b5b0dc037c71c4634c42b73b668220a
Parents: de711c7
Author: ivasilinets <iv...@gridgain.com>
Authored: Fri Jun 26 18:23:26 2015 +0300
Committer: ivasilinets <iv...@gridgain.com>
Committed: Fri Jun 26 18:23:26 2015 +0300

----------------------------------------------------------------------
 .../handlers/query/QueryCommandHandler.java     | 53 ++++++++++++++------
 1 file changed, 37 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/1d03ca2d/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/query/QueryCommandHandler.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/query/QueryCommandHandler.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/query/QueryCommandHandler.java
index 6d2a2b7..f31e246 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/query/QueryCommandHandler.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/query/QueryCommandHandler.java
@@ -25,10 +25,10 @@ import org.apache.ignite.internal.processors.rest.handlers.*;
 import org.apache.ignite.internal.processors.rest.request.*;
 import org.apache.ignite.internal.util.future.*;
 import org.apache.ignite.internal.util.typedef.internal.*;
-import org.apache.ignite.lang.*;
 
 import javax.cache.*;
 import java.util.*;
+import java.util.concurrent.*;
 
 import static org.apache.ignite.internal.processors.rest.GridRestCommand.*;
 
@@ -61,25 +61,46 @@ public class QueryCommandHandler extends GridRestCommandHandlerAdapter {
             case EXECUTE_SQL_QUERY: {
                 assert req instanceof RestSqlQueryRequest : "Invalid type of query request.";
 
-                return ctx.closure().callAsync(new IgniteClosure<RestSqlQueryRequest, GridRestResponse>() {
-                    @Override public GridRestResponse apply(RestSqlQueryRequest req0) {
-                        try {
-                            SqlQuery<String, String> qry = new SqlQuery(String.class, req0.sqlQuery());
+                return ctx.closure().callLocalSafe(new ExecuteQueryCallable(ctx, (RestSqlQueryRequest)req),false);
+            }
+        }
+
+        return new GridFinishedFuture<>();
+    }
 
-                            IgniteCache<Object, Object> cache = ctx.grid().cache(req0.cacheName());
+    /**
+     * Execute query callable.
+     */
+    private static class ExecuteQueryCallable implements Callable<GridRestResponse> {
+        /** Kernal context. */
+        private GridKernalContext ctx;
 
-                            List<Cache.Entry<String, String>> res = cache.query(qry).getAll();
+        /** Execute query request. */
+        private RestSqlQueryRequest req;
 
-                            return new GridRestResponse(res);
-                        }
-                        catch (Exception e) {
-                            return new GridRestResponse(GridRestResponse.STATUS_FAILED, e.getMessage());
-                        }
-                    }
-                }, (RestSqlQueryRequest)req, Collections.singleton(ctx.grid().localNode()));
-            }
+        /**
+         * @param ctx Kernal context.
+         * @param req Execute query request.
+         */
+        public ExecuteQueryCallable(GridKernalContext ctx, RestSqlQueryRequest req) {
+            this.ctx = ctx;
+            this.req = req;
         }
 
-        return new GridFinishedFuture<>();
+        /** {@inheritDoc} */
+        @Override public GridRestResponse call() throws Exception {
+            try {
+                SqlQuery<String, String> qry = new SqlQuery(String.class, req.sqlQuery());
+
+                IgniteCache<Object, Object> cache = ctx.grid().cache(req.cacheName());
+
+                List<Cache.Entry<String, String>> res = cache.query(qry).getAll();
+
+                return new GridRestResponse(res);
+            }
+            catch (Exception e) {
+                return new GridRestResponse(GridRestResponse.STATUS_FAILED, e.getMessage());
+            }
+        }
     }
 }


[5/7] incubator-ignite git commit: Merge branch 'ignite-961' into ignite-964

Posted by sb...@apache.org.
Merge branch 'ignite-961' into ignite-964


Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/de711c7f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/de711c7f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/de711c7f

Branch: refs/heads/ignite-964
Commit: de711c7fcc2ee372e1c0d8601b810eaadf209aa1
Parents: 1e61b51 8379cd7
Author: ivasilinets <iv...@gridgain.com>
Authored: Fri Jun 26 18:20:01 2015 +0300
Committer: ivasilinets <iv...@gridgain.com>
Committed: Fri Jun 26 18:20:01 2015 +0300

----------------------------------------------------------------------
 .../IgniteScriptingCommandHandler.java          | 97 +++++++++++++++-----
 1 file changed, 72 insertions(+), 25 deletions(-)
----------------------------------------------------------------------



[2/7] incubator-ignite git commit: #ignite-964: Fix test for cache query nodejs.

Posted by sb...@apache.org.
#ignite-964: Fix test for cache query nodejs.


Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/10d3229e
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/10d3229e
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/10d3229e

Branch: refs/heads/ignite-964
Commit: 10d3229e51fa9db9316a5bf78f465efe3d435696
Parents: 967ea54
Author: ivasilinets <iv...@gridgain.com>
Authored: Fri Jun 26 16:46:36 2015 +0300
Committer: ivasilinets <iv...@gridgain.com>
Committed: Fri Jun 26 16:46:36 2015 +0300

----------------------------------------------------------------------
 .../rest/handlers/query/QueryCommandHandler.java         |  2 +-
 modules/nodejs/src/test/js/test-query.js                 | 11 +++++++++--
 2 files changed, 10 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/10d3229e/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/query/QueryCommandHandler.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/query/QueryCommandHandler.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/query/QueryCommandHandler.java
index c866933..6d2a2b7 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/query/QueryCommandHandler.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/query/QueryCommandHandler.java
@@ -70,7 +70,7 @@ public class QueryCommandHandler extends GridRestCommandHandlerAdapter {
 
                             List<Cache.Entry<String, String>> res = cache.query(qry).getAll();
 
-                            return new GridRestResponse("Page size " + res);
+                            return new GridRestResponse(res);
                         }
                         catch (Exception e) {
                             return new GridRestResponse(GridRestResponse.STATUS_FAILED, e.getMessage());

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/10d3229e/modules/nodejs/src/test/js/test-query.js
----------------------------------------------------------------------
diff --git a/modules/nodejs/src/test/js/test-query.js b/modules/nodejs/src/test/js/test-query.js
index cb861fc..a09c5da 100644
--- a/modules/nodejs/src/test/js/test-query.js
+++ b/modules/nodejs/src/test/js/test-query.js
@@ -35,7 +35,14 @@ testSqlQuery = function() {
             });
 
         qry.on("end", function(res) {
-                console.log("!!!!!!!!!!!Result: " + res);
+                assert(res.length, 1, "Result length is not correct" +
+                    "[expected=1, val = " + res.length + "]");
+
+                assert(res[0]["key"] === "key0", "Result value for key is not correct "+
+                    "[expected=key0, real=" + res[0]["key"] + "]");
+
+                assert(res[0]["value"] === "val0", "Result value for key is not correct "+
+                    "[expected=val0, real=" + res[0]["value"] + "]");
 
                 TestUtils.testDone();
             });
@@ -46,7 +53,7 @@ testSqlQuery = function() {
     function put(error, ignite) {
         assert(error == null, "error on put [err=" + error + "]");
 
-        ignite.cache("mycache").put("key", "val", sqlQuery.bind(null, ignite))
+        ignite.cache("mycache").put("key0", "val0", sqlQuery.bind(null, ignite))
     }
 
     TestUtils.startIgniteNode(put);


[7/7] incubator-ignite git commit: #ignite-964: simple query works with pages.

Posted by sb...@apache.org.
#ignite-964: simple query works with pages.


Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/ed7dd30e
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/ed7dd30e
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/ed7dd30e

Branch: refs/heads/ignite-964
Commit: ed7dd30ed613657e0d2576260aeebdf5c181e7a2
Parents: 1d03ca2
Author: ivasilinets <iv...@gridgain.com>
Authored: Fri Jun 26 19:46:37 2015 +0300
Committer: ivasilinets <iv...@gridgain.com>
Committed: Fri Jun 26 19:46:37 2015 +0300

----------------------------------------------------------------------
 .../rest/handlers/query/CacheQueryResult.java   |  32 ++---
 .../handlers/query/QueryCommandHandler.java     | 117 +++++++++++++++++--
 .../IgniteScriptingCommandHandler.java          |   6 +
 .../rest/request/RestSqlQueryRequest.java       |  17 +++
 modules/nodejs/src/main/js/cache.js             |  18 ++-
 modules/nodejs/src/main/js/sql-query.js         |  11 +-
 modules/nodejs/src/test/js/test-query.js        |  22 ++--
 .../http/jetty/GridJettyRestHandler.java        |  12 ++
 8 files changed, 192 insertions(+), 43 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/ed7dd30e/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/query/CacheQueryResult.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/query/CacheQueryResult.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/query/CacheQueryResult.java
index ede8a45..3e49576 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/query/CacheQueryResult.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/query/CacheQueryResult.java
@@ -38,70 +38,57 @@ public class CacheQueryResult implements Externalizable {
     /** Last flag. */
     private boolean last;
 
-    /** Node ID. */
-    private UUID nodeId;
-
     /**
      * @return Query ID.
      */
-    public long queryId() {
+    public long getQueryId() {
         return qryId;
     }
 
     /**
      * @param qryId Query ID.
      */
-    public void queryId(long qryId) {
+    public void setQueryId(long qryId) {
         this.qryId = qryId;
     }
 
     /**
      * @return Items.
      */
-    public Collection<?> items() {
+    public Collection<?> getItems() {
         return items;
     }
 
     /**
      * @param items Items.
      */
-    public void items(Collection<?> items) {
+    public void setItems(Collection<?> items) {
         this.items = items;
     }
 
     /**
      * @return Last flag.
      */
-    public boolean last() {
+    public boolean getLast() {
         return last;
     }
 
     /**
      * @param last Last flag.
      */
-    public void last(boolean last) {
+    public void setLast(boolean last) {
         this.last = last;
     }
 
-    /**
-     * @return Node ID.
-     */
-    public UUID nodeId() {
-        return nodeId;
-    }
-
-    /**
-     * @param nodeId Node ID.
-     */
-    public void nodeId(UUID nodeId) {
-        this.nodeId = nodeId;
+    /** {@inheritDoc} */
+    @Override public String toString() {
+        return S.toString(CacheQueryResult.class, this);
     }
 
     /** {@inheritDoc} */
     @Override public void writeExternal(ObjectOutput out) throws IOException {
         out.writeBoolean(last);
         out.writeLong(qryId);
-        U.writeUuid(out, nodeId);
         U.writeCollection(out, items);
     }
 
@@ -109,7 +96,6 @@ public class CacheQueryResult implements Externalizable {
     @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
         last = in.readBoolean();
         qryId = in.readLong();
-        nodeId = U.readUuid(in);
         items = U.readCollection(in);
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/ed7dd30e/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/query/QueryCommandHandler.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/query/QueryCommandHandler.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/query/QueryCommandHandler.java
index f31e246..82f3726 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/query/QueryCommandHandler.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/query/QueryCommandHandler.java
@@ -17,7 +17,6 @@
 
 package org.apache.ignite.internal.processors.rest.handlers.query;
 
-import org.apache.ignite.*;
 import org.apache.ignite.cache.query.*;
 import org.apache.ignite.internal.*;
 import org.apache.ignite.internal.processors.rest.*;
@@ -29,6 +28,7 @@ import org.apache.ignite.internal.util.typedef.internal.*;
 import javax.cache.*;
 import java.util.*;
 import java.util.concurrent.*;
+import java.util.concurrent.atomic.*;
 
 import static org.apache.ignite.internal.processors.rest.GridRestCommand.*;
 
@@ -37,7 +37,15 @@ import static org.apache.ignite.internal.processors.rest.GridRestCommand.*;
  */
 public class QueryCommandHandler extends GridRestCommandHandlerAdapter {
     /** Supported commands. */
-    private static final Collection<GridRestCommand> SUPPORTED_COMMANDS = U.sealList(EXECUTE_SQL_QUERY);
+    private static final Collection<GridRestCommand> SUPPORTED_COMMANDS = U.sealList(EXECUTE_SQL_QUERY,
+        FETCH_SQL_QUERY);
+
+    /** Query ID sequence. */
+    private static final AtomicLong qryIdGen = new AtomicLong();
+
+    /** Current queries. */
+    private final ConcurrentHashMap<Long, Iterator<Cache.Entry<String, String>>> curs =
+        new ConcurrentHashMap<>();
 
     /**
      * @param ctx Context.
@@ -61,7 +69,15 @@ public class QueryCommandHandler extends GridRestCommandHandlerAdapter {
             case EXECUTE_SQL_QUERY: {
                 assert req instanceof RestSqlQueryRequest : "Invalid type of query request.";
 
-                return ctx.closure().callLocalSafe(new ExecuteQueryCallable(ctx, (RestSqlQueryRequest)req),false);
+                return ctx.closure().callLocalSafe(
+                    new ExecuteQueryCallable(ctx, (RestSqlQueryRequest)req, curs), false);
+            }
+
+            case FETCH_SQL_QUERY: {
+                assert req instanceof RestSqlQueryRequest : "Invalid type of query request.";
+
+                return ctx.closure().callLocalSafe(
+                    new FetchQueryCallable(ctx, (RestSqlQueryRequest)req, curs), false);
             }
         }
 
@@ -72,19 +88,27 @@ public class QueryCommandHandler extends GridRestCommandHandlerAdapter {
      * Execute query callable.
      */
     private static class ExecuteQueryCallable implements Callable<GridRestResponse> {
+        /** */
+        private static final long serialVersionUID = 0L;
+
         /** Kernal context. */
         private GridKernalContext ctx;
 
         /** Execute query request. */
         private RestSqlQueryRequest req;
 
+        /** Queries cursors. */
+        private ConcurrentHashMap<Long, Iterator<Cache.Entry<String, String>>> curs;
+
         /**
          * @param ctx Kernal context.
          * @param req Execute query request.
          */
-        public ExecuteQueryCallable(GridKernalContext ctx, RestSqlQueryRequest req) {
+        public ExecuteQueryCallable(GridKernalContext ctx, RestSqlQueryRequest req,
+            ConcurrentHashMap<Long, Iterator<Cache.Entry<String, String>>> curs) {
             this.ctx = ctx;
             this.req = req;
+            this.curs = curs;
         }
 
         /** {@inheritDoc} */
@@ -92,11 +116,90 @@ public class QueryCommandHandler extends GridRestCommandHandlerAdapter {
             try {
                 SqlQuery<String, String> qry = new SqlQuery(String.class, req.sqlQuery());
 
-                IgniteCache<Object, Object> cache = ctx.grid().cache(req.cacheName());
+                Iterator<Cache.Entry<String, String>> cur =
+                    ctx.grid().cache(req.cacheName()).query(qry).iterator();
+
+                long qryId = qryIdGen.getAndIncrement();
+
+                curs.put(qryId, cur);
+
+                List<Cache.Entry<String, String>> res = new ArrayList<>();
+
+                CacheQueryResult response = new CacheQueryResult();
+
+                for (int i = 0; i < req.pageSize() && cur.hasNext(); ++i)
+                    res.add(cur.next());
+
+                response.setItems(res);
+
+                response.setLast(!cur.hasNext());
+
+                response.setQueryId(qryId);
+
+                if (!cur.hasNext())
+                    curs.remove(qryId);
+
+                return new GridRestResponse(response);
+            }
+            catch (Exception e) {
+                return new GridRestResponse(GridRestResponse.STATUS_FAILED, e.getMessage());
+            }
+        }
+    }
+
+    /**
+     * Fetch query callable.
+     */
+    private static class FetchQueryCallable implements Callable<GridRestResponse> {
+        /** */
+        private static final long serialVersionUID = 0L;
+
+        /** Kernal context. */
+        private GridKernalContext ctx;
+
+        /** Execute query request. */
+        private RestSqlQueryRequest req;
+
+        /** Queries cursors. */
+        private ConcurrentHashMap<Long, Iterator<Cache.Entry<String, String>>> curs;
+
+        /**
+         * @param ctx Kernal context.
+         * @param req Execute query request.
+         */
+        public FetchQueryCallable(GridKernalContext ctx, RestSqlQueryRequest req,
+            ConcurrentHashMap<Long, Iterator<Cache.Entry<String, String>>> curs) {
+            this.ctx = ctx;
+            this.req = req;
+            this.curs = curs;
+        }
+
+        /** {@inheritDoc} */
+        @Override public GridRestResponse call() throws Exception {
+            try {
+                if (curs.contains(req.queryId()))
+                    return new GridRestResponse(GridRestResponse.STATUS_FAILED,
+                        "Cannot find query [qryId=" + req.queryId() + "]");
+
+                Iterator<Cache.Entry<String, String>> cur = curs.get(req.queryId());
+
+                List<Cache.Entry<String, String>> res = new ArrayList<>();
+
+                CacheQueryResult response = new CacheQueryResult();
+
+                for (int i = 0; i < req.pageSize() && cur.hasNext(); ++i)
+                    res.add(cur.next());
+
+                response.setItems(res);
+
+                response.setLast(!cur.hasNext());
+
+                response.setQueryId(req.queryId());
 
-                List<Cache.Entry<String, String>> res = cache.query(qry).getAll();
+                if (!cur.hasNext())
+                    curs.remove(req.queryId());
 
-                return new GridRestResponse(res);
+                return new GridRestResponse(response);
             }
             catch (Exception e) {
                 return new GridRestResponse(GridRestResponse.STATUS_FAILED, e.getMessage());

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/ed7dd30e/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/scripting/IgniteScriptingCommandHandler.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/scripting/IgniteScriptingCommandHandler.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/scripting/IgniteScriptingCommandHandler.java
index 2d65016..d7525a0 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/scripting/IgniteScriptingCommandHandler.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/scripting/IgniteScriptingCommandHandler.java
@@ -260,6 +260,9 @@ public class IgniteScriptingCommandHandler extends GridRestCommandHandlerAdapter
      * Run script callable.
      */
     private static class RunScriptCallable implements Callable<GridRestResponse> {
+        /** */
+        private static final long serialVersionUID = 0L;
+
         /** Kernal context. */
         private GridKernalContext ctx;
 
@@ -291,6 +294,9 @@ public class IgniteScriptingCommandHandler extends GridRestCommandHandlerAdapter
      * Map reduce callable.
      */
     private static class MapReduceCallable implements Callable<GridRestResponse> {
+        /** */
+        private static final long serialVersionUID = 0L;
+
         /** Kernal context. */
         private GridKernalContext ctx;
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/ed7dd30e/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/request/RestSqlQueryRequest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/request/RestSqlQueryRequest.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/request/RestSqlQueryRequest.java
index 5731a03..3a0005c 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/request/RestSqlQueryRequest.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/request/RestSqlQueryRequest.java
@@ -33,6 +33,9 @@ public class RestSqlQueryRequest extends GridRestRequest {
     /** Cache name. */
     private String cacheName;
 
+    /** Query id. */
+    private Long qryId;
+
     /**
      * @param sqlQry Sql query.
      */
@@ -88,4 +91,18 @@ public class RestSqlQueryRequest extends GridRestRequest {
     public String cacheName() {
         return cacheName;
     }
+
+    /**
+     * @param id Query id.
+     */
+    public void queryId(Long id) {
+        this.qryId = id;
+    }
+
+    /**
+     * @return Query id.
+     */
+    public Long queryId() {
+        return qryId;
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/ed7dd30e/modules/nodejs/src/main/js/cache.js
----------------------------------------------------------------------
diff --git a/modules/nodejs/src/main/js/cache.js b/modules/nodejs/src/main/js/cache.js
index cdbd6d4..56a2def 100644
--- a/modules/nodejs/src/main/js/cache.js
+++ b/modules/nodejs/src/main/js/cache.js
@@ -134,21 +134,33 @@ Cache.prototype.getAll = function(keys, callback) {
  * @param {SqlQuery} qry Query
  */
 Cache.prototype.query = function(qry) {
-    function onQuery(qry, error, res) {
+    function onQueryExecute(qry, error, res) {
         if (error) {
             qry.error(error);
 
             return;
         }
 
-        qry.end(res);
+        qry.page(res["items"]);
+
+        if (res["last"]) {
+            qry.end();
+        }
+        else {
+            this._server.runCommand("qryfetch", [
+                Server.pair("cacheName", this._cacheName),
+                Server.pair("qryId", res.queryId),
+                Server.pair("psz", qry.pageSize())],
+                onQueryExecute.bind(this, qry, res["queryId"]));
+        }
     }
 
     this._server.runCommand("qryexecute", [
         Server.pair("cacheName", this._cacheName),
         Server.pair("qry", qry.query()),
         Server.pair("arg", qry.arguments()),
-        Server.pair("psz", qry.pageSize())], onQuery.bind(null, qry));
+        Server.pair("psz", qry.pageSize())],
+        onQueryExecute.bind(this, qry));
 }
 
 /**

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/ed7dd30e/modules/nodejs/src/main/js/sql-query.js
----------------------------------------------------------------------
diff --git a/modules/nodejs/src/main/js/sql-query.js b/modules/nodejs/src/main/js/sql-query.js
index ea3b23b..ba554a3 100644
--- a/modules/nodejs/src/main/js/sql-query.js
+++ b/modules/nodejs/src/main/js/sql-query.js
@@ -22,8 +22,9 @@
 function SqlQuery(sql) {
     this._sql = sql;
     this._arg = [];
-    this._pageSz = 0;
+    this._pageSz = 1;
     this._endFunc = function(res) {console.log("Empty end function is called [res=" + res + "]")};
+    this._pageFunc = function(res) {console.log("Empty page function is called [res=" + res + "]")}
     this._errFunc = function(err) {console.log("Empty error function is called [err=" + err + "]")}
 }
 
@@ -33,6 +34,10 @@ SqlQuery.prototype.on = function(code, f) {
             this._endFunc = f;
 
             break;
+        case "page":
+            this._pageFunc = f;
+
+            break;
         case "error" :
             this._errFunc = f;
 
@@ -50,6 +55,10 @@ SqlQuery.prototype.error = function(err) {
     return this._errFunc(err);
 }
 
+SqlQuery.prototype.page = function(res) {
+    return this._pageFunc(res);
+}
+
 SqlQuery.prototype.query = function() {
     return this._sql;
 }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/ed7dd30e/modules/nodejs/src/test/js/test-query.js
----------------------------------------------------------------------
diff --git a/modules/nodejs/src/test/js/test-query.js b/modules/nodejs/src/test/js/test-query.js
index a09c5da..bc0fdc2 100644
--- a/modules/nodejs/src/test/js/test-query.js
+++ b/modules/nodejs/src/test/js/test-query.js
@@ -28,21 +28,25 @@ testSqlQuery = function() {
 
         var qry = new SqlQuery("select * from String");
 
-        qry.on("error", function(err) {
-                console.log("!!!!!!!!!!!!Error: " + err);
+        var fullRes = [];
 
+        qry.on("error", function(err) {
                 TestUtils.testFails();
             });
 
-        qry.on("end", function(res) {
-                assert(res.length, 1, "Result length is not correct" +
-                    "[expected=1, val = " + res.length + "]");
+        qry.on("page", function(res) {
+            fullRes = fullRes.concat(res);
+        });
+
+        qry.on("end", function() {
+                assert(fullRes.length, 1, "Result length is not correct" +
+                    "[expected=1, val = " + fullRes.length + "]");
 
-                assert(res[0]["key"] === "key0", "Result value for key is not correct "+
-                    "[expected=key0, real=" + res[0]["key"] + "]");
+                assert(fullRes[0]["key"] === "key0", "Result value for key is not correct "+
+                    "[expected=key0, real=" + fullRes[0]["key"] + "]");
 
-                assert(res[0]["value"] === "val0", "Result value for key is not correct "+
-                    "[expected=val0, real=" + res[0]["value"] + "]");
+                assert(fullRes[0]["value"] === "val0", "Result value for key is not correct "+
+                    "[expected=val0, real=" + fullRes[0]["value"] + "]");
 
                 TestUtils.testDone();
             });

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/ed7dd30e/modules/rest-http/src/main/java/org/apache/ignite/internal/processors/rest/protocols/http/jetty/GridJettyRestHandler.java
----------------------------------------------------------------------
diff --git a/modules/rest-http/src/main/java/org/apache/ignite/internal/processors/rest/protocols/http/jetty/GridJettyRestHandler.java b/modules/rest-http/src/main/java/org/apache/ignite/internal/processors/rest/protocols/http/jetty/GridJettyRestHandler.java
index c188439..361b713 100644
--- a/modules/rest-http/src/main/java/org/apache/ignite/internal/processors/rest/protocols/http/jetty/GridJettyRestHandler.java
+++ b/modules/rest-http/src/main/java/org/apache/ignite/internal/processors/rest/protocols/http/jetty/GridJettyRestHandler.java
@@ -484,6 +484,18 @@ public class GridJettyRestHandler extends AbstractHandler {
                 break;
             }
 
+            case FETCH_SQL_QUERY: {
+                RestSqlQueryRequest restReq0 = new RestSqlQueryRequest();
+
+                restReq0.queryId(Long.parseLong((String)params.get("qryId")));
+                restReq0.pageSize(Integer.parseInt((String)params.get("psz")));
+                restReq0.cacheName((String)params.get("cacheName"));
+
+                restReq = restReq0;
+
+                break;
+            }
+
             default:
                 throw new IgniteCheckedException("Invalid command: " + cmd);
         }