ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From se...@apache.org
Subject [48/50] [abbrv] incubator-ignite git commit: #ignite-sql-tests - test fix x
Date Thu, 05 Feb 2015 13:43:14 GMT
#ignite-sql-tests - test fix x


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

Branch: refs/heads/ignite-sql-tests
Commit: 684b1a74aa6d76c083d0096d2b1a2adb01b38700
Parents: 202f90f
Author: S.Vladykin <svladykin@gridgain.com>
Authored: Thu Feb 5 15:32:14 2015 +0300
Committer: S.Vladykin <svladykin@gridgain.com>
Committed: Thu Feb 5 15:32:14 2015 +0300

----------------------------------------------------------------------
 .../ignite/cache/query/QuerySqlPredicate.java   | 17 ++++-
 .../ignite/cache/query/QueryTextPredicate.java  |  4 +-
 .../processors/cache/IgniteCacheProxy.java      | 24 +++++++
 .../query/h2/sql/GridSqlQueryParser.java        | 23 ++++++
 .../cache/IgniteCacheAbstractQuerySelfTest.java | 74 +++++++++-----------
 .../cache/IgniteCacheQueryLoadSelfTest.java     |  6 +-
 6 files changed, 104 insertions(+), 44 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/684b1a74/modules/core/src/main/java/org/apache/ignite/cache/query/QuerySqlPredicate.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/cache/query/QuerySqlPredicate.java
b/modules/core/src/main/java/org/apache/ignite/cache/query/QuerySqlPredicate.java
index 061b2a0..a235985 100644
--- a/modules/core/src/main/java/org/apache/ignite/cache/query/QuerySqlPredicate.java
+++ b/modules/core/src/main/java/org/apache/ignite/cache/query/QuerySqlPredicate.java
@@ -134,7 +134,22 @@ public final class QuerySqlPredicate extends QueryPredicate {
      * @param type Type.
      */
     public void setType(Class<?> type) {
-        this.type = type == null ? null : type.getSimpleName();
+        setType(name(type));
+    }
+
+    /**
+     * @param type Type class.
+     * @return Type name.
+     */
+    static String name(Class<?> type) {
+        if (type == null)
+            return null;
+
+        String name = type.getName();
+
+        int dot = name.lastIndexOf('.');
+
+        return dot == -1 ? name : name.substring(dot + 1);
     }
 
     /** {@inheritDoc} */

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/684b1a74/modules/core/src/main/java/org/apache/ignite/cache/query/QueryTextPredicate.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/cache/query/QueryTextPredicate.java
b/modules/core/src/main/java/org/apache/ignite/cache/query/QueryTextPredicate.java
index 4064f64..c3765cc 100644
--- a/modules/core/src/main/java/org/apache/ignite/cache/query/QueryTextPredicate.java
+++ b/modules/core/src/main/java/org/apache/ignite/cache/query/QueryTextPredicate.java
@@ -19,6 +19,8 @@ package org.apache.ignite.cache.query;
 
 import org.apache.ignite.internal.util.typedef.internal.*;
 
+import static org.apache.ignite.cache.query.QuerySqlPredicate.name;
+
 /**
  * Predicate for Lucene based fulltext search.
  */
@@ -62,7 +64,7 @@ public final class QueryTextPredicate extends QueryPredicate {
      * @param type Type.
      */
     public void setType(Class<?> type) {
-        setType(type == null ? null : type.getSimpleName());
+        setType(name(type));
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/684b1a74/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheProxy.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheProxy.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheProxy.java
index 87fe0b7..0665ca8 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheProxy.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheProxy.java
@@ -321,6 +321,12 @@ public class IgniteCacheProxy<K, V> extends IgniteAsyncSupportAdapter<IgniteCach
 
             return query(filter, null);
         }
+        catch (Exception e) {
+            if (e instanceof CacheException)
+                throw e;
+
+            throw new CacheException(e);
+        }
         finally {
             gate.leave(prev);
         }
@@ -335,6 +341,12 @@ public class IgniteCacheProxy<K, V> extends IgniteAsyncSupportAdapter<IgniteCach
         try {
             return ctx.kernalContext().query().queryTwoStep(ctx.name(), filter.getSql(),
filter.getArgs());
         }
+        catch (Exception e) {
+            if (e instanceof CacheException)
+                throw e;
+
+            throw new CacheException(e);
+        }
         finally {
             gate.leave(prev);
         }
@@ -356,6 +368,12 @@ public class IgniteCacheProxy<K, V> extends IgniteAsyncSupportAdapter<IgniteCach
 
             return query(filter, ctx.kernalContext().grid().forLocal());
         }
+        catch (Exception e) {
+            if (e instanceof CacheException)
+                throw e;
+
+            throw new CacheException(e);
+        }
         finally {
             gate.leave(prev);
         }
@@ -371,6 +389,12 @@ public class IgniteCacheProxy<K, V> extends IgniteAsyncSupportAdapter<IgniteCach
             return new QueryCursorImpl<>(ctx.kernalContext().query().queryLocalFields(
                 ctx.name(), filter.getSql(), filter.getArgs()));
         }
