Skip to content

Commit

Permalink
#ignite-sql-tests - test fix x
Browse files Browse the repository at this point in the history
  • Loading branch information
S.Vladykin committed Feb 5, 2015
1 parent 202f90f commit 684b1a7
Show file tree
Hide file tree
Showing 6 changed files with 104 additions and 44 deletions.
Expand Up @@ -134,7 +134,22 @@ public void setType(String type) {
* @param type Type. * @param type Type.
*/ */
public void setType(Class<?> 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} */ /** {@inheritDoc} */
Expand Down
Expand Up @@ -19,6 +19,8 @@


import org.apache.ignite.internal.util.typedef.internal.*; import org.apache.ignite.internal.util.typedef.internal.*;


import static org.apache.ignite.cache.query.QuerySqlPredicate.name;

/** /**
* Predicate for Lucene based fulltext search. * Predicate for Lucene based fulltext search.
*/ */
Expand Down Expand Up @@ -62,7 +64,7 @@ public String getType() {
* @param type Type. * @param type Type.
*/ */
public void setType(Class<?> type) { public void setType(Class<?> type) {
setType(type == null ? null : type.getSimpleName()); setType(name(type));
} }


/** /**
Expand Down
Expand Up @@ -321,6 +321,12 @@ else if (filter instanceof QuerySpiPredicate) {


return query(filter, null); return query(filter, null);
} }
catch (Exception e) {
if (e instanceof CacheException)
throw e;

throw new CacheException(e);
}
finally { finally {
gate.leave(prev); gate.leave(prev);
} }
Expand All @@ -335,6 +341,12 @@ else if (filter instanceof QuerySpiPredicate) {
try { try {
return ctx.kernalContext().query().queryTwoStep(ctx.name(), filter.getSql(), filter.getArgs()); 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 { finally {
gate.leave(prev); gate.leave(prev);
} }
Expand All @@ -356,6 +368,12 @@ else if (filter instanceof QuerySpiPredicate) {


return query(filter, ctx.kernalContext().grid().forLocal()); return query(filter, ctx.kernalContext().grid().forLocal());
} }
catch (Exception e) {
if (e instanceof CacheException)
throw e;

throw new CacheException(e);
}
finally { finally {
gate.leave(prev); gate.leave(prev);
} }
Expand All @@ -371,6 +389,12 @@ else if (filter instanceof QuerySpiPredicate) {
return new QueryCursorImpl<>(ctx.kernalContext().query().queryLocalFields( return new QueryCursorImpl<>(ctx.kernalContext().query().queryLocalFields(
ctx.name(), filter.getSql(), filter.getArgs())); ctx.name(), filter.getSql(), filter.getArgs()));
} }
catch (Exception e) {
if (e instanceof CacheException)
throw e;

throw new CacheException(e);
}
finally { finally {
gate.leave(prev); gate.leave(prev);
} }
Expand Down
Expand Up @@ -129,6 +129,12 @@ public class GridSqlQueryParser {
/** */ /** */
private static final Getter<Aggregate, Expression> ON = getter(Aggregate.class, "on"); 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<>(); private final IdentityHashMap<Object, Object> h2ObjToGridObj = new IdentityHashMap<>();


Expand Down Expand Up @@ -161,6 +167,12 @@ else if (tbl instanceof TableView) {


res = new GridSqlSubquery(parse((Select)qry)); 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 else
throw new IgniteException("Unsupported query: " + filter); throw new IgniteException("Unsupported query: " + filter);


Expand Down Expand Up @@ -428,6 +440,17 @@ private GridSqlElement parseExpression0(Expression expression) {
return res; 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) if (expression instanceof Parameter)
return new GridSqlParameter(((Parameter)expression).getIndex()); return new GridSqlParameter(((Parameter)expression).getIndex());


Expand Down
Expand Up @@ -234,7 +234,7 @@ public void testIntegerType() throws Exception {
cache.put(key, val); cache.put(key, val);


QueryCursor<Cache.Entry<String, Integer>> qry = 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()); Cache.Entry<String, Integer> entry = F.first(qry.getAll());


Expand All @@ -250,7 +250,7 @@ public void testIntegerType() throws Exception {
*/ */
public void testUserDefinedFunction() throws IgniteCheckedException { public void testUserDefinedFunction() throws IgniteCheckedException {
// Without alias. // 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)")); QueryCursor<List<?>> qry = cache.queryFields(new QuerySqlPredicate("select square(1), square(2)"));


Expand All @@ -276,13 +276,11 @@ public void testUserDefinedFunction() throws IgniteCheckedException {
assertEquals(8, row.get(1)); assertEquals(8, row.get(1));


// Not registered. // Not registered.
final QueryCursor<List<?>> qry3 = cache.queryFields(new QuerySqlPredicate("select no()"));

GridTestUtils.assertThrows( GridTestUtils.assertThrows(
log, log,
new Callable<Object>() { new Callable<Object>() {
@Override public Object call() throws Exception { @Override public Object call() throws Exception {
qry3.getAll(); cache.queryFields(new QuerySqlPredicate("select no()"));


return null; return null;
} }
Expand All @@ -303,15 +301,15 @@ public void testExpiration() throws Exception {


IgniteCache<String, Integer> cache = ignite.jcache(null); 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()); assertEquals(1, res.getValue().intValue());


U.sleep(1020); U.sleep(1020);


res = F.first(qry.getAll()); res = F.first(qry);


assertNull(res); assertNull(res);
} }
Expand All @@ -325,7 +323,7 @@ public void testIllegalBounds() throws Exception {
cache.put(1, 1); cache.put(1, 1);
cache.put(2, 2); 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()); assertTrue(qry.getAll().isEmpty());
} }
Expand Down Expand Up @@ -442,7 +440,7 @@ public void testObjectQuery() throws Exception {
for (int i = 0; i < expCnt; i++) for (int i = 0; i < expCnt; i++)
assert iter.next() != null; assert iter.next() != null;


assert iter.next() == null; assert !iter.hasNext();


qry = cache.query(new QueryTextPredicate(ObjectValue.class, "test")); qry = cache.query(new QueryTextPredicate(ObjectValue.class, "test"));


Expand All @@ -453,7 +451,7 @@ public void testObjectQuery() throws Exception {
for (int i = 0; i < expCnt; i++) for (int i = 0; i < expCnt; i++)
assert iter.next() != null; assert iter.next() != null;


assert iter.next() == null; assert !iter.hasNext();
} }


/** /**
Expand Down Expand Up @@ -501,15 +499,17 @@ public void testObjectQueryWithSwap() throws Exception {


Cache.Entry<Integer, ObjectValue> next; Cache.Entry<Integer, ObjectValue> next;


while ((next = iter.next()) != null) { while (iter.hasNext()) {
next = iter.next();

ObjectValue v = next.getValue(); ObjectValue v = next.getValue();


assert !set.contains(v.intValue()); assert !set.contains(v.intValue());


set.add(v.intValue()); set.add(v.intValue());
} }


assert iter.next() == null; assert !iter.hasNext();


assertEquals(cnt, set.size()); assertEquals(cnt, set.size());


Expand All @@ -532,7 +532,7 @@ public void testObjectQueryWithSwap() throws Exception {
set.add(v.intValue()); set.add(v.intValue());
} }


assert iter.next() == null; assert !iter.hasNext();


assertEquals(cnt / 2, set.size()); assertEquals(cnt / 2, set.size());


Expand All @@ -553,11 +553,11 @@ public void testFullTextSearch() throws Exception {


// Try to execute on empty cache first. // Try to execute on empty cache first.
QueryCursor<Cache.Entry<Integer, ObjectValue>> qry = QueryCursor<Cache.Entry<Integer, ObjectValue>> qry =
cache.query(new QuerySqlPredicate(ObjectValue.class, "full")); cache.query(new QueryTextPredicate(ObjectValue.class, "full"));


assert qry.getAll().isEmpty(); assert qry.getAll().isEmpty();


qry = cache.query(new QuerySqlPredicate(ObjectValue.class, "full")); qry = cache.query(new QueryTextPredicate(ObjectValue.class, "full"));


assert qry.getAll().isEmpty(); assert qry.getAll().isEmpty();


Expand All @@ -574,15 +574,15 @@ public void testFullTextSearch() throws Exception {


cache.put(key2, val2); 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(); Collection<Cache.Entry<Integer, ObjectValue>> res = qry.getAll();


assert res != null; assert res != null;


assert res.size() == 2; assert res.size() == 2;


qry = cache.query(new QuerySqlPredicate(ObjectValue.class, "full")); qry = cache.query(new QueryTextPredicate(ObjectValue.class, "full"));


res = qry.getAll(); res = qry.getAll();


Expand Down Expand Up @@ -652,7 +652,7 @@ public void testScanQuery() throws Exception {
assertEquals("value", e1.getValue()); assertEquals("value", e1.getValue());
} }


assert iter.next() == null; assert !iter.hasNext();
} }


/** /**
Expand Down Expand Up @@ -851,7 +851,7 @@ public void testEmptyGrid() throws Exception {
cache.put(key, val); cache.put(key, val);


QueryCursor<Cache.Entry<String, Integer>> qry = cache.query(new QuerySqlPredicate(Integer.class, 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()); Cache.Entry<String, Integer> entry = F.first(qry.getAll());


Expand Down Expand Up @@ -904,22 +904,22 @@ public void testAnonymousClasses() throws Exception {
} }
}; };


assertTrue(val.getClass().getName().endsWith("GridCacheAbstractQuerySelfTest$16")); assertTrue(val.getClass().getName(), val.getClass().getName().endsWith("IgniteCacheAbstractQuerySelfTest$5"));


cache.put(1, val); 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(); Collection<Cache.Entry<Integer, Object>> res = q.getAll();


assertEquals(1, res.size()); assertEquals(1, res.size());


QueryCursor<List<?>> fieldsRes = cache.queryFields(new QuerySqlPredicate( List<List<?>> fieldsRes = cache.queryFields(new QuerySqlPredicate(
"select field1 from GridCacheAbstractQuerySelfTest_16")); "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(1, fields.size());
assertEquals(10, fields.get(0)); assertEquals(10, fields.get(0));
Expand All @@ -946,7 +946,7 @@ public void testTwoAnonymousClasses() throws Exception {
cache.put(1, val1); cache.put(1, val1);
cache.put(2, val2); 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(); Collection<Cache.Entry<Integer, Object>> res = q.getAll();


Expand Down Expand Up @@ -993,25 +993,21 @@ public void testLimitOnly() throws Exception {
cache.put(i, i); cache.put(i, i);


QueryCursor<Cache.Entry<Integer, Integer>> q = 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(); Collection<Cache.Entry<Integer, Integer>> res = q.getAll();


assertEquals(10, res.size()); assertEquals(5, res.size());


if (cacheMode() != PARTITIONED) { Iterator<Cache.Entry<Integer, Integer>> it = res.iterator();
assertEquals(5, res.size());


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++) { Cache.Entry<Integer, Integer> e = it.next();
assertTrue(it.hasNext());


Cache.Entry<Integer, Integer> e = it.next(); assertEquals(i, e.getKey());

assertEquals(i, e.getValue());
assertEquals(i, e.getKey());
assertEquals(i, e.getValue());
}
} }
} }


Expand Down
Expand Up @@ -113,7 +113,7 @@ private long size(Class<?> cls) throws IgniteCheckedException {
* @throws Exception If failed. * @throws Exception If failed.
*/ */
public void testLoadCache() throws Exception { public void testLoadCache() throws Exception {
IgniteCache<Integer, ValueObject> cache = grid(0).jcache(null); IgniteCache<Integer, ValueObject> cache = grid().jcache(null);


cache.loadCache(null, 0); cache.loadCache(null, 0);


Expand Down Expand Up @@ -151,7 +151,7 @@ public void testLoadCacheAsync() throws Exception {
* @throws Exception If failed. * @throws Exception If failed.
*/ */
public void testLoadCacheFiltered() throws Exception { 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>() { cache.loadCache(new P2<Integer, ValueObject>() {
@Override public boolean apply(Integer key, ValueObject val) { @Override public boolean apply(Integer key, ValueObject val) {
Expand All @@ -173,7 +173,7 @@ public void testLoadCacheFiltered() throws Exception {
* @throws Exception If failed. * @throws Exception If failed.
*/ */
public void testLoadCacheAsyncFiltered() throws Exception { 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>() { cache.withAsync().loadCache(new P2<Integer, ValueObject>() {
@Override public boolean apply(Integer key, ValueObject val) { @Override public boolean apply(Integer key, ValueObject val) {
Expand Down

0 comments on commit 684b1a7

Please sign in to comment.