ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ivasilin...@apache.org
Subject incubator-ignite git commit: #ignite-964: wip
Date Mon, 29 Jun 2015 20:19:24 GMT
Repository: incubator-ignite
Updated Branches:
  refs/heads/ignite-964 90a17a6b3 -> 02b53870a


#ignite-964: wip


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

Branch: refs/heads/ignite-964
Commit: 02b53870a68fb27851e92bf4c4190e9370d55f6b
Parents: 90a17a6
Author: ivasilinets <ivasilinets@gridgain.com>
Authored: Mon Jun 29 23:19:29 2015 +0300
Committer: ivasilinets <ivasilinets@gridgain.com>
Committed: Mon Jun 29 23:19:29 2015 +0300

----------------------------------------------------------------------
 .../handlers/query/QueryCommandHandler.java     |  10 +-
 .../rest/request/RestSqlQueryRequest.java       |   6 +-
 modules/nodejs/src/main/js/cache.js             |  19 +-
 modules/nodejs/src/main/js/server.js            |   3 -
 .../apache/ignite/internal/NodeJsSqlQuery.java  | 165 -----------------
 .../ignite/internal/NodeJsSqlQuerySelfTest.java | 180 +++++++++++++++++++
 .../testsuites/IgniteNodeJsTestSuite.java       |   2 +-
 modules/nodejs/src/test/js/test-query.js        |  45 ++++-
 .../http/jetty/GridJettyRestHandler.java        |   3 +-
 9 files changed, 248 insertions(+), 185 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/02b53870/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 b550a46..496243e 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
@@ -118,11 +118,17 @@ public class QueryCommandHandler extends GridRestCommandHandlerAdapter
{
             try {
                 Query qry;
 
-                if (req.typeName() != null)
+                if (req.typeName() != null) {
                     qry = new SqlQuery(req.typeName(), req.sqlQuery());
-                else
+
+                    ((SqlQuery)qry).setArgs(req.arguments());
+                }
+                else {
                     qry = new SqlFieldsQuery(req.sqlQuery());
 
+                    ((SqlFieldsQuery)qry).setArgs(req.arguments());
+                }
+
                 Iterator<Cache.Entry<String, String>> cur =
                     ctx.grid().cache(req.cacheName()).query(qry).iterator();
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/02b53870/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 09b2fa3..830011a 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,7 @@ public class RestSqlQueryRequest extends GridRestRequest {
     private String sqlQry;
 
     /** Sql query arguments. */
-    private Object args;
+    private Object[] args;
 
     /** Page size. */
     private Integer pageSz;
@@ -56,14 +56,14 @@ 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;
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/02b53870/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 991390a..fc988da 100644
--- a/modules/nodejs/src/main/js/cache.js
+++ b/modules/nodejs/src/main/js/cache.js
@@ -158,7 +158,7 @@ Cache.prototype.query = function(qry) {
                 Server.pair("cacheName", this._cacheName),
                 Server.pair("qryId", res.queryId),
                 Server.pair("psz", qry.pageSize())],
-                onQueryExecute.bind(this, qry, res["queryId"]));
+                onQueryExecute.bind(this, qry));
         }
     }
 
