ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sboi...@apache.org
Subject [11/50] incubator-ignite git commit: ignite-sprint-4 - big query fix
Date Tue, 21 Apr 2015 11:01:14 GMT
ignite-sprint-4 - big query fix


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

Branch: refs/heads/ignite-648
Commit: ffddb3e9176331e99ccfb44db251f46ae1303334
Parents: a57a520
Author: S.Vladykin <svladykin@gridgain.com>
Authored: Fri Apr 17 11:32:06 2015 +0300
Committer: S.Vladykin <svladykin@gridgain.com>
Committed: Fri Apr 17 11:32:06 2015 +0300

----------------------------------------------------------------------
 .../query/h2/sql/GridSqlFunction.java           |  6 +--
 .../query/h2/sql/GridSqlPlaceholder.java        | 51 ++++++++++++++++++++
 .../query/h2/sql/GridSqlQueryParser.java        |  6 +--
 .../h2/sql/AbstractH2CompareQueryTest.java      | 49 ++++++++++++++-----
 .../query/h2/sql/GridQueryParsingTest.java      |  9 ++++
 .../query/h2/sql/H2CompareBigQueryTest.java     |  2 +-
 .../processors/query/h2/sql/bigQuery.sql        |  2 +-
 7 files changed, 104 insertions(+), 21 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/ffddb3e9/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlFunction.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlFunction.java
