use of org.apache.geode.cache.query.internal.DefaultQuery in project geode by apache.
the class IndexHintJUnitTest method testTwoIndexHint.
// Tests the grammar for a hint with two index names
@Test
public void testTwoIndexHint() throws Exception {
createRegion();
QueryService qs = CacheUtils.getQueryService();
DefaultQuery query = (DefaultQuery) qs.newQuery("<hint 'FirstIndex', 'SecondIndex'> select * from /Portfolios p where p.ID > 10");
QueryExecutionContext qec = new QueryExecutionContext(new Object[1], CacheUtils.getCache(), query);
query.executeUsingContext(qec);
assertTrue(qec.isHinted("FirstIndex"));
assertTrue(qec.isHinted("SecondIndex"));
}
use of org.apache.geode.cache.query.internal.DefaultQuery in project geode by apache.
the class LocalDataSet method query.
public SelectResults query(String queryPredicate) throws FunctionDomainException, TypeMismatchException, NameResolutionException, QueryInvocationTargetException {
QueryService qs = getCache().getLocalQueryService();
DefaultQuery query = (DefaultQuery) qs.newQuery("select * from " + getFullPath() + " this where " + queryPredicate);
Object[] params = null;
return (SelectResults) this.executeQuery(query, params, getBucketSet());
}
use of org.apache.geode.cache.query.internal.DefaultQuery in project geode by apache.
the class QueryJUnitTest method testThreadSafetyOfCompiledSelectScopeId.
@Test
public void testThreadSafetyOfCompiledSelectScopeId() throws Exception {
try {
Cache cache = CacheUtils.getCache();
RegionFactory<Integer, Portfolio> rf = cache.createRegionFactory(RegionShortcut.PARTITION);
Region r = rf.create("keyzset");
for (int i = 0; i < 100; i++) {
r.put(i, new Portfolio(i));
}
ScopeThreadingTestHook scopeIDTestHook = new ScopeThreadingTestHook(3);
DefaultQuery.testHook = scopeIDTestHook;
QueryService qs = cache.getQueryService();
Query q = qs.newQuery("SELECT DISTINCT * FROM /keyzset.keySet key WHERE key.id > 0 AND key.id <= 0 ORDER BY key asc LIMIT $3");
Thread q1 = new Thread(new QueryRunnable(q, new Object[] { 10, 20, 10 }));
Thread q2 = new Thread(new QueryRunnable(q, new Object[] { 5, 10, 5 }));
Thread q3 = new Thread(new QueryRunnable(q, new Object[] { 2, 10, 8 }));
q1.start();
q2.start();
q3.start();
q1.join();
q2.join();
q3.join();
assertEquals("Exceptions were thrown due to DefaultQuery not being thread-safe", true, scopeIDTestHook.isOk());
} finally {
DefaultQuery.testHook = null;
}
}
use of org.apache.geode.cache.query.internal.DefaultQuery in project geode by apache.
the class QueryJUnitTest method test006GetRegionsInQuery.
@Test
public void test006GetRegionsInQuery() {
String[] queryStrs = new String[] { "SELECT DISTINCT * FROM /Portfolios where status='active'", "/Portfolios", "/Portfolios.values", "/Portfolios.keys()", "/Portfolios.entries(false)", "null = null", "select distinct * from /Employees where not (select distinct * from collect).isEmpty", "select distinct * from $2 where salary > $1", "SELECT DISTINCT key: key, iD: entry.value.iD, secId: posnVal.secId FROM /pos.entries entry, entry.value.positions.values posnVal WHERE entry.value.\"type\" = 'type0' AND posnVal.secId = 'YHOO'", "SELECT DISTINCT * FROM (SELECT DISTINCT * FROM /Portfolios ptf, positions pos) WHERE pos.value.secId = 'IBM'", "SELECT DISTINCT * FROM /Portfolios WHERE NOT(SELECT DISTINCT * FROM positions.values p WHERE p.secId = 'IBM').isEmpty", "SELECT DISTINCT * FROM /Portfolios where status = ELEMENT(SELECT DISTINCT * FROM /Portfolios p where p.ID = 0).status", "Select distinct * from /Portfolios pf, /Portfolios2, /Portfolios3, /Data where pf.status='active'", "select distinct * from /portfolios p, p.positions.values myPos, (select distinct * from /Employees x) where myPos.secId = 'YHOO'", "select distinct * from /portfolios p, p.positions.values myPos, (select distinct * from /Employees x, /portfolios) where myPos.secId = 'YHOO'", "select distinct * from /portfolios p, p.positions.values myPos, (select distinct * from /Employees x, /Portfolios) where myPos.secId = 'YHOO'", "select distinct /Portfolios.size, key FROM /pos.entries", "select distinct /Portfolios2.size, key FROM /pos.entries WHERE (Select distinct * from /portfolios4, entries).size = 3" };
String[][] regions = new String[][] { { "/Portfolios" }, { "/Portfolios" }, { "/Portfolios" }, { "/Portfolios" }, { "/Portfolios" }, {}, { "/Employees" }, { "/Portfolios" }, { "/pos" }, { "/Portfolios" }, { "/Portfolios" }, { "/Portfolios" }, { "/Portfolios", "/Portfolios2", "/Portfolios3", "/Data" }, { "/portfolios", "/Employees" }, { "/portfolios", "/Employees" }, { "/portfolios", "/Employees", "/Portfolios" }, { "/Portfolios", "/pos" }, { "/Portfolios2", "/pos", "/portfolios4" } };
Object[] params = new Object[] { "", CacheUtils.createRegion("Portfolios", Portfolio.class) };
for (int i = 0; i < queryStrs.length; ++i) {
Query q = CacheUtils.getQueryService().newQuery(queryStrs[i]);
Set set = ((DefaultQuery) q).getRegionsInQuery(params);
String[] qRegions = regions[i];
assertEquals("region names don't match in query #" + i + "(\"" + queryStrs[i] + "\"", new HashSet(Arrays.asList(qRegions)), set);
}
DefaultQuery q = (DefaultQuery) CacheUtils.getQueryService().newQuery(queryStrs[0]);
Set set = q.getRegionsInQuery(params);
try {
set.add("test");
fail("The set returned should not be modifiable");
} catch (Exception e) {
// Expected
}
}
use of org.apache.geode.cache.query.internal.DefaultQuery in project geode by apache.
the class RangeIndexAPIJUnitTest method testQueryMethod_3.
/**
* Tests the query method of RangeIndex with takes a bound defined ( lower as well as upper) & may
* contain NotEqaul Keys
*/
@Test
public void testQueryMethod_3() throws Exception {
QueryService qs;
qs = CacheUtils.getQueryService();
AbstractIndex i1 = (AbstractIndex) qs.createIndex("idIndex", IndexType.FUNCTIONAL, "ID", "/portfolios");
AbstractIndex i2 = (AbstractIndex) qs.createIndex("statusIndex", IndexType.FUNCTIONAL, "status", "/portfolios");
AbstractIndex i3 = (AbstractIndex) qs.createIndex("status.toString()", IndexType.FUNCTIONAL, "status.toString", "/portfolios");
Set results = new HashSet();
DefaultQuery q = new DefaultQuery("select * from /portfolios", CacheUtils.getCache(), false);
q.setRemoteQuery(false);
ExecutionContext context = new QueryExecutionContext(null, CacheUtils.getCache(), q);
bindIterators(context, "/portfolios");
Set keysToRemove = new HashSet();
i1.query(new Integer(5), OQLLexerTokenTypes.TOK_GT, new Integer(10), OQLLexerTokenTypes.TOK_LT, results, null, context);
assertEquals(4, results.size());
for (int i = 6; i < 10; ) {
assertTrue(results.contains(region.get(new Integer(i))));
++i;
}
results.clear();
keysToRemove.clear();
keysToRemove.add(new Integer(10));
keysToRemove.add(new Integer(9));
i1.query(new Integer(5), OQLLexerTokenTypes.TOK_GT, new Integer(10), OQLLexerTokenTypes.TOK_LT, results, keysToRemove, context);
assertEquals(3, results.size());
for (int i = 6; i < 9; ) {
assertTrue(results.contains(region.get(new Integer(i))));
++i;
}
results.clear();
keysToRemove.clear();
keysToRemove.add(new Integer(10));
i1.query(new Integer(5), OQLLexerTokenTypes.TOK_GT, new Integer(10), OQLLexerTokenTypes.TOK_LE, results, keysToRemove, context);
assertEquals(4, results.size());
for (int i = 6; i < 10; ) {
assertTrue(results.contains(region.get(new Integer(i))));
++i;
}
results.clear();
keysToRemove.clear();
i1.query(new Integer(5), OQLLexerTokenTypes.TOK_GT, new Integer(10), OQLLexerTokenTypes.TOK_LE, results, null, context);
assertEquals(5, results.size());
for (int i = 6; i < 11; ) {
assertTrue(results.contains(region.get(new Integer(i))));
++i;
}
results.clear();
keysToRemove.clear();
i1.query(new Integer(5), OQLLexerTokenTypes.TOK_GE, new Integer(10), OQLLexerTokenTypes.TOK_LE, results, null, context);
assertEquals(6, results.size());
for (int i = 5; i < 11; ) {
assertTrue(results.contains(region.get(new Integer(i))));
++i;
}
results.clear();
keysToRemove.clear();
keysToRemove.add(new Integer(5));
i1.query(new Integer(5), OQLLexerTokenTypes.TOK_GE, new Integer(10), OQLLexerTokenTypes.TOK_LE, results, keysToRemove, context);
assertEquals(5, results.size());
for (int i = 6; i < 11; ) {
assertTrue(results.contains(region.get(new Integer(i))));
++i;
}
results.clear();
keysToRemove.clear();
keysToRemove.add(new Integer(5));
keysToRemove.add(new Integer(10));
keysToRemove.add(new Integer(7));
i1.query(new Integer(5), OQLLexerTokenTypes.TOK_GE, new Integer(10), OQLLexerTokenTypes.TOK_LE, results, keysToRemove, context);
assertEquals(3, results.size());
assertTrue(results.contains(region.get(new Integer(6))));
assertTrue(results.contains(region.get(new Integer(8))));
assertTrue(results.contains(region.get(new Integer(9))));
}
Aggregations