You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by ak...@apache.org on 2016/09/16 05:49:31 UTC

[17/50] [abbrv] ignite git commit: IGNITE-3831: CPP: Added distributed joins query example. This closes #1035.

IGNITE-3831: CPP: Added distributed joins query example. This closes #1035.


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

Branch: refs/heads/ignite-3443
Commit: fc6f8797ed5a22820a8cf0df0482dc09e2df6731
Parents: 35d6a56
Author: Igor Sapego <is...@gridgain.com>
Authored: Tue Sep 13 14:57:36 2016 +0300
Committer: vozerov-gridgain <vo...@gridgain.com>
Committed: Tue Sep 13 14:57:36 2016 +0300

----------------------------------------------------------------------
 .../query-example/src/query_example.cpp         | 54 ++++++++++++++++++++
 1 file changed, 54 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/fc6f8797/modules/platforms/cpp/examples/query-example/src/query_example.cpp
----------------------------------------------------------------------
diff --git a/modules/platforms/cpp/examples/query-example/src/query_example.cpp b/modules/platforms/cpp/examples/query-example/src/query_example.cpp
index 1bbf21b..9bf3e52 100644
--- a/modules/platforms/cpp/examples/query-example/src/query_example.cpp
+++ b/modules/platforms/cpp/examples/query-example/src/query_example.cpp
@@ -43,6 +43,57 @@ const char* PERSON_CACHE = "Person";
 const char* PERSON_TYPE = "Person";
 
 /**
+ * Example for SQL queries based on all employees working for a specific
+ * organization (query uses distributed join).
+ */
+void DoSqlQueryWithDistributedJoin()
+{
+    typedef std::vector< CacheEntry<int64_t, Person> > ResVector;
+
+    Cache<int64_t, Person> cache = Ignition::Get().GetCache<int64_t, Person>(PERSON_CACHE);
+
+    // SQL clause query which joins on 2 types to select people for a specific organization.
+    std::string joinSql(
+        "from Person, \"Organization\".Organization as org "
+        "where Person.orgId = org._key "
+        "and lower(org.name) = lower(?)");
+
+    SqlQuery qry("Person", joinSql);
+
+    qry.AddArgument<std::string>("ApacheIgnite");
+
+    // Enable distributed joins for query.
+    qry.SetDistributedJoins(true);
+
+    // Execute queries for find employees for different organizations.
+    ResVector igniters;
+    cache.Query(qry).GetAll(igniters);
+
+    // Printing first result set.
+    std::cout << "Following people are 'ApacheIgnite' employees (distributed join): " << std::endl;
+
+    for (ResVector::const_iterator i = igniters.begin(); i != igniters.end(); ++i)
+        std::cout << i->GetKey() << " : " << i->GetValue().ToString() << std::endl;
+
+    std::cout << std::endl;
+
+    qry = SqlQuery("Person", joinSql);
+
+    qry.AddArgument<std::string>("Other");
+
+    ResVector others;
+    cache.Query(qry).GetAll(others);
+
+    // Printing second result set.
+    std::cout << "Following people are 'Other' employees (distributed join): " << std::endl;
+
+    for (ResVector::const_iterator i = others.begin(); i != others.end(); ++i)
+        std::cout << i->GetKey() << " : " << i->GetValue().ToString() << std::endl;
+
+    std::cout << std::endl;
+}
+
+/**
  * Example for SQL-based fields queries that return only required
  * fields instead of whole key-value pairs.
  *
@@ -374,6 +425,9 @@ int main()
         // Example for SQL-based querying employees for a given organization (includes SQL join).
         DoSqlQueryWithJoin();
 
+        // Example for SQL-based querying employees for a given organization (includes distributed SQL join).
+        DoSqlQueryWithDistributedJoin();
+
         // Example for TEXT-based querying for a given string in peoples resumes.
         DoTextQuery();