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 5C532200B16 for ; Mon, 20 Jun 2016 14:52:44 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 5B2C7160A6C; Mon, 20 Jun 2016 12:52:44 +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 D223C160A6E for ; Mon, 20 Jun 2016 14:52:42 +0200 (CEST) Received: (qmail 7013 invoked by uid 500); 20 Jun 2016 12:52:42 -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 6567 invoked by uid 99); 20 Jun 2016 12:52:41 -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, 20 Jun 2016 12:52:41 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id B6311DFC6F; Mon, 20 Jun 2016 12:52:41 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: vozerov@apache.org To: commits@ignite.apache.org Date: Mon, 20 Jun 2016 12:52:53 -0000 Message-Id: In-Reply-To: <89985bfe12394840b4deddba739acaf2@git.apache.org> References: <89985bfe12394840b4deddba739acaf2@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [13/50] ignite git commit: IGNITE-3273 - fixed archived-at: Mon, 20 Jun 2016 12:52:44 -0000 IGNITE-3273 - fixed Project: http://git-wip-us.apache.org/repos/asf/ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/e27ba14d Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/e27ba14d Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/e27ba14d Branch: refs/heads/ignite-3341 Commit: e27ba14d51b9ba43a1f5a467d09b2e5e5072cd9c Parents: 5f44672 Author: Sergi Vladykin Authored: Tue Jun 14 21:47:11 2016 +0300 Committer: Sergi Vladykin Committed: Wed Jun 15 10:28:49 2016 +0300 ---------------------------------------------------------------------- .../processors/query/h2/sql/GridSqlConst.java | 5 ++ .../processors/query/h2/sql/GridSqlJoin.java | 17 +++-- .../processors/query/h2/sql/GridSqlType.java | 5 ++ .../query/IgniteSqlSplitterSelfTest.java | 75 ++++++++++++++++++++ 4 files changed, 93 insertions(+), 9 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ignite/blob/e27ba14d/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlConst.java ---------------------------------------------------------------------- diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlConst.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlConst.java index 36c95ce..976eb2c 100644 --- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlConst.java +++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlConst.java @@ -19,12 +19,17 @@ package org.apache.ignite.internal.processors.query.h2.sql; import java.util.Collections; import org.h2.value.Value; +import org.h2.value.ValueBoolean; /** * Constant value. */ public class GridSqlConst extends GridSqlElement implements GridSqlValue { /** */ + public static final GridSqlElement TRUE = new GridSqlConst(ValueBoolean.get(true)) + .resultType(GridSqlType.BOOLEAN); + + /** */ private final Value val; /** http://git-wip-us.apache.org/repos/asf/ignite/blob/e27ba14d/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlJoin.java ---------------------------------------------------------------------- diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlJoin.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlJoin.java index 0148404..f1ad2e5 100644 --- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlJoin.java +++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlJoin.java @@ -36,13 +36,15 @@ public class GridSqlJoin extends GridSqlElement { * @param on Join condition. */ public GridSqlJoin(GridSqlElement leftTbl, GridSqlElement rightTbl, boolean leftOuter, @Nullable GridSqlElement on) { - super(new ArrayList(on == null ? 2 : 3)); + super(new ArrayList(3)); addChild(leftTbl); addChild(rightTbl); - if (on != null) - addChild(on); + if (on == null) // To avoid query nesting issues in FROM clause we need to always generate ON condition. + on = GridSqlConst.TRUE; + + addChild(on); this.leftOuter = leftOuter; } @@ -64,8 +66,8 @@ public class GridSqlJoin extends GridSqlElement { /** * @return {@code JOIN ON} condition. */ - @Nullable public GridSqlElement on() { - return size() < 3 ? null : child(2); + public GridSqlElement on() { + return child(2); } /** {@inheritDoc} */ @@ -78,10 +80,7 @@ public class GridSqlJoin extends GridSqlElement { buff.append(rightTable().getSQL()); - GridSqlElement on = on(); - - if (on != null) - buff.append(" \n ON ").append(StringUtils.unEnclose(on.getSQL())); + buff.append(" \n ON ").append(StringUtils.unEnclose(on().getSQL())); return buff.toString(); } http://git-wip-us.apache.org/repos/asf/ignite/blob/e27ba14d/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlType.java ---------------------------------------------------------------------- diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlType.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlType.java index febf174..efe9138 100644 --- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlType.java +++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlType.java @@ -22,6 +22,7 @@ import org.apache.ignite.internal.util.typedef.internal.S; import org.h2.expression.Expression; import org.h2.table.Column; import org.h2.value.Value; +import org.h2.value.ValueBoolean; import org.h2.value.ValueDouble; import org.h2.value.ValueLong; @@ -43,6 +44,10 @@ public final class GridSqlType { /** */ public static final GridSqlType UUID = new GridSqlType(Value.UUID, 0, Integer.MAX_VALUE, 36, "UUID"); + /** */ + public static final GridSqlType BOOLEAN = new GridSqlType(Value.BOOLEAN, 0, ValueBoolean.PRECISION, + ValueBoolean.DISPLAY_SIZE, "BOOLEAN"); + /** H2 type. */ private final int type; http://git-wip-us.apache.org/repos/asf/ignite/blob/e27ba14d/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/IgniteSqlSplitterSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/IgniteSqlSplitterSelfTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/IgniteSqlSplitterSelfTest.java index d0e2780..fd52469 100644 --- a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/IgniteSqlSplitterSelfTest.java +++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/IgniteSqlSplitterSelfTest.java @@ -313,6 +313,81 @@ public class IgniteSqlSplitterSelfTest extends GridCommonAbstractTest { } /** + * + */ + public void testImplicitJoinConditionGeneration() { + IgniteCache p = ignite(0).createCache(cacheConfig("P", true, Integer.class, Person.class)); + IgniteCache d = ignite(0).createCache(cacheConfig("D", true, Integer.class, Department.class)); + IgniteCache o = ignite(0).createCache(cacheConfig("O", true, Integer.class, Org.class)); + + try { + info("Plan: " + p.query(new SqlFieldsQuery( + "explain select P.Person.*,dep.*,org.* " + + "from P.Person inner join D.Department dep ON dep.id=P.Person.depId " + + "left join O.Org org ON org.id=dep.orgId" + )).getAll()); + + assertEquals(0, p.query(new SqlFieldsQuery( + "select P.Person.*,dep.*,org.* " + + "from P.Person inner join D.Department dep ON dep.id=P.Person.depId " + + "left join O.Org org ON org.id=dep.orgId" + )).getAll().size()); + } + finally { + p.destroy(); + d.destroy(); + o.destroy(); + } + } + + /** + * + */ + public static class Person { + /** */ + @QuerySqlField + private int id; + + /** */ + @QuerySqlField + private String name; + + /** */ + @QuerySqlField + private int depId; + } + + /** + * + */ + public static class Org { + /** */ + @QuerySqlField(index = true) + private int id; + + /** */ + @QuerySqlField + private String name; + } + + /** + * + */ + public static class Department { + /** */ + @QuerySqlField(index = true) + private int id; + + /** */ + @QuerySqlField(index = true) + private int orgId; + + /** */ + @QuerySqlField + private String name; + } + + /** * Test value. */ private static class GroupIndexTestValue implements Serializable {