You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by sb...@apache.org on 2015/07/23 11:59:51 UTC

[12/32] incubator-ignite git commit: ignite-1015

ignite-1015


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

Branch: refs/heads/ignite-788-last-review
Commit: f1f3da8ed047bf3df173b74b6430d52fe06c9f57
Parents: f9fe999
Author: S.Vladykin <sv...@gridgain.com>
Authored: Tue Jul 21 20:29:58 2015 +0300
Committer: S.Vladykin <sv...@gridgain.com>
Committed: Tue Jul 21 20:29:58 2015 +0300

----------------------------------------------------------------------
 .../processors/query/h2/sql/GridSqlElement.java |  17 +-
 .../query/h2/sql/GridSqlOperation.java          |  14 --
 .../processors/query/h2/sql/GridSqlQuery.java   |  17 +-
 .../query/h2/sql/GridSqlQueryParser.java        |  11 +-
 .../query/h2/sql/GridSqlQuerySplitter.java      | 196 ++++++++++---------
 .../processors/query/h2/sql/GridSqlSelect.java  |  72 +------
 .../processors/query/h2/sql/GridSqlType.java    |  10 +-
 .../processors/query/h2/sql/GridSqlUnion.java   |  11 --
 .../cache/GridCacheCrossCacheQuerySelfTest.java |  70 -------
 9 files changed, 125 insertions(+), 293 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/f1f3da8e/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlElement.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlElement.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlElement.java
index a1c91ff..9a6b410 100644
--- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlElement.java
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlElement.java
@@ -22,7 +22,7 @@ import java.util.*;
 /**
  * Abstract SQL element.
  */
-public abstract class GridSqlElement implements Cloneable, Iterable<GridSqlElement> {
+public abstract class GridSqlElement implements Iterable<GridSqlElement> {
     /** */
     protected List<GridSqlElement> children = new ArrayList<>();
 
@@ -78,21 +78,6 @@ public abstract class GridSqlElement implements Cloneable, Iterable<GridSqlEleme
         return children.get(idx);
     }
 
-    /** {@inheritDoc} */
-    @SuppressWarnings({"CloneCallsConstructors", "CloneDoesntDeclareCloneNotSupportedException"})
-    @Override public GridSqlElement clone() {
-        try {
-            GridSqlElement res = (GridSqlElement)super.clone();
-
-            res.children = new ArrayList<>(children);
-
-            return res;
-        }
-        catch (CloneNotSupportedException e) {
-            throw new IllegalStateException(e);
-        }
-    }
-
     /**
      * @param idx Index.
      * @param child New child.

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/f1f3da8e/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlOperation.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlOperation.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlOperation.java
index 625444c..6100618 100644
--- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlOperation.java
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlOperation.java
@@ -54,20 +54,6 @@ public class GridSqlOperation extends GridSqlElement {
     }
 
     /**
-     * @return Left.
-     */
-    public GridSqlElement left() {
-        return child(0);
-    }
-
-    /**
-     * @return Right.
-     */
-    public GridSqlElement right() {
-        return child(1);
-    }
-
-    /**
      * @return Operation type.
      */
     public GridSqlOperationType opType() {

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/f1f3da8e/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlQuery.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlQuery.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlQuery.java
index 207588e..b562279 100644
--- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlQuery.java
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlQuery.java
@@ -24,7 +24,7 @@ import java.util.*;
 /**
  * Select query.
  */
-public abstract class GridSqlQuery implements Cloneable {
+public abstract class GridSqlQuery {
     /** */
     protected boolean distinct;
 
@@ -185,19 +185,4 @@ public abstract class GridSqlQuery implements Cloneable {
             buff.append(" OFFSET ").append(StringUtils.unEnclose(offset.getSQL()));
 
     }
-
-    /** {@inheritDoc} */
-    @SuppressWarnings({"CloneCallsConstructors", "CloneDoesntDeclareCloneNotSupportedException"})
-    @Override public GridSqlQuery clone() {
-        try {
-            GridSqlQuery res = (GridSqlQuery)super.clone();
-
-            res.sort = new ArrayList<>(sort);
-
-            return res;
-        }
-        catch (CloneNotSupportedException e) {
-            throw new RuntimeException(e); // Never thrown.
-        }
-    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/f1f3da8e/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlQueryParser.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlQueryParser.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlQueryParser.java
index 74e4748..4267b4a 100644
--- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlQueryParser.java
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlQueryParser.java
@@ -276,21 +276,14 @@ public class GridSqlQueryParser {
 
         int[] grpIdx = GROUP_INDEXES.get(select);
 
-        if (grpIdx != null) {
+        if (grpIdx != null)
             res.groupColumns(grpIdx);
 
-            for (int idx : grpIdx)
-                res.addGroupExpression(parseExpression(expressions.get(idx)));
-        }
-
         int havingIdx = HAVING_INDEX.get(select);
 
-        if (havingIdx >= 0) {
+        if (havingIdx >= 0)
             res.havingColumn(havingIdx);
 
-            res.having(parseExpression(expressions.get(havingIdx)));
-        }
-
         processSortOrder(select.getSortOrder(), res);
 
         res.limit(parseExpression(select.getLimit()));

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/f1f3da8e/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlQuerySplitter.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlQuerySplitter.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlQuerySplitter.java
index 7ffbc16..b1dc0dc 100644
--- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlQuerySplitter.java
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlQuerySplitter.java
@@ -70,77 +70,85 @@ public class GridSqlQuerySplitter {
     }
 
     /**
-     * @param stmt Prepared statement.
-     * @param params Parameters.
-     * @param collocated Collocated query.
-     * @return Two step query.
+     * @param qry Query.
+     * @return Select query.
      */
-    public static GridCacheTwoStepQuery split(JdbcPreparedStatement stmt, Object[] params, boolean collocated) {
-        if (params == null)
-            params = GridCacheSqlQuery.EMPTY_PARAMS;
+    private static GridSqlSelect wrapUnion(GridSqlQuery qry) {
+        if (qry instanceof GridSqlSelect)
+            return (GridSqlSelect)qry;
 
-        final GridSqlQuery qry0 = GridSqlQueryParser.parse(stmt);
+        // Handle UNION.
+        GridSqlSelect wrapQry = new GridSqlSelect().from(new GridSqlSubquery(qry));
 
-        GridSqlSelect srcQry;
+        wrapQry.explain(qry.explain());
+        qry.explain(false);
 
-        if (qry0 instanceof GridSqlSelect)
-            srcQry = (GridSqlSelect)qry0;
-        else { // Handle UNION.
-            srcQry = new GridSqlSelect().from(new GridSqlSubquery(qry0));
+        GridSqlSelect left = leftest(qry);
 
-            srcQry.explain(qry0.explain());
+        int c = 0;
 
-            GridSqlSelect left = leftest(qry0);
+        for (GridSqlElement expr : left.select(true)) {
+            String colName;
 
-            int c = 0;
+            if (expr instanceof GridSqlAlias)
+                colName = ((GridSqlAlias)expr).alias();
+            else if (expr instanceof GridSqlColumn)
+                colName = ((GridSqlColumn)expr).columnName();
+            else {
+                colName = columnName(c);
 
-            for (GridSqlElement expr : left.select(true)) {
-                String colName;
+                expr = alias(colName, expr);
 
-                if (expr instanceof GridSqlAlias)
-                    colName = ((GridSqlAlias)expr).alias();
-                else if (expr instanceof GridSqlColumn)
-                    colName = ((GridSqlColumn)expr).columnName();
-                else {
-                    colName = columnName(c);
+                // Set generated alias to the expression.
+                left.setSelectExpression(c, expr);
+            }
 
-                    expr = alias(colName, expr);
+            GridSqlColumn col = column(colName);
 
-                    // Set generated alias to the expression.
-                    left.setSelectExpression(c, expr);
-                }
+            wrapQry.addSelectExpression(col, true);
 
-                GridSqlColumn col = column(colName);
+            c++;
+        }
 
-                srcQry.addSelectExpression(col, true);
+        // ORDER BY
+        if (!qry.sort().isEmpty()) {
+            for (GridSqlSortColumn col : qry.sort())
+                wrapQry.addSort(col);
+        }
 
-                qry0.sort();
+        return wrapQry;
+    }
 
-                c++;
-            }
+    /**
+     * @param stmt Prepared statement.
+     * @param params Parameters.
+     * @param collocated Collocated query.
+     * @return Two step query.
+     */
+    public static GridCacheTwoStepQuery split(JdbcPreparedStatement stmt, Object[] params, boolean collocated) {
+        if (params == null)
+            params = GridCacheSqlQuery.EMPTY_PARAMS;
 
-            // ORDER BY
-            if (!qry0.sort().isEmpty()) {
-                for (GridSqlSortColumn col : qry0.sort())
-                    srcQry.addSort(col);
-            }
-        }
+        Set<String> spaces = new HashSet<>();
+
+        // Map query will be direct reference to the original query AST.
+        // Thus all the modifications will be performed on the original AST, so we should be careful when
+        // nullifying or updating things, have to make sure that we will not need them in the original form later.
+        final GridSqlSelect mapQry = wrapUnion(collectAllSpaces(GridSqlQueryParser.parse(stmt), spaces));
 
         final String mergeTable = TABLE_FUNC_NAME + "()"; // table(0); TODO
 
-        // Create map and reduce queries.
-        GridSqlSelect mapQry = srcQry.clone();
+        final boolean explain = mapQry.explain();
 
         mapQry.explain(false);
 
         GridSqlSelect rdcQry = new GridSqlSelect().from(new GridSqlFunction(null, TABLE_FUNC_NAME)); // table(mergeTable)); TODO
 
         // Split all select expressions into map-reduce parts.
-        List<GridSqlElement> mapExps = F.addAll(
-            new ArrayList<GridSqlElement>(srcQry.allColumns()),
-            srcQry.select(false));
+        List<GridSqlElement> mapExps = F.addAll(new ArrayList<GridSqlElement>(mapQry.allColumns()),
+            mapQry.select(false));
 
-        GridSqlElement[] rdcExps = new GridSqlElement[srcQry.visibleColumns()];
+        GridSqlElement[] rdcExps = new GridSqlElement[mapQry.visibleColumns()];
 
         Set<String> colNames = new HashSet<>();
 
@@ -162,66 +170,56 @@ public class GridSqlQuerySplitter {
             rdcQry.addSelectExpression(column(((GridSqlAlias)mapExps.get(i)).alias()), false);
 
         // -- GROUP BY
-        if (srcQry.hasGroupBy()) {
-            mapQry.clearGroups();
-
-            for (int col : srcQry.groupColumns())
-                mapQry.addGroupExpression(column(((GridSqlAlias)mapExps.get(col)).alias()));
-
-            if (!collocated) {
-                for (int col : srcQry.groupColumns())
-                    rdcQry.addGroupExpression(column(((GridSqlAlias)mapExps.get(col)).alias()));
-            }
-        }
+        if (mapQry.groupColumns() != null && !collocated)
+            rdcQry.groupColumns(mapQry.groupColumns());
 
         // -- HAVING
-        if (srcQry.having() != null && !collocated) {
-            // TODO Find aggregate functions in HAVING clause.
-            rdcQry.whereAnd(column(columnName(srcQry.havingColumn())));
+        if (mapQry.havingColumn() >= 0 && !collocated) {
+            // TODO Find aggregate functions in HAVING clause or rewrite query to put all aggregates to SELECT clause.
+            rdcQry.whereAnd(column(columnName(mapQry.havingColumn())));
 
-            mapQry.having(null);
+            mapQry.havingColumn(-1);
         }
 
         // -- ORDER BY
-        if (!srcQry.sort().isEmpty()) {
+        if (!mapQry.sort().isEmpty()) {
+            for (GridSqlSortColumn sortCol : mapQry.sort())
+                rdcQry.addSort(sortCol);
+
             if (aggregateFound) // Ordering over aggregates does not make sense.
                 mapQry.clearSort(); // Otherwise map sort will be used by offset-limit.
-
-            for (GridSqlSortColumn sortCol : srcQry.sort())
-                rdcQry.addSort(sortCol);
+            // TODO Check if sorting is done over aggregated expression, otherwise we can sort and use offset-limit.
         }
 
         // -- LIMIT
-        if (srcQry.limit() != null) {
+        if (mapQry.limit() != null) {
+            rdcQry.limit(mapQry.limit());
+
             if (aggregateFound)
                 mapQry.limit(null);
-
-            rdcQry.limit(srcQry.limit());
         }
 
         // -- OFFSET
-        if (srcQry.offset() != null) {
-            mapQry.offset(null);
+        if (mapQry.offset() != null) {
+            rdcQry.offset(mapQry.offset());
 
-            rdcQry.offset(srcQry.offset());
+            mapQry.offset(null);
         }
 
         // -- DISTINCT
-        if (srcQry.distinct()) {
-            mapQry.distinct(false);
+        if (mapQry.distinct()) {
+            mapQry.distinct(!aggregateFound && mapQry.groupColumns() == null && mapQry.havingColumn() < 0);
             rdcQry.distinct(true);
         }
 
         // Build resulting two step query.
-        GridCacheTwoStepQuery res = new GridCacheTwoStepQuery(
-            collectAllSpaces(qry0, new HashSet<String>()),
-            rdcQry.getSQL(),
+        GridCacheTwoStepQuery res = new GridCacheTwoStepQuery(spaces, rdcQry.getSQL(),
             findParams(rdcQry, params, new ArrayList<>()).toArray());
 
         res.addMapQuery(mergeTable, mapQry.getSQL(),
             findParams(mapQry, params, new ArrayList<>(params.length)).toArray());
 
-        res.explain(qry0.explain());
+        res.explain(explain);
 
         return res;
     }
@@ -229,19 +227,27 @@ public class GridSqlQuerySplitter {
     /**
      * @param qry Query.
      * @param spaces Space names.
-     * @return Space names.
+     * @return Query.
      */
-    private static Set<String> collectAllSpaces(GridSqlQuery qry, Set<String> spaces) {
+    private static GridSqlQuery collectAllSpaces(GridSqlQuery qry, Set<String> spaces) {
         if (qry instanceof GridSqlUnion) {
             GridSqlUnion union = (GridSqlUnion)qry;
 
             collectAllSpaces(union.left(), spaces);
             collectAllSpaces(union.right(), spaces);
         }
-        else
-            collectAllSpacesInFrom(((GridSqlSelect)qry).from(), spaces);
+        else {
+            GridSqlSelect select = (GridSqlSelect)qry;
+
+            collectAllSpacesInFrom(select.from(), spaces);
+
+            for (GridSqlElement el : select.select(false))
+                collectAllSpacesInSubqueries(el, spaces);
+
+            collectAllSpacesInSubqueries(select.where(), spaces);
+        }
 
-        return spaces;
+        return qry;
     }
 
     /**
@@ -271,6 +277,23 @@ public class GridSqlQuerySplitter {
     }
 
     /**
+     * Searches spaces in subqueries in SELECT and WHERE clauses.
+     * @param el Element.
+     * @param spaces Space names.
+     */
+    private static void collectAllSpacesInSubqueries(GridSqlElement el, Set<String> spaces) {
+        if (el instanceof GridSqlAlias)
+            el = el.child();
+
+        if (el instanceof GridSqlOperation || el instanceof GridSqlFunction || el instanceof GridSqlAggregateFunction) {
+            for (GridSqlElement child : el)
+                collectAllSpacesInSubqueries(child, spaces);
+        }
+        else if (el instanceof GridSqlSubquery)
+            collectAllSpaces(((GridSqlSubquery)el).select(), spaces);
+    }
+
+    /**
      * @param qry Select.
      * @param params Parameters.
      * @param target Extracted parameters.
@@ -307,10 +330,7 @@ public class GridSqlQuerySplitter {
         findParams(qry.from(), params, target);
         findParams(qry.where(), params, target);
 
-        for (GridSqlElement el : qry.groups())
-            findParams(el, params, target);
-
-        findParams(qry.having(), params, target);
+        // Don't search in GROUP BY and HAVING since they expected to be in select list.
 
         findParams(qry.limit(), params, target);
         findParams(qry.offset(), params, target);
@@ -362,7 +382,7 @@ public class GridSqlQuerySplitter {
      * @return {@code true} If aggregate was found.
      */
     private static boolean splitSelectExpression(List<GridSqlElement> mapSelect, GridSqlElement[] rdcSelect,
-        Set<String> colNames, int idx, boolean collocated) {
+        Set<String> colNames, final int idx, boolean collocated) {
         GridSqlElement el = mapSelect.get(idx);
 
         GridSqlAlias alias = null;
@@ -416,7 +436,6 @@ public class GridSqlQuerySplitter {
                 case MAX: // MAX( MAX(x) )
                 case MIN: // MIN( MIN(x) )
                     mapAgg = aggregate(agg.distinct(), agg.type()).addChild(agg.child());
-
                     rdcAgg = aggregate(agg.distinct(), agg.type()).addChild(column(mapAggAlias));
 
                     break;
@@ -429,7 +448,6 @@ public class GridSqlQuerySplitter {
                         mapAgg.addChild(agg.child());
 
                     rdcAgg = aggregate(false, SUM).addChild(column(mapAggAlias));
-
                     rdcAgg = function(CAST).setCastType("BIGINT").addChild(rdcAgg);
 
                     break;
@@ -469,7 +487,7 @@ public class GridSqlQuerySplitter {
                 GridSqlType type = el.expressionResultType();
 
                 if (type != null && type.type() == Value.UUID) // There is no JDBC type UUID, so conversion to bytes occurs.
-                    rdcEl = function(CAST).setCastType("UUID").addChild(rdcEl);
+                    rdcEl = function(CAST).setCastType("UUID").addChild(rdcEl); // TODO remove this cast when table function removed
 
                 if (colNames.add(rdcColAlias)) // To handle column name duplication (usually wildcard for few tables).
                     rdcEl = alias(rdcColAlias, rdcEl);

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/f1f3da8e/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlSelect.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlSelect.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlSelect.java
index 9972bba..84b0031 100644
--- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlSelect.java
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlSelect.java
@@ -32,9 +32,6 @@ public class GridSqlSelect extends GridSqlQuery {
     private List<GridSqlElement> select = new ArrayList<>();
 
     /** */
-    private List<GridSqlElement> groups = new ArrayList<>();
-
-    /** */
     private int[] grpCols;
 
     /** */
@@ -44,9 +41,6 @@ public class GridSqlSelect extends GridSqlQuery {
     private GridSqlElement where;
 
     /** */
-    private GridSqlElement having;
-
-    /** */
     private int havingCol = -1;
 
     /** {@inheritDoc} */
@@ -84,12 +78,14 @@ public class GridSqlSelect extends GridSqlQuery {
         if (where != null)
             buff.append("\nWHERE ").append(StringUtils.unEnclose(where.getSQL()));
 
-        if (!groups.isEmpty()) {
+        if (grpCols != null) {
             buff.append("\nGROUP BY ");
 
             buff.resetCount();
 
-            for (GridSqlElement expression : groups) {
+            for (int grpCol : grpCols) {
+                GridSqlElement expression = allExprs.get(grpCol);
+
                 buff.appendExceptFirst(", ");
 
                 if (expression instanceof GridSqlAlias)
@@ -99,8 +95,8 @@ public class GridSqlSelect extends GridSqlQuery {
             }
         }
 
-        if (having != null)
-            buff.append("\nHAVING ").append(StringUtils.unEnclose(having.getSQL()));
+        if (havingCol >= 0)
+            buff.append("\nHAVING ").append(StringUtils.unEnclose(allExprs.get(havingCol).getSQL()));
 
         getSortLimitSQL(buff);
 
@@ -158,38 +154,6 @@ public class GridSqlSelect extends GridSqlQuery {
     }
 
     /**
-     * @return Expressions.
-     */
-    public Iterable<GridSqlElement> groups() {
-        return groups;
-    }
-
-    /**
-     * @return {@code true} If the select has group by expression.
-     */
-    public boolean hasGroupBy() {
-        return !groups.isEmpty();
-    }
-
-    /**
-     *
-     */
-    public void clearGroups() {
-        groups = new ArrayList<>();
-        grpCols = null;
-    }
-
-    /**
-     * @param expression Expression.
-     */
-    public void addGroupExpression(GridSqlElement expression) {
-        if (expression == null)
-            throw new NullPointerException();
-
-        groups.add(expression);
-    }
-
-    /**
      * @return Group columns.
      */
     public int[] groupColumns() {
@@ -253,20 +217,15 @@ public class GridSqlSelect extends GridSqlQuery {
      * @return Having.
      */
     public GridSqlElement having() {
-        return having;
-    }
-
-    /**
-     * @param having New having.
-     */
-    public void having(GridSqlElement having) {
-        this.having = having;
+        return havingCol >= 0 ? allExprs.get(havingCol) : null;
     }
 
     /**
      * @param col Index of HAVING column.
      */
     public void havingColumn(int col) {
+        assert col >= -1 : col;
+
         havingCol = col;
     }
 
@@ -276,17 +235,4 @@ public class GridSqlSelect extends GridSqlQuery {
     public int havingColumn() {
         return havingCol;
     }
-
-    /** {@inheritDoc} */
-    @SuppressWarnings({"CloneCallsConstructors", "CloneDoesntDeclareCloneNotSupportedException"})
-    @Override public GridSqlSelect clone() {
-        GridSqlSelect res = (GridSqlSelect)super.clone();
-
-        res.groups = new ArrayList<>(groups);
-        res.grpCols =  grpCols == null ? null : grpCols.clone();
-        res.select = new ArrayList<>(select);
-        res.allExprs = new ArrayList<>(allExprs);
-
-        return res;
-    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/f1f3da8e/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 117313d..1dbcd46 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,19 +22,19 @@ package org.apache.ignite.internal.processors.query.h2.sql;
  */
 public class GridSqlType {
     /** H2 type. */
-    private int type;
+    private final int type;
 
     /** */
-    private int scale;
+    private final int scale;
 
     /** */
-    private long precision;
+    private final long precision;
 
     /** */
-    private int displaySize;
+    private final int displaySize;
 
     /** */
-    private String sql;
+    private final String sql;
 
     /**
      * @param type H2 Type.

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/f1f3da8e/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlUnion.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlUnion.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlUnion.java
index 96beb6b..721c288 100644
--- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlUnion.java
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlUnion.java
@@ -79,17 +79,6 @@ public class GridSqlUnion extends GridSqlQuery {
         return buff.toString();
     }
 
-    /** {@inheritDoc} */
-    @SuppressWarnings({"CloneCallsConstructors", "CloneDoesntDeclareCloneNotSupportedException"})
-    @Override public GridSqlUnion clone() {
-        GridSqlUnion res = (GridSqlUnion)super.clone();
-
-        res.right = right.clone();
-        res.left = left.clone();
-
-        return res;
-    }
-
     /**
      * @return Union type.
      */

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/f1f3da8e/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheCrossCacheQuerySelfTest.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheCrossCacheQuerySelfTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheCrossCacheQuerySelfTest.java
index b295c46..f94d695 100644
--- a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheCrossCacheQuerySelfTest.java
+++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheCrossCacheQuerySelfTest.java
@@ -23,17 +23,14 @@ import org.apache.ignite.cache.query.*;
 import org.apache.ignite.cache.query.annotations.*;
 import org.apache.ignite.configuration.*;
 import org.apache.ignite.internal.*;
-import org.apache.ignite.internal.processors.cache.query.*;
 import org.apache.ignite.internal.processors.query.*;
 import org.apache.ignite.internal.util.typedef.*;
-import org.apache.ignite.marshaller.optimized.*;
 import org.apache.ignite.spi.discovery.tcp.*;
 import org.apache.ignite.spi.discovery.tcp.ipfinder.*;
 import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.*;
 import org.apache.ignite.testframework.junits.common.*;
 
 import java.util.*;
-import java.util.concurrent.*;
 
 import static org.apache.ignite.cache.CacheAtomicityMode.*;
 import static org.apache.ignite.cache.CacheRebalanceMode.*;
@@ -113,37 +110,6 @@ public class GridCacheCrossCacheQuerySelfTest extends GridCommonAbstractTest {
     /**
      * @throws Exception If failed.
      */
-    public void testTwoStep() throws Exception {
-        fail("https://issues.apache.org/jira/browse/IGNITE-827");
-
-        String cache = "partitioned";
-
-        GridQueryProcessor qryProc = ((IgniteKernal) ignite).context().query();
-
-//        for (Map.Entry<Integer, FactPurchase> e : qx.createSqlQuery(FactPurchase.class, "1 = 1").execute().get())
-//            X.println("___ "  + e);
-
-        GridCacheTwoStepQuery q = new GridCacheTwoStepQuery(null,
-            "select cast(sum(x) as long) from _cnts_ where ? = ?", 1, 1);
-
-        q.addMapQuery("_cnts_", "select count(*) x from \"partitioned\".FactPurchase where ? = ?", 2, 2);
-
-        Iterator<List<?>> it = qryProc.queryTwoStep(cache, q).iterator();
-
-        try {
-            Object cnt = it.next().get(0);
-
-            assertEquals(10L, cnt);
-        }
-        finally {
-            if (it instanceof AutoCloseable)
-                ((AutoCloseable)it).close();
-        }
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
     public void testTwoStepGroupAndAggregates() throws Exception {
         IgniteInternalCache<Integer, FactPurchase> cache =
             ((IgniteKernal)ignite).getCache("partitioned");
@@ -258,42 +224,6 @@ public class GridCacheCrossCacheQuerySelfTest extends GridCommonAbstractTest {
 //        return 10 * 60 * 1000;
 //    }
 
-    public void testLoop() throws Exception {
-        fail("https://issues.apache.org/jira/browse/IGNITE-827");
-
-        final IgniteCache<Object,Object> c = ignite.cache("partitioned");
-
-        X.println("___ GET READY");
-
-        Thread.sleep(20000);
-
-        X.println("___ GO");
-
-        multithreaded(new Callable<Object>() {
-            @Override public Object call() throws Exception {
-                long start = System.currentTimeMillis();
-
-                for (int i = 0; i < 1000000; i++) {
-                    if (i % 10000 == 0) {
-                        long t = System.currentTimeMillis();
-
-                        X.println(Thread.currentThread().getId() + "__ " + i + " -> " + (t - start));
-
-                        start = t;
-                    }
-
-                    c.query(new SqlFieldsQuery("select * from FactPurchase")).getAll();
-                }
-
-                return null;
-            }
-        }, 20);
-
-        X.println("___ OK");
-
-        Thread.sleep(300000);
-    }
-
     /**
      * @param l List.
      * @param idx Index.