+        catch (Exception e) {
+            if (e instanceof CacheException)
+                throw e;
+
+            throw new CacheException(e);
+        }
         finally {
             gate.leave(prev);
         }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/684b1a74/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 2865db9..7b2cd49 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
@@ -130,6 +130,12 @@ public class GridSqlQueryParser {
     private static final Getter<Aggregate, Expression> ON = getter(Aggregate.class,
"on");
 
     /** */
+    private static final Getter<RangeTable, Expression> RANGE_MIN = getter(RangeTable.class,
"min");
+
+    /** */
+    private static final Getter<RangeTable, Expression> RANGE_MAX = getter(RangeTable.class,
"max");
+
+    /** */
     private final IdentityHashMap<Object, Object> h2ObjToGridObj = new IdentityHashMap<>();
 
     /**
@@ -161,6 +167,12 @@ public class GridSqlQueryParser {
 
                 res = new GridSqlSubquery(parse((Select)qry));
             }
+            else if (tbl instanceof RangeTable) {
+                res = new GridSqlFunction("SYSTEM_RANGE");
+
+                res.addChild(parseExpression(RANGE_MIN.get((RangeTable)tbl)));
+                res.addChild(parseExpression(RANGE_MAX.get((RangeTable)tbl)));
+            }
             else
                 throw new IgniteException("Unsupported query: " + filter);
 
@@ -428,6 +440,17 @@ public class GridSqlQueryParser {
             return res;
         }
 
+        if (expression instanceof JavaFunction) {
+            JavaFunction f = (JavaFunction)expression;
+
+            GridSqlFunction res = new GridSqlFunction(f.getName());
+
+            for (Expression arg : f.getArgs())
+                res.addChild(parseExpression(arg));
+
+            return res;
+        }
+
         if (expression instanceof Parameter)
             return new GridSqlParameter(((Parameter)expression).getIndex());
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/684b1a74/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheAbstractQuerySelfTest.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheAbstractQuerySelfTest.java
b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheAbstractQuerySelfTest.java
index 212514e..e1fd827 100644
--- a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheAbstractQuerySelfTest.java
+++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheAbstractQuerySelfTest.java
@@ -234,7 +234,7 @@ public abstract class IgniteCacheAbstractQuerySelfTest extends GridCommonAbstrac
         cache.put(key, val);
 
         QueryCursor<Cache.Entry<String, Integer>> qry =
-            cache.query(new QuerySqlPredicate(Integer.class, "where _key = 'k' and _val >
1"));
+            cache.query(new QuerySqlPredicate(Integer.class, "_key = 'k' and _val > 1"));
 
         Cache.Entry<String, Integer> entry = F.first(qry.getAll());
 
@@ -250,7 +250,7 @@ public abstract class IgniteCacheAbstractQuerySelfTest extends GridCommonAbstrac
      */
     public void testUserDefinedFunction() throws IgniteCheckedException {
         // Without alias.
-        IgniteCache<Object, Object> cache = ignite.jcache(null);
+        final IgniteCache<Object, Object> cache = ignite.jcache(null);
 
         QueryCursor<List<?>> qry = cache.queryFields(new QuerySqlPredicate("select
square(1), square(2)"));
 
@@ -276,13 +276,11 @@ public abstract class IgniteCacheAbstractQuerySelfTest extends GridCommonAbstrac
         assertEquals(8, row.get(1));
 
         // Not registered.
-        final QueryCursor<List<?>> qry3 = cache.queryFields(new QuerySqlPredicate("select
no()"));
-
         GridTestUtils.assertThrows(
             log,
             new Callable<Object>() {
                 @Override public Object call() throws Exception {
-                    qry3.getAll();
+                    cache.queryFields(new QuerySqlPredicate("select no()"));
 
                     return null;
                 }
@@ -303,15 +301,15 @@ public abstract class IgniteCacheAbstractQuerySelfTest extends GridCommonAbstrac
 
         IgniteCache<String, Integer> cache = ignite.jcache(null);
 
-        QueryCursor<Cache.Entry<String, Integer>> qry = cache.query(new QuerySqlPredicate(Integer.class,
"1=1"));
+        List<Cache.Entry<String, Integer>> qry = cache.query(new QuerySqlPredicate(Integer.class,
"1=1")).getAll();
 
-        Cache.Entry<String, Integer> res = F.first(qry.getAll());
+        Cache.Entry<String, Integer> res = F.first(qry);
 
         assertEquals(1, res.getValue().intValue());
 
         U.sleep(1020);
 
-        res = F.first(qry.getAll());
+        res = F.first(qry);
 
         assertNull(res);
     }
@@ -325,7 +323,7 @@ public abstract class IgniteCacheAbstractQuerySelfTest extends GridCommonAbstrac
         cache.put(1, 1);
         cache.put(2, 2);
 
-        QueryCursor<List<?>> qry = cache.queryFields(new QuerySqlPredicate(Integer.class,
"_key between 2 and 1"));
+        QueryCursor<Cache.Entry<Integer,Integer>> qry = cache.query(new QuerySqlPredicate(Integer.class,
"_key between 2 and 1"));
 
         assertTrue(qry.getAll().isEmpty());
     }
@@ -442,7 +440,7 @@ public abstract class IgniteCacheAbstractQuerySelfTest extends GridCommonAbstrac
         for (int i = 0; i < expCnt; i++)
             assert iter.next() != null;
 
-        assert iter.next() == null;
+        assert !iter.hasNext();
 
         qry = cache.query(new QueryTextPredicate(ObjectValue.class, "test"));
 
@@ -453,7 +451,7 @@ public abstract class IgniteCacheAbstractQuerySelfTest extends GridCommonAbstrac
         for (int i = 0; i < expCnt; i++)
             assert iter.next() != null;
 
-        assert iter.next() == null;
+        assert !iter.hasNext();
     }
 
     /**
@@ -501,7 +499,9 @@ public abstract class IgniteCacheAbstractQuerySelfTest extends GridCommonAbstrac
 
         Cache.Entry<Integer, ObjectValue> next;
 
-        while ((next = iter.next()) != null) {
+        while (iter.hasNext()) {
+            next = iter.next();
+            
             ObjectValue v = next.getValue();
 
             assert !set.contains(v.intValue());
@@ -509,7 +509,7 @@ public abstract class IgniteCacheAbstractQuerySelfTest extends GridCommonAbstrac
             set.add(v.intValue());
         }
 
-        assert iter.next() == null;
+        assert !iter.hasNext();
 
         assertEquals(cnt, set.size());
 
@@ -532,7 +532,7 @@ public abstract class IgniteCacheAbstractQuerySelfTest extends GridCommonAbstrac
             set.add(v.intValue());
         }
 
-        assert iter.next() == null;
+        assert !iter.hasNext();
 
         assertEquals(cnt / 2, set.size());
 
@@ -553,11 +553,11 @@ public abstract class IgniteCacheAbstractQuerySelfTest extends GridCommonAbstrac
 
         // Try to execute on empty cache first.
         QueryCursor<Cache.Entry<Integer, ObjectValue>> qry =
-            cache.query(new QuerySqlPredicate(ObjectValue.class, "full"));
+            cache.query(new QueryTextPredicate(ObjectValue.class, "full"));
 
         assert qry.getAll().isEmpty();
 
-        qry = cache.query(new QuerySqlPredicate(ObjectValue.class, "full"));
+        qry = cache.query(new QueryTextPredicate(ObjectValue.class, "full"));
 
         assert qry.getAll().isEmpty();
 
@@ -574,7 +574,7 @@ public abstract class IgniteCacheAbstractQuerySelfTest extends GridCommonAbstrac
 
         cache.put(key2, val2);
 
-        qry = cache.query(new QuerySqlPredicate(ObjectValue.class, "full"));
+        qry = cache.query(new QueryTextPredicate(ObjectValue.class, "full"));
 
         Collection<Cache.Entry<Integer, ObjectValue>> res = qry.getAll();
 
@@ -582,7 +582,7 @@ public abstract class IgniteCacheAbstractQuerySelfTest extends GridCommonAbstrac
 
         assert res.size() == 2;
 
-        qry = cache.query(new QuerySqlPredicate(ObjectValue.class, "full"));
+        qry = cache.query(new QueryTextPredicate(ObjectValue.class, "full"));
 
         res = qry.getAll();
 
@@ -652,7 +652,7 @@ public abstract class IgniteCacheAbstractQuerySelfTest extends GridCommonAbstrac
             assertEquals("value", e1.getValue());
         }
 
-        assert iter.next() == null;
+        assert !iter.hasNext();
     }
 
     /**
@@ -851,7 +851,7 @@ public abstract class IgniteCacheAbstractQuerySelfTest extends GridCommonAbstrac
         cache.put(key, val);
 
         QueryCursor<Cache.Entry<String, Integer>> qry = cache.query(new QuerySqlPredicate(Integer.class,
-                "where _key = 'k' and _val > 1"));
+                "_key = 'k' and _val > 1"));
 
         Cache.Entry<String, Integer> entry = F.first(qry.getAll());
 
@@ -904,22 +904,22 @@ public abstract class IgniteCacheAbstractQuerySelfTest extends GridCommonAbstrac
             }
         };
 
-        assertTrue(val.getClass().getName().endsWith("GridCacheAbstractQuerySelfTest$16"));
+        assertTrue(val.getClass().getName(), val.getClass().getName().endsWith("IgniteCacheAbstractQuerySelfTest$5"));
 
         cache.put(1, val);
 
-        QueryCursor<Cache.Entry<Integer, Object>> q = cache.query(new QuerySqlPredicate(Object.class,
"_key >= 0"));
+        QueryCursor<Cache.Entry<Integer, Object>> q = cache.query(new QuerySqlPredicate(val.getClass(),
"_key >= 0"));
 
         Collection<Cache.Entry<Integer, Object>> res = q.getAll();
 
         assertEquals(1, res.size());
 
-        QueryCursor<List<?>> fieldsRes = cache.queryFields(new QuerySqlPredicate(
-                "select field1 from GridCacheAbstractQuerySelfTest_16"));
+        List<List<?>> fieldsRes = cache.queryFields(new QuerySqlPredicate(
+                "select field1 from IgniteCacheAbstractQuerySelfTest_5")).getAll();
 
-        assertEquals(1, fieldsRes.getAll());
+        assertEquals(1, fieldsRes.size());
 
-        List<?> fields = F.first(fieldsRes.getAll());
+        List<?> fields = F.first(fieldsRes);
 
         assertEquals(1, fields.size());
         assertEquals(10, fields.get(0));
@@ -946,7 +946,7 @@ public abstract class IgniteCacheAbstractQuerySelfTest extends GridCommonAbstrac
         cache.put(1, val1);
         cache.put(2, val2);
 
-        QueryCursor<Cache.Entry<Integer, Object>> q = cache.query(new QuerySqlPredicate(Object.class,
"_key >= 0"));
+        QueryCursor<Cache.Entry<Integer, Object>> q = cache.query(new QuerySqlPredicate(val1.getClass(),
"_key >= 0"));
 
         Collection<Cache.Entry<Integer, Object>> res = q.getAll();
 
@@ -993,25 +993,21 @@ public abstract class IgniteCacheAbstractQuerySelfTest extends GridCommonAbstrac
             cache.put(i, i);
 
         QueryCursor<Cache.Entry<Integer, Integer>> q =
-                cache.query(new QuerySqlPredicate(Integer.class, "_key >= 0"));
+                cache.query(new QuerySqlPredicate(Integer.class, "limit 5"));
 
         Collection<Cache.Entry<Integer, Integer>> res = q.getAll();
 
-        assertEquals(10, res.size());
+        assertEquals(5, res.size());
 
-        if (cacheMode() != PARTITIONED) {
-            assertEquals(5, res.size());
+        Iterator<Cache.Entry<Integer, Integer>> it = res.iterator();
 
-            Iterator<Cache.Entry<Integer, Integer>> it = res.iterator();
+        for (Integer i = 0; i < 5; i++) {
+            assertTrue(it.hasNext());
 
-            for (Integer i = 0; i < 5; i++) {
-                assertTrue(it.hasNext());
+            Cache.Entry<Integer, Integer> e = it.next();
 
-                Cache.Entry<Integer, Integer> e = it.next();
-
-                assertEquals(i, e.getKey());
-                assertEquals(i, e.getValue());
-            }
+            assertEquals(i, e.getKey());
+            assertEquals(i, e.getValue());
         }
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/684b1a74/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheQueryLoadSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheQueryLoadSelfTest.java
b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheQueryLoadSelfTest.java
index 9c6dd18..b0e286b 100644
--- a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheQueryLoadSelfTest.java
+++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheQueryLoadSelfTest.java
@@ -113,7 +113,7 @@ public class IgniteCacheQueryLoadSelfTest extends GridCommonAbstractTest
{
      * @throws Exception If failed.
      */
     public void testLoadCache() throws Exception {
-        IgniteCache<Integer, ValueObject> cache = grid(0).jcache(null);
+        IgniteCache<Integer, ValueObject> cache = grid().jcache(null);
 
         cache.loadCache(null, 0);
 
@@ -151,7 +151,7 @@ public class IgniteCacheQueryLoadSelfTest extends GridCommonAbstractTest
{
      * @throws Exception If failed.
      */
     public void testLoadCacheFiltered() throws Exception {
-        IgniteCache<Integer, ValueObject> cache = grid(0).jcache(null);
+        IgniteCache<Integer, ValueObject> cache = grid().jcache(null);
 
         cache.loadCache(new P2<Integer, ValueObject>() {
             @Override public boolean apply(Integer key, ValueObject val) {
@@ -173,7 +173,7 @@ public class IgniteCacheQueryLoadSelfTest extends GridCommonAbstractTest
{
      * @throws Exception If failed.
      */
     public void testLoadCacheAsyncFiltered() throws Exception {
-        IgniteCache<Integer, ValueObject> cache = grid(0).jcache(null);
+        IgniteCache<Integer, ValueObject> cache = grid().jcache(null);
 
         cache.withAsync().loadCache(new P2<Integer, ValueObject>() {
             @Override public boolean apply(Integer key, ValueObject val) {


Mime
View raw message