You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by vo...@apache.org on 2016/06/20 12:52:53 UTC
[13/50] ignite git commit: IGNITE-3273 - fixed
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 <se...@gmail.com>
Authored: Tue Jun 14 21:47:11 2016 +0300
Committer: Sergi Vladykin <se...@gmail.com>
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<GridSqlElement>(on == null ? 2 : 3));
+ super(new ArrayList<GridSqlElement>(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<Integer, Person> p = ignite(0).createCache(cacheConfig("P", true, Integer.class, Person.class));
+ IgniteCache<Integer, Department> d = ignite(0).createCache(cacheConfig("D", true, Integer.class, Department.class));
+ IgniteCache<Integer, Org> 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 {