@@ -173,19 +173,32 @@ Cache.prototype.query = function(qry) {
 Cache.prototype._sqlFieldsQuery = function(qry, onQueryExecute) {
     var params = [Server.pair("cacheName", this._cacheName),
         Server.pair("qry", qry.query()),
-        Server.pair("arg", qry.arguments()),
         Server.pair("psz", qry.pageSize())];
 
+    params = params.concat(this._sqlArguments(qry.arguments()));
+
     this._server.runCommand("qryfieldsexecute", params,
         onQueryExecute.bind(this, qry));
 }
 
+Cache.prototype._sqlArguments = function(args) {
+    var res = [];
+    console.log("ARGS=" + args);
+
+    for (var i = 1; i <= args.length; i++) {
+        res.push(Server.pair("arg" + i, args[i - 1]));
+    }
+
+    return res;
+}
+
 Cache.prototype._sqlQuery = function(qry, onQueryExecute) {
     var params = [Server.pair("cacheName", this._cacheName),
         Server.pair("qry", qry.query()),
-        Server.pair("arg", qry.arguments()),
         Server.pair("psz", qry.pageSize())]
 
+    params = params.concat(this._sqlArguments(qry.arguments()));
+
     if (qry.returnType() != null) {
         params.push(Server.pair("type", qry.returnType()));
     }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/02b53870/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 488d497..81462a4 100644
--- a/modules/nodejs/src/main/js/server.js
+++ b/modules/nodejs/src/main/js/server.js
@@ -83,7 +83,6 @@ Server.prototype.runCommand = function(cmdName, params, callback) {
         var fullResponseString = '';
 
         response.on('data', function (chunk) {
-            console.log("data:" + chunk);
             fullResponseString += chunk;
         });
 
@@ -104,7 +103,6 @@ Server.prototype.runCommand = function(cmdName, params, callback) {
 
             try {
                 igniteResponse = JSON.parse(fullResponseString);
-                console.log("igniteResponse:" + igniteResponse);
             }
             catch (e) {
                 callback.call(null, e, null);
@@ -116,7 +114,6 @@ Server.prototype.runCommand = function(cmdName, params, callback) {
                 callback.call(null, igniteResponse.error, null)
             }
             else {
-                console.log("igniteResponse.response:" + igniteResponse.response);
                 callback.call(null, null, igniteResponse.response);
             }
         });

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/02b53870/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
deleted file mode 100644
index 3fcf3ad..0000000
--- a/modules/nodejs/src/test/java/org/apache/ignite/internal/NodeJsSqlQuery.java
+++ /dev/null
@@ -1,165 +0,0 @@
-/*
- * 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;
-
-import org.apache.ignite.*;
-import org.apache.ignite.cache.affinity.*;
-import org.apache.ignite.cache.query.annotations.*;
-import org.apache.ignite.configuration.*;
-
-import java.io.*;
-import java.util.*;
-
-/**
- * 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");
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testSqlFieldsQuery() throws Exception {
-
-        CacheConfiguration<UUID, Organization> orgCacheCfg = new CacheConfiguration<>("organization");
-        orgCacheCfg.setIndexedTypes(UUID.class, Organization.class);
-
-        CacheConfiguration<AffinityKey<UUID>, Person> personCacheCfg = new CacheConfiguration<>("person");
-        personCacheCfg.setIndexedTypes(AffinityKey.class, Person.class);
-
-        IgniteCache<UUID, Organization> orgCache = grid(0).getOrCreateCache(orgCacheCfg);
-
-        Organization org1 = new Organization("ApacheIgnite");
-        Organization org2 = new Organization("Other");
-
-        orgCache.put(org1.id, org1);
-        orgCache.put(org2.id, org2);
-
-        IgniteCache<AffinityKey<UUID>, Person> personCache = grid(0).getOrCreateCache(personCacheCfg);
-
-        Person p1 = new Person(org1, "John", "Doe", 2000);
-        Person p2 = new Person(org1, "Jane", "Doe", 1000);
-        Person p3 = new Person(org2, "John", "Smith", 1000);
-        Person p4 = new Person(org2, "Jane", "Smith", 2000);
-
-        personCache.put(p1.key(), p1);
-        personCache.put(p2.key(), p2);
-        personCache.put(p3.key(), p3);
-        personCache.put(p4.key(), p4);
-
-        runJsScript("testSqlFieldsQuery");
-    }
-
-    /**
-     * Person class.
-     */
-    private static class Person implements Serializable {
-        /** Person ID (indexed). */
-        @QuerySqlField(index = true)
-        private UUID id;
-
-        /** Organization ID (indexed). */
-        @QuerySqlField(index = true)
-        private UUID orgId;
-
-        /** First name (not-indexed). */
-        @QuerySqlField
-        private String firstName;
-
-        /** Last name (not indexed). */
-        @QuerySqlField
-        private String lastName;
-
-        /** Salary (indexed). */
-        @QuerySqlField(index = true)
-        private double salary;
-
-        /** Custom cache key to guarantee that person is always collocated with its organization.
*/
-        private transient AffinityKey<UUID> key;
-
-        /**
-         * @param org Organization.
-         * @param firstName First name.
-         * @param lastName Last name.
-         * @param salary Salary.
-         */
-        Person(Organization org, String firstName, String lastName, double salary) {
-            id = UUID.randomUUID();
-
-            orgId = org.id;
-
-            this.firstName = firstName;
-            this.lastName = lastName;
-            this.salary = salary;
-        }
-
-        /**
-         * @return Custom affinity key to guarantee that person is always collocated with
organization.
-         */
-        public AffinityKey<UUID> key() {
-            if (key == null)
-                key = new AffinityKey<>(id, orgId);
-
-            return key;
-        }
-    }
-
-    /**
-     * Organization class.
-     */
-    private static class Organization implements Serializable {
-        /** Organization ID (indexed). */
-        @QuerySqlField(index = true)
-        private UUID id;
-
-        /** Organization name (indexed). */
-        @QuerySqlField(index = true)
-        private String name;
-
-        /**
-         * @param name Organization name.
-         */
-        Organization(String name) {
-            id = UUID.randomUUID();
-
-            this.name = name;
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/02b53870/modules/nodejs/src/test/java/org/apache/ignite/internal/NodeJsSqlQuerySelfTest.java
----------------------------------------------------------------------
diff --git a/modules/nodejs/src/test/java/org/apache/ignite/internal/NodeJsSqlQuerySelfTest.java
b/modules/nodejs/src/test/java/org/apache/ignite/internal/NodeJsSqlQuerySelfTest.java
new file mode 100644
index 0000000..97d9852
--- /dev/null
+++ b/modules/nodejs/src/test/java/org/apache/ignite/internal/NodeJsSqlQuerySelfTest.java
@@ -0,0 +1,180 @@
+/*
+ * 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;
+
+import org.apache.ignite.*;
+import org.apache.ignite.cache.affinity.*;
+import org.apache.ignite.cache.query.annotations.*;
+import org.apache.ignite.configuration.*;
+
+import java.io.*;
+import java.util.*;
+
+/**
+ * Node js sql query test.
+ */
+public class NodeJsSqlQuerySelfTest extends NodeJsAbstractTest {
+    /**
+     * Constructor.
+     */
+    public NodeJsSqlQuerySelfTest() {
+        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");
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testSqlFieldsQuery() throws Exception {
+        initCache();
+
+        runJsScript("testSqlFieldsQuery");
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testSqlQueryWithParams() throws Exception {
+        initCache();
+
+        runJsScript("testSqlQueryWithParams");
+    }
+
+    /**
+     * Init cache.
+     */
+    private void initCache() {
+        CacheConfiguration<UUID, Organization> orgCacheCfg = new CacheConfiguration<>("organization");
+        orgCacheCfg.setIndexedTypes(UUID.class, Organization.class);
+
+        CacheConfiguration<AffinityKey<UUID>, Person> personCacheCfg = new CacheConfiguration<>("person");
+        personCacheCfg.setIndexedTypes(AffinityKey.class, Person.class);
+
+        IgniteCache<UUID, Organization> orgCache = grid(0).getOrCreateCache(orgCacheCfg);
+
+        Organization org1 = new Organization("ApacheIgnite");
+        Organization org2 = new Organization("Other");
+
+        orgCache.put(org1.id, org1);
+        orgCache.put(org2.id, org2);
+
+        IgniteCache<AffinityKey<UUID>, Person> personCache = grid(0).getOrCreateCache(personCacheCfg);
+
+        Person p1 = new Person(org1, "John", "Doe", 2000);
+        Person p2 = new Person(org1, "Jane", "Doe", 1000);
+        Person p3 = new Person(org2, "John", "Smith", 1000);
+        Person p4 = new Person(org2, "Jane", "Smith", 2000);
+
+        personCache.put(p1.key(), p1);
+        personCache.put(p2.key(), p2);
+        personCache.put(p3.key(), p3);
+        personCache.put(p4.key(), p4);
+    }
+
+    /**
+     * Person class.
+     */
+    private static class Person implements Serializable {
+        /** Person ID (indexed). */
+        @QuerySqlField(index = true)
+        private UUID id;
+
+        /** Organization ID (indexed). */
+        @QuerySqlField(index = true)
+        private UUID orgId;
+
+        /** First name (not-indexed). */
+        @QuerySqlField
+        private String firstName;
+
+        /** Last name (not indexed). */
+        @QuerySqlField
+        private String lastName;
+
+        /** Salary (indexed). */
+        @QuerySqlField(index = true)
+        private double salary;
+
+        /** Custom cache key to guarantee that person is always collocated with its organization.
*/
+        private transient AffinityKey<UUID> key;
+
+        /**
+         * @param org Organization.
+         * @param firstName First name.
+         * @param lastName Last name.
+         * @param salary Salary.
+         */
+        Person(Organization org, String firstName, String lastName, double salary) {
+            id = UUID.randomUUID();
+
+            orgId = org.id;
+
+            this.firstName = firstName;
+            this.lastName = lastName;
+            this.salary = salary;
+        }
+
+        /**
+         * @return Custom affinity key to guarantee that person is always collocated with
organization.
+         */
+        public AffinityKey<UUID> key() {
+            if (key == null)
+                key = new AffinityKey<>(id, orgId);
+
+            return key;
+        }
+    }
+
+    /**
+     * Organization class.
+     */
+    private static class Organization implements Serializable {
+        /** Organization ID (indexed). */
+        @QuerySqlField(index = true)
+        private UUID id;
+
+        /** Organization name (indexed). */
+        @QuerySqlField(index = true)
+        private String name;
+
+        /**
+         * @param name Organization name.
+         */
+        Organization(String name) {
+            id = UUID.randomUUID();
+
+            this.name = name;
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/02b53870/modules/nodejs/src/test/java/org/apache/ignite/testsuites/IgniteNodeJsTestSuite.java
----------------------------------------------------------------------
diff --git a/modules/nodejs/src/test/java/org/apache/ignite/testsuites/IgniteNodeJsTestSuite.java
b/modules/nodejs/src/test/java/org/apache/ignite/testsuites/IgniteNodeJsTestSuite.java
index f848b43..f6ab879 100644
--- a/modules/nodejs/src/test/java/org/apache/ignite/testsuites/IgniteNodeJsTestSuite.java
+++ b/modules/nodejs/src/test/java/org/apache/ignite/testsuites/IgniteNodeJsTestSuite.java
@@ -36,7 +36,7 @@ public class IgniteNodeJsTestSuite extends TestSuite {
         suite.addTest(new TestSuite(NodeJsSecretKeySelfTest.class));
         suite.addTest(new TestSuite(NodeJsComputeSelfTest.class));
         suite.addTest(new TestSuite(NodeJsIgniteSelfTest.class));
-        suite.addTest(new TestSuite(NodeJsSqlQuery.class));
+        suite.addTest(new TestSuite(NodeJsSqlQuerySelfTest.class));
 
         return suite;
     }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/02b53870/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 502d391..794e71a 100644
--- a/modules/nodejs/src/test/js/test-query.js
+++ b/modules/nodejs/src/test/js/test-query.js
@@ -79,21 +79,52 @@ testSqlFieldsQuery = function() {
             });
 
         qry.on("page", function(res) {
-            console.log("PAGE   : " + res);
             fullRes = fullRes.concat(res);
         });
 
         qry.on("end", function() {
-                console.log("END=" + fullRes);
-
                 assert(fullRes.length, 1, "Result length is not correct" +
                     "[expected=1, val = " + fullRes.length + "]");
 
-                assert(fullRes[0]["key"] === "key0", "Result value for key is not correct
"+
-                    "[expected=key0, real=" + fullRes[0]["key"] + "]");
+                assert(fullRes[0].indexOf("Jane Doe") > -1,
+                    "Result does not contain Jane Doe [res=" + fullRes[0] + "]");
 
-                assert(fullRes[0]["value"] === "val0", "Result value for key is not correct
"+
-                    "[expected=val0, real=" + fullRes[0]["value"] + "]");
+                TestUtils.testDone();
+            });
+
+        ignite.cache("person").query(qry);
+    }
+
+    TestUtils.startIgniteNode(sqlFieldsQuery.bind(null));
+}
+
+testSqlQueryWithParams = function() {
+    function sqlFieldsQuery(error, ignite) {
+        assert(error == null, "error on sql query [err=" + error + "]");
+
+        var qry = new SqlQuery("salary > ? and salary <= ?");
+
+        qry.setReturnType("Person");
+
+        qry.setArguments([1000, 2000]);
+
+        var fullRes = [];
+
+        qry.on("error", function(err) {
+                TestUtils.testFails();
+            });
+
+        qry.on("page", function(res) {
+            fullRes = fullRes.concat(res);
+        });
+
+        qry.on("end", function() {
+                //TODO:
+                assert(fullRes.length, 1, "Result length is not correct" +
+                    "[expected=1, val = " + fullRes.length + "]");
+
+                assert(fullRes[0].indexOf("Jane Doe") > -1,
+                    "Result does not contain Jane Doe [res=" + fullRes[0] + "]");
 
                 TestUtils.testDone();
             });

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/02b53870/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 2269823..8d88adf 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
@@ -476,7 +476,8 @@ public class GridJettyRestHandler extends AbstractHandler {
                 RestSqlQueryRequest restReq0 = new RestSqlQueryRequest();
 
                 restReq0.sqlQuery((String)params.get("qry"));
-                restReq0.arguments(params.get("arg"));
+                List<Object> args = values("arg", params);
+                restReq0.arguments(args.toArray());
                 restReq0.typeName((String)params.get("type"));
                 restReq0.pageSize(Integer.parseInt((String) params.get("psz")));
                 restReq0.cacheName((String)params.get("cacheName"));


Mime
View raw message