b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlFunction.java
index 37ed59b..9479538 100644
--- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlFunction.java
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlFunction.java
@@ -105,14 +105,14 @@ public class GridSqlFunction extends GridSqlElement {
         buff.append(Parser.quoteIdentifier(name));
 
         if (type == CASE) {
-            if (!children.isEmpty())
-                buff.append(" ").append(child().getSQL());
+            buff.append(' ').append(child().getSQL());
 
             for (int i = 1, len = children.size() - 1; i < len; i += 2) {
                 buff.append(" WHEN ").append(child(i).getSQL());
                 buff.append(" THEN ").append(child(i + 1).getSQL());
             }
-            if (children.size() % 2 == 0)
+
+            if ((children.size() & 1) == 0)
                 buff.append(" ELSE ").append(child(children.size() - 1).getSQL());
 
             return buff.append(" END").toString();

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/ffddb3e9/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlPlaceholder.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlPlaceholder.java
b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlPlaceholder.java
new file mode 100644
index 0000000..02fa7d7
--- /dev/null
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlPlaceholder.java
@@ -0,0 +1,51 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.query.h2.sql;
+
+/**
+ * Placeholder.
+ */
+public class GridSqlPlaceholder extends GridSqlElement {
+    /** */
+    public static final GridSqlPlaceholder EMPTY = new GridSqlPlaceholder("");
+
+    /** */
+    private final String sql;
+
+    /**
+     * @param sql SQL.
+     */
+    public GridSqlPlaceholder(String sql) {
+        this.sql = sql;
+    }
+
+    /** {@inheritDoc} */
+    @Override public String getSQL() {
+        return sql;
+    }
+
+    /** {@inheritDoc} */
+    @Override public GridSqlElement addChild(GridSqlElement expr) {
+        throw new IllegalStateException();
+    }
+
+    /** {@inheritDoc} */
+    @Override public GridSqlElement child(int idx) {
+        throw new IllegalStateException();
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/ffddb3e9/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 3817c1a..62ec72f 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
@@ -522,10 +522,10 @@ public class GridSqlQueryParser {
                         if (f.getFunctionType() != Function.CASE)
                             throw new IllegalStateException("Function type with null arg:
" + f.getFunctionType());
 
-                        continue;
+                        res.addChild(GridSqlPlaceholder.EMPTY);
                     }
-
-                    res.addChild(parseExpression(arg));
+                    else
+                        res.addChild(parseExpression(arg));
                 }
             }
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/ffddb3e9/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/sql/AbstractH2CompareQueryTest.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/sql/AbstractH2CompareQueryTest.java
b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/sql/AbstractH2CompareQueryTest.java
index 2caeab8..d71e3fd 100644
--- a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/sql/AbstractH2CompareQueryTest.java
+++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/sql/AbstractH2CompareQueryTest.java
@@ -21,6 +21,7 @@ import org.apache.ignite.*;
 import org.apache.ignite.cache.*;
 import org.apache.ignite.cache.query.*;
 import org.apache.ignite.configuration.*;
+import org.apache.ignite.internal.util.typedef.*;
 import org.apache.ignite.internal.util.typedef.internal.*;
 import org.apache.ignite.marshaller.optimized.*;
 import org.apache.ignite.spi.discovery.tcp.*;
@@ -259,7 +260,14 @@ public abstract class AbstractH2CompareQueryTest extends GridCommonAbstractTest
 
             rs = st.executeQuery();
 
-            int colCnt = rs.getMetaData().getColumnCount();
+            ResultSetMetaData meta = rs.getMetaData();
+
+            int colCnt = meta.getColumnCount();
+
+            for (int i = 1; i <= colCnt; i++)
+                X.print(meta.getColumnLabel(i) + "  ");
+
+            X.println();
 
             while (rs.next()) {
                 List<Object> row = new ArrayList<>(colCnt);
@@ -302,18 +310,30 @@ public abstract class AbstractH2CompareQueryTest extends GridCommonAbstractTest
 
                 break;
             case RANDOM:
-                Map<List<?>, Integer> rowsWithCnt1 = extractUniqueRowsWithCounts(rs1);
-                Map<List<?>, Integer> rowsWithCnt2 = extractUniqueRowsWithCounts(rs2);
-                
+                TreeMap<String, Integer> rowsWithCnt1 = extractUniqueRowsWithCounts(rs1);
+                TreeMap<String, Integer> rowsWithCnt2 = extractUniqueRowsWithCounts(rs2);
+
                 assertEquals("Unique rows count has to be equal.", rowsWithCnt1.size(), rowsWithCnt2.size());
 
-                for (Map.Entry<List<?>, Integer> entry1 : rowsWithCnt1.entrySet())
{
-                    List<?> row = entry1.getKey();
-                    Integer cnt1 = entry1.getValue();
+                X.println("Result size: " + rowsWithCnt1.size());
+
+                Iterator<Map.Entry<String,Integer>> iter1 = rowsWithCnt1.entrySet().iterator();
+                Iterator<Map.Entry<String,Integer>> iter2 = rowsWithCnt2.entrySet().iterator();
 
-                    Integer cnt2 = rowsWithCnt2.get(row);
+                for (;;) {
+                    if (!iter1.hasNext()) {
+                        assertFalse(iter2.hasNext());
 
-                    assertEquals("Row has different occurance number.\nRow=" + row, cnt1,
cnt2);
+                        break;
+                    }
+
+                    assertTrue(iter2.hasNext());
+
+                    Map.Entry<String,Integer> e1 = iter1.next();
+                    Map.Entry<String,Integer> e2 = iter2.next();
+
+                    assertEquals(e1.getKey(), e2.getKey());
+                    assertEquals(e1.getValue(), e2.getValue());
                 }
                 
                 break;
@@ -326,17 +346,20 @@ public abstract class AbstractH2CompareQueryTest extends GridCommonAbstractTest
      * @param rs Result set.
      * @return Map of unique rows at the result set to number of occuriances at the result
set.
      */
-    private Map<List<?>, Integer> extractUniqueRowsWithCounts(Iterable<List<?>>
rs) {
-        Map<List<?>, Integer> res = new HashMap<>();
+    private TreeMap<String, Integer> extractUniqueRowsWithCounts(Iterable<List<?>>
rs) {
+        TreeMap<String, Integer> res = new TreeMap<>();
 
         for (List<?> row : rs) {
-            Integer cnt = res.get(row);
+            String rowStr = row.toString();
+
+            Integer cnt = res.get(rowStr);
             
             if (cnt == null)
                 cnt = 0;
             
-            res.put(row, cnt + 1);
+            res.put(rowStr, cnt + 1);
         }
+
         return res;
     }
     

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/ffddb3e9/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 66ba6ac..e8b3c61 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
@@ -199,6 +199,15 @@ public class GridQueryParsingTest extends GridCommonAbstractTest {
 
         checkQuery("select p.name n from \"\".Person p order by p.old + 10");
 
+        checkQuery("select case when p.name is null then 'Vasya' end x from \"\".Person p");
+        checkQuery("select case when p.name like 'V%' then 'Vasya' else 'Other' end x from
\"\".Person p");
+        checkQuery("select case when upper(p.name) = 'VASYA' then 'Vasya' when p.name is
not null then p.name else 'Other' end x from \"\".Person p");
+
+        checkQuery("select case p.name when 'Vasya' then 1 end z from \"\".Person p");
+        checkQuery("select case p.name when 'Vasya' then 1 when 'Petya' then 2 end z from
\"\".Person p");
+        checkQuery("select case p.name when 'Vasya' then 1 when 'Petya' then 2 else 3 end
z from \"\".Person p");
+        checkQuery("select case p.name when 'Vasya' then 1 else 3 end z from \"\".Person
p");
+
         checkQuery("select count(*) as a from Person union select count(*) as a from Address");
         checkQuery("select old, count(*) as a from Person group by old union select 1, count(*)
as a from Address");
         checkQuery("select name from Person MINUS select street from Address");

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/ffddb3e9/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/sql/H2CompareBigQueryTest.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/sql/H2CompareBigQueryTest.java
b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/sql/H2CompareBigQueryTest.java
index 9cff4b5..e015aba 100644
--- a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/sql/H2CompareBigQueryTest.java
+++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/sql/H2CompareBigQueryTest.java
@@ -230,7 +230,7 @@ public class H2CompareBigQueryTest extends AbstractH2CompareQueryTest
{
         
         assertTrue(!res.isEmpty()); // Ensure we set good testing data at database.
     }
-    
+
     /** {@inheritDoc} */
     @Override protected Statement initializeH2Schema() throws SQLException {
         Statement st = super.initializeH2Schema();

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/ffddb3e9/modules/indexing/src/test/resources/org/apache/ignite/internal/processors/query/h2/sql/bigQuery.sql
----------------------------------------------------------------------
diff --git a/modules/indexing/src/test/resources/org/apache/ignite/internal/processors/query/h2/sql/bigQuery.sql
b/modules/indexing/src/test/resources/org/apache/ignite/internal/processors/query/h2/sql/bigQuery.sql
index 5f5cb74..efa768c 100644
--- a/modules/indexing/src/test/resources/org/apache/ignite/internal/processors/query/h2/sql/bigQuery.sql
+++ b/modules/indexing/src/test/resources/org/apache/ignite/internal/processors/query/h2/sql/bigQuery.sql
@@ -50,6 +50,6 @@ inner join (
   group by e.date, e.rootOrderId
 ) oep on (cop.date = oep.date and cop.custOrderId = oep.eRootOrderId)
 left outer join (
-  select top 1 refOrderId, date from "part".Cancel
+  select top 1 refOrderId, date from "part".Cancel order by date desc
 ) cc on (cc.refOrderId = cop.orderId and cc.date = cop.date)
 where cop.alias='CUSTOM'


Mime
View raw message