ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From se...@apache.org
Subject [1/2] ignite git commit: ignite-3860 - parsing fixed
Date Tue, 21 Feb 2017 23:32:22 GMT
Repository: ignite
Updated Branches:
  refs/heads/ignite-1.9 a16016257 -> 437f37469


ignite-3860 - parsing fixed


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

Branch: refs/heads/ignite-1.9
Commit: efb866803e9831c86b1c4b1bab93cf12076c8a73
Parents: bf337bc
Author: Sergi Vladykin <sergi.vladykin@gmail.com>
Authored: Wed Feb 22 02:31:54 2017 +0300
Committer: Sergi Vladykin <sergi.vladykin@gmail.com>
Committed: Wed Feb 22 02:31:54 2017 +0300

----------------------------------------------------------------------
 .../query/h2/sql/GridSqlQueryParser.java        | 20 +++++++++-----
 .../query/h2/sql/GridQueryParsingTest.java      | 28 ++++++++++++++++++++
 2 files changed, 41 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/efb86680/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 f5ad397..024529c 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
@@ -344,7 +344,7 @@ public class GridSqlQueryParser {
     /**
      * @param filter Filter.
      */
-    private GridSqlElement parseTable(TableFilter filter) {
+    private GridSqlElement parseTableFilter(TableFilter filter) {
         GridSqlElement res = (GridSqlElement)h2ObjToGridObj.get(filter);
 
         if (res == null) {
@@ -369,9 +369,15 @@ public class GridSqlQueryParser {
         GridSqlElement res = (GridSqlElement)h2ObjToGridObj.get(tbl);
 
         if (res == null) {
+            // We can't cache simple tables because otherwise it will be the same instance
for all
+            // table filters. Thus we will not be able to distinguish one table filter from
another.
+            // Table here is semantically equivalent to a table filter.
             if (tbl instanceof TableBase)
-                res = new GridSqlTable(tbl);
-            else if (tbl instanceof TableView) {
+                return new GridSqlTable(tbl);
+
+            // Other stuff can be cached because we will have separate instances in
+            // different table filters anyways. Thus the semantics will be correct.
+            if (tbl instanceof TableView) {
                 Query qry = VIEW_QUERY.get((TableView) tbl);
 
                 res = new GridSqlSubquery(parseQuery(qry));
@@ -438,7 +444,7 @@ public class GridSqlQueryParser {
 
         for (int i = 0; i < tableFilters.size(); i++) {
             TableFilter f = tableFilters.get(i);
-            GridSqlElement gridFilter = parseTable(f);
+            GridSqlElement gridFilter = parseTableFilter(f);
 
             from = from == null ? gridFilter : new GridSqlJoin(from, gridFilter, f.isJoinOuter(),
                 parseExpression(f.getJoinCondition(), false));
@@ -606,7 +612,7 @@ public class GridSqlQueryParser {
         res = new GridSqlDelete();
         h2ObjToGridObj.put(del, res);
 
-        GridSqlElement tbl = parseTable(DELETE_FROM.get(del));
+        GridSqlElement tbl = parseTableFilter(DELETE_FROM.get(del));
         GridSqlElement where = parseExpression(DELETE_WHERE.get(del), true);
         GridSqlElement limit = parseExpression(DELETE_LIMIT.get(del), true);
         res.from(tbl).where(where).limit(limit);
@@ -626,7 +632,7 @@ public class GridSqlQueryParser {
         res = new GridSqlUpdate();
         h2ObjToGridObj.put(update, res);
 
-        GridSqlElement tbl = parseTable(UPDATE_TARGET.get(update));
+        GridSqlElement tbl = parseTableFilter(UPDATE_TARGET.get(update));
 
         List<Column> srcCols = UPDATE_COLUMNS.get(update);
         Map<Column, Expression> srcSet = UPDATE_SET.get(update);
@@ -826,7 +832,7 @@ public class GridSqlQueryParser {
             ExpressionColumn expCol = (ExpressionColumn)expression;
 
             return new GridSqlColumn(expCol.getColumn(),
-                parseTable(expCol.getTableFilter()),
+                parseTableFilter(expCol.getTableFilter()),
                 SCHEMA_NAME.get(expCol),
                 expCol.getOriginalTableAliasName(),
                 expCol.getColumnName());

http://git-wip-us.apache.org/repos/asf/ignite/blob/efb86680/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/sql/GridQueryParsingTest.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/sql/GridQueryParsingTest.java
b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/sql/GridQueryParsingTest.java
index d3ff902..b869da9 100644
--- a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/sql/GridQueryParsingTest.java
+++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/sql/GridQueryParsingTest.java
@@ -283,6 +283,34 @@ public class GridQueryParsingTest extends GridCommonAbstractTest {
         checkQuery("select sch.\"#\".* from Person \"#\"");
     }
 
+    /**
+     * Query AST transformation heavily depends on this behavior.
+     *
+     * @throws Exception If failed.
+     */
+    public void testParseTableFilter() throws Exception {
+        Prepared prepared = parse("select Person.old, p1.old from Person, Person p1");
+
+        GridSqlSelect select = (GridSqlSelect)new GridSqlQueryParser(false).parse(prepared);
+
+        GridSqlJoin join = (GridSqlJoin)select.from();
+
+        GridSqlTable tbl1 = (GridSqlTable)join.leftTable();
+        GridSqlAlias tbl2Alias = (GridSqlAlias)join.rightTable();
+        GridSqlTable tbl2 = tbl2Alias.child();
+
+        // Must be distinct objects, even if it is the same table.
+        assertNotSame(tbl1, tbl2);
+
+        GridSqlColumn col1 = (GridSqlColumn)select.column(0);
+        GridSqlColumn col2 = (GridSqlColumn)select.column(1);
+
+        assertSame(tbl1, col1.expressionInFrom());
+
+        // Alias in FROM must be included in column.
+        assertSame(tbl2Alias, col2.expressionInFrom());
+    }
+
     /** */
     public void testParseMerge() throws Exception {
         /* Plain rows w/functions, operators, defaults, and placeholders. */


Mime
View raw message