You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by pt...@apache.org on 2016/07/25 13:14:55 UTC
[7/9] ignite git commit: ignite-3573 Support of Distributed joins
queries in REST API
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/855281ed
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/855281ed
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/855281ed
Branch: refs/heads/master
Commit: 855281ed33563f861921c5f93b39625db0206f72
Parents: 763f067
Author: agura <ag...@gridgain.com>
Authored: Mon Jul 25 14:31:10 2016 +0300
Committer: agura <ag...@gridgain.com>
Committed: Mon Jul 25 15:24:41 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/855281ed/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 81bffcf..637099b 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
@@ -1679,6 +1679,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<String, String> 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";
@@ -1700,6 +1726,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<String, String> 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";
@@ -1823,6 +1871,20 @@ public abstract class JettyRestProcessorAbstractSelfTest extends AbstractRestPro
* Init cache.
*/
private void initCache() {
+ CacheConfiguration<Integer, Organization> orgCacheCfg = new CacheConfiguration<>("organization");
+
+ orgCacheCfg.setIndexedTypes(Integer.class, Organization.class);
+
+ IgniteCache<Integer, Organization> 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<Integer, Person> personCacheCfg = new CacheConfiguration<>("person");
personCacheCfg.setIndexedTypes(Integer.class, Person.class);
@@ -1831,10 +1893,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);
@@ -1848,6 +1910,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.
*/
@@ -1859,6 +1958,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;
@@ -1876,15 +1979,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/855281ed/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/855281ed/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/855281ed/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)