Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id B02D7200B52 for ; Mon, 25 Jul 2016 14:23:33 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id AE853160A7D; Mon, 25 Jul 2016 12:23:33 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id D17D2160A78 for ; Mon, 25 Jul 2016 14:23:32 +0200 (CEST) Received: (qmail 32385 invoked by uid 500); 25 Jul 2016 12:23:31 -0000 Mailing-List: contact commits-help@ignite.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@ignite.apache.org Delivered-To: mailing list commits@ignite.apache.org Received: (qmail 32376 invoked by uid 99); 25 Jul 2016 12:23:31 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 25 Jul 2016 12:23:31 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id C672BE00A7; Mon, 25 Jul 2016 12:23:31 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: sboikov@apache.org To: commits@ignite.apache.org Message-Id: X-Mailer: ASF-Git Admin Mailer Subject: ignite git commit: ignite-3573 Support of Distributed joins queries in REST API Date: Mon, 25 Jul 2016 12:23:31 +0000 (UTC) archived-at: Mon, 25 Jul 2016 12:23:33 -0000 Repository: ignite Updated Branches: refs/heads/master 0e15cf1df -> f245c3838 ignite-3573 Support of Distributed joins queries in REST API Project: http://git-wip-us.apache.org/repos/asf/ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/f245c383 Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/f245c383 Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/f245c383 Branch: refs/heads/master Commit: f245c3838bd2eda4aa11b0bd0d07223b9cb2f237 Parents: 0e15cf1 Author: agura Authored: Mon Jul 25 14:31:10 2016 +0300 Committer: agura Committed: Mon Jul 25 15:22:47 2016 +0300 ---------------------------------------------------------------------- .../JettyRestProcessorAbstractSelfTest.java | 121 ++++++++++++++++++- .../handlers/query/QueryCommandHandler.java | 4 + .../rest/request/RestQueryRequest.java | 17 +++ .../http/jetty/GridJettyRestHandler.java | 5 + 4 files changed, 142 insertions(+), 5 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ignite/blob/f245c383/modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/JettyRestProcessorAbstractSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/JettyRestProcessorAbstractSelfTest.java b/modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/JettyRestProcessorAbstractSelfTest.java index 0dd12ac..8d3ab74 100644 --- a/modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/JettyRestProcessorAbstractSelfTest.java +++ b/modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/JettyRestProcessorAbstractSelfTest.java @@ -1687,6 +1687,32 @@ public abstract class JettyRestProcessorAbstractSelfTest extends AbstractRestPro /** * @throws Exception If failed. */ + public void testDistributedJoinsQuery() throws Exception { + String qry = "select * from Person, \"organization\".Organization " + + "where \"organization\".Organization.id = Person.orgId " + + "and \"organization\".Organization.name = ?"; + + Map params = new HashMap<>(); + params.put("cmd", GridRestCommand.EXECUTE_SQL_QUERY.key()); + params.put("type", "Person"); + params.put("distributedJoins", "true"); + params.put("pageSize", "10"); + params.put("cacheName", "person"); + params.put("qry", URLEncoder.encode(qry, CHARSET)); + params.put("arg1", "o1"); + + String ret = content(params); + + JsonNode items = jsonResponse(ret).get("items"); + + assertEquals(2, items.size()); + + assertFalse(queryCursorFound()); + } + + /** + * @throws Exception If failed. + */ public void testSqlFieldsQuery() throws Exception { String qry = "select concat(firstName, ' ', lastName) from Person"; @@ -1708,6 +1734,28 @@ public abstract class JettyRestProcessorAbstractSelfTest extends AbstractRestPro /** * @throws Exception If failed. */ + public void testDistributedJoinsSqlFieldsQuery() throws Exception { + String qry = "select * from \"person\".Person p, \"organization\".Organization o where o.id = p.orgId"; + + Map params = new HashMap<>(); + params.put("cmd", GridRestCommand.EXECUTE_SQL_FIELDS_QUERY.key()); + params.put("distributedJoins", "true"); + params.put("pageSize", "10"); + params.put("cacheName", "person"); + params.put("qry", URLEncoder.encode(qry, CHARSET)); + + String ret = content(params); + + JsonNode items = jsonResponse(ret).get("items"); + + assertEquals(4, items.size()); + + assertFalse(queryCursorFound()); + } + + /** + * @throws Exception If failed. + */ public void testSqlFieldsMetadataQuery() throws Exception { String qry = "select firstName, lastName from Person"; @@ -1831,6 +1879,20 @@ public abstract class JettyRestProcessorAbstractSelfTest extends AbstractRestPro * Init cache. */ private void initCache() { + CacheConfiguration orgCacheCfg = new CacheConfiguration<>("organization"); + + orgCacheCfg.setIndexedTypes(Integer.class, Organization.class); + + IgniteCache orgCache = ignite(0).getOrCreateCache(orgCacheCfg); + + orgCache.clear(); + + Organization o1 = new Organization(1, "o1"); + Organization o2 = new Organization(2, "o2"); + + orgCache.put(1, o1); + orgCache.put(2, o2); + CacheConfiguration personCacheCfg = new CacheConfiguration<>("person"); personCacheCfg.setIndexedTypes(Integer.class, Person.class); @@ -1839,10 +1901,10 @@ public abstract class JettyRestProcessorAbstractSelfTest extends AbstractRestPro personCache.clear(); - Person p1 = new Person("John", "Doe", 2000); - Person p2 = new Person("Jane", "Doe", 1000); - Person p3 = new Person("John", "Smith", 1000); - Person p4 = new Person("Jane", "Smith", 2000); + Person p1 = new Person(1, "John", "Doe", 2000); + Person p2 = new Person(1, "Jane", "Doe", 1000); + Person p3 = new Person(2, "John", "Smith", 1000); + Person p4 = new Person(2, "Jane", "Smith", 2000); personCache.put(p1.getId(), p1); personCache.put(p2.getId(), p2); @@ -1856,6 +1918,43 @@ public abstract class JettyRestProcessorAbstractSelfTest extends AbstractRestPro assertEquals(2, personCache.query(qry).getAll().size()); } + + /** + * Organization class. + */ + public static class Organization implements Serializable { + /** Organization ID (indexed). */ + @QuerySqlField(index = true) + private Integer id; + + /** First name (not-indexed). */ + @QuerySqlField(index = true) + private String name; + + /** + * @param id Id. + * @param name Name. + */ + Organization(Integer id, String name) { + this.id = id; + this.name = name; + } + + /** + * @return Id. + */ + public Integer getId() { + return id; + } + + /** + * @return Name. + */ + public String getName() { + return name; + } + } + /** * Person class. */ @@ -1867,6 +1966,10 @@ public abstract class JettyRestProcessorAbstractSelfTest extends AbstractRestPro @QuerySqlField(index = true) private Integer id; + /** Organization id. */ + @QuerySqlField(index = true) + private Integer orgId; + /** First name (not-indexed). */ @QuerySqlField private String firstName; @@ -1884,15 +1987,23 @@ public abstract class JettyRestProcessorAbstractSelfTest extends AbstractRestPro * @param lastName Last name. * @param salary Salary. */ - Person(String firstName, String lastName, double salary) { + Person(Integer orgId, String firstName, String lastName, double salary) { id = PERSON_ID++; + this.orgId = orgId; this.firstName = firstName; this.lastName = lastName; this.salary = salary; } /** + * @return Organization ID. + */ + public Integer getOrganizationId() { + return orgId; + } + + /** * @return First name. */ public String getFirstName() { http://git-wip-us.apache.org/repos/asf/ignite/blob/f245c383/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 67e146b..4317dd9 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 @@ -278,6 +278,8 @@ public class QueryCommandHandler extends GridRestCommandHandlerAdapter { ((SqlQuery)qry).setArgs(req.arguments()); + ((SqlQuery)qry).setDistributedJoins(req.distributedJoins()); + break; case SQL_FIELDS: @@ -285,6 +287,8 @@ public class QueryCommandHandler extends GridRestCommandHandlerAdapter { ((SqlFieldsQuery)qry).setArgs(req.arguments()); + ((SqlFieldsQuery)qry).setDistributedJoins(req.distributedJoins()); + break; case SCAN: http://git-wip-us.apache.org/repos/asf/ignite/blob/f245c383/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/request/RestQueryRequest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/request/RestQueryRequest.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/request/RestQueryRequest.java index a719776..7159c83 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/request/RestQueryRequest.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/request/RestQueryRequest.java @@ -32,6 +32,9 @@ public class RestQueryRequest extends GridRestRequest { /** Page size. */ private Integer pageSize; + /** Distributed joins. */ + private boolean distributedJoins; + /** Cache name. */ private String cacheName; @@ -90,6 +93,20 @@ public class RestQueryRequest extends GridRestRequest { } /** + * @param distributedJoins New distributed joins. + */ + public void distributedJoins(boolean distributedJoins) { + this.distributedJoins = distributedJoins; + } + + /** + * @return Distributed joins. + */ + public boolean distributedJoins() { + return distributedJoins; + } + + /** * @param cacheName Cache name. */ public void cacheName(String cacheName) { http://git-wip-us.apache.org/repos/asf/ignite/blob/f245c383/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 c2679df..c864a10 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 @@ -566,6 +566,11 @@ public class GridJettyRestHandler extends AbstractHandler { if (pageSize != null) restReq0.pageSize(Integer.parseInt(pageSize)); + String distributedJoins = (String)params.get("distributedJoins"); + + if (distributedJoins != null) + restReq0.distributedJoins(Boolean.parseBoolean(distributedJoins)); + restReq0.cacheName((String)params.get("cacheName")); if (cmd == EXECUTE_SQL_QUERY)