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 85DFA200B80 for ; Wed, 14 Sep 2016 11:18:07 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 84C78160AB4; Wed, 14 Sep 2016 09:18:07 +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 B28A6160ADE for ; Wed, 14 Sep 2016 11:18:06 +0200 (CEST) Received: (qmail 9871 invoked by uid 500); 14 Sep 2016 09:18:05 -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 9628 invoked by uid 99); 14 Sep 2016 09:18:05 -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; Wed, 14 Sep 2016 09:18:05 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 74F96E09C6; Wed, 14 Sep 2016 09:18:05 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: akuznetsov@apache.org To: commits@ignite.apache.org Date: Wed, 14 Sep 2016 09:18:09 -0000 Message-Id: <4d5aa2a457574b6fb8ff0b86907e77d9@git.apache.org> In-Reply-To: <61d13fe42f974ca2b741564ee09255e5@git.apache.org> References: <61d13fe42f974ca2b741564ee09255e5@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [05/12] ignite git commit: IGNITE-3831: CPP: Added distributed joins query example. This closes #1035. archived-at: Wed, 14 Sep 2016 09:18:07 -0000 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/master Commit: fc6f8797ed5a22820a8cf0df0482dc09e2df6731 Parents: 35d6a56 Author: Igor Sapego Authored: Tue Sep 13 14:57:36 2016 +0300 Committer: vozerov-gridgain 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 > ResVector; + + Cache cache = Ignition::Get().GetCache(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("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("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();