use of org.apache.geode.cache.query.data.Portfolio in project geode by apache.
the class OrderByTestImplementation method testOrderByWithIndexResultWithProjection.
@Test
public void testOrderByWithIndexResultWithProjection() throws Exception {
String[] queries = { // Test case No. IUMR021
"SELECT distinct ID, description, createTime FROM /portfolio1 pf1 where ID > 10 order by ID desc ", "SELECT distinct ID, description, createTime FROM /portfolio1 pf1 where ID > 10 order by ID asc ", "SELECT distinct ID, description, createTime FROM /portfolio1 pf1 where ID > 10 and ID < 20 order by ID asc ", "SELECT distinct ID, description, createTime FROM /portfolio1 pf1 where ID > 10 and ID < 20 order by ID desc ", "SELECT distinct ID, description, createTime FROM /portfolio1 pf1 where ID >= 10 and ID <= 20 order by ID desc ", "SELECT distinct ID, description, createTime FROM /portfolio1 pf1 where ID >= 10 and ID <= 20 order by ID asc", "SELECT distinct ID, description, createTime FROM /portfolio1 pf1 where ID != 10 order by ID asc ", "SELECT distinct ID, description, createTime FROM /portfolio1 pf1 where ID != 10 order by ID desc ", "SELECT distinct ID, description, createTime FROM /portfolio1 pf1 where ID > 10 order by ID desc limit 5", "SELECT distinct ID, description, createTime FROM /portfolio1 pf1 where ID > 10 order by ID asc limit 5", "SELECT distinct ID, description, createTime FROM /portfolio1 pf1 where ID > 10 and ID < 20 order by ID asc limit 5 ", "SELECT distinct ID, description, createTime FROM /portfolio1 pf1 where ID > 10 and ID < 20 order by ID desc limit 5", "SELECT distinct ID, description, createTime FROM /portfolio1 pf1 where ID >= 10 and ID <= 20 order by ID desc limit 5", "SELECT distinct ID, description, createTime FROM /portfolio1 pf1 where ID >= 10 and ID <= 20 order by ID asc limit 5", "SELECT distinct ID, description, createTime FROM /portfolio1 pf1 where ID != 10 order by ID asc limit 10", "SELECT distinct ID, description, createTime FROM /portfolio1 pf1 where ID != 10 order by ID desc limit 10" };
Object[][] r = new Object[queries.length][2];
QueryService qs;
qs = CacheUtils.getQueryService();
Position.resetCounter();
// Create Regions
Region r1 = createRegion("portfolio1", Portfolio.class);
for (int i = 0; i < 50; i++) {
r1.put(i + "", new Portfolio(i));
}
// Execute Queries without Indexes
for (int i = 0; i < queries.length; i++) {
Query q = null;
try {
q = CacheUtils.getQueryService().newQuery(queries[i]);
CacheUtils.getLogger().info("Executing query: " + queries[i]);
r[i][0] = q.execute();
} catch (Exception e) {
e.printStackTrace();
fail(q.getQueryString());
}
}
// Create Indexes
this.createIndex("IDIndexPf1", IndexType.FUNCTIONAL, "ID", "/portfolio1");
// Execute Queries with Indexes
for (int i = 0; i < queries.length; i++) {
Query q = null;
try {
q = CacheUtils.getQueryService().newQuery(queries[i]);
CacheUtils.getLogger().info("Executing query: " + queries[i]);
QueryObserverImpl observer = new QueryObserverImpl();
QueryObserverHolder.setInstance(observer);
r[i][1] = q.execute();
SelectResults rcw = (SelectResults) r[i][1];
int indexLimit = queries[i].indexOf("limit");
int limit = -1;
boolean limitQuery = indexLimit != -1;
if (limitQuery) {
limit = Integer.parseInt(queries[i].substring(indexLimit + 5).trim());
}
assertTrue(!limitQuery || rcw.size() <= limit);
// assertIndexDetailsEquals("Set",rcw.getCollectionType().getSimpleClassName());
String colType = rcw.getCollectionType().getSimpleClassName();
if (!(colType.equals("Ordered") || colType.equals("LinkedHashSet"))) {
fail("The collection type " + colType + " is not expexted");
}
if (assertIndexUsedOnQueryNode() && !observer.isIndexesUsed) {
fail("Index is NOT uesd");
}
Iterator itr = observer.indexesUsed.iterator();
while (itr.hasNext()) {
if (!(itr.next().toString()).equals("IDIndexPf1")) {
fail("<IDIndexPf1> was expected but found " + itr.next().toString());
}
// assertIndexDetailsEquals("statusIndexPf1",itr.next().toString());
}
int indxs = observer.indexesUsed.size();
System.out.println("**************************************************Indexes Used :::::: " + indxs + " Index Name: " + observer.indexName);
} catch (Exception e) {
e.printStackTrace();
fail(q.getQueryString());
}
}
StructSetOrResultsSet ssOrrs = new StructSetOrResultsSet();
ssOrrs.CompareQueryResultsWithoutAndWithIndexes(r, queries.length, true, queries);
ssOrrs.compareExternallySortedQueriesWithOrderBy(queries, r);
}
use of org.apache.geode.cache.query.data.Portfolio in project geode by apache.
the class StructMemberAccessJUnitTest method setUp.
@Before
public void setUp() throws java.lang.Exception {
CacheUtils.startCache();
Region region = CacheUtils.createRegion("Portfolios", Portfolio.class);
for (int i = 0; i < 4; i++) {
region.put("" + i, new Portfolio(i));
}
}
use of org.apache.geode.cache.query.data.Portfolio in project geode by apache.
the class ResultsDataSerializabilityJUnitTest method testDataSerializability.
// For locally executed queries, ResultsCollectionPdxDeserializerWrapper is
// returned which is not required to be DSFID as it is not sent over the
// network. Hence a dunit test is required for testing this functionality.
/* test DataSerializability of a simple query result */
@Ignore
@Test
public void testDataSerializability() throws Exception {
Region region = CacheUtils.createRegion("Portfolios", Portfolio.class);
for (int i = 0; i < 10000; i++) {
region.put(i + "", new Portfolio(i));
}
String queryStr = "SELECT DISTINCT * FROM /Portfolios";
Query q = CacheUtils.getQueryService().newQuery(queryStr);
SelectResults res1 = (SelectResults) q.execute();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
DataOutputStream out = new DataOutputStream(baos);
// false prevents Java serialization
DataSerializer.writeObject(res1, out, false);
out.close();
DataInputStream in = new DataInputStream(new ByteArrayInputStream(baos.toByteArray()));
SelectResults res2 = (SelectResults) DataSerializer.readObject(in);
in.close();
assertEquals(res2.size(), res1.size());
}
use of org.apache.geode.cache.query.data.Portfolio in project geode by apache.
the class IndexMaintainceJUnitTest method test004DestroyEntry.
@Test
public void test004DestroyEntry() throws Exception {
IndexStatistics stats = index.getStatistics();
region.put("4", new Portfolio(4));
region.destroy("4");
assertEquals(4, stats.getNumberOfValues());
// Set results = new HashSet();
// index.query("active", OQLLexerTokenTypes.TOK_EQ, results,new ExecutionContext(null,
// CacheUtils.getCache()));
SelectResults results = region.query("status = 'active'");
assertEquals(2, results.size());
}
use of org.apache.geode.cache.query.data.Portfolio in project geode by apache.
the class HashIndexSetJUnitTest method testGetByKeyLocatesAfterMultipleColiisionsAndRemoveToken.
@Test
public void testGetByKeyLocatesAfterMultipleColiisionsAndRemoveToken() throws Exception {
int numEntries = 20;
int keyToLookup = 1;
his = createHashIndexSet();
Map<Integer, Portfolio> collectionOfPorts1 = this.createPortfolioObjects(numEntries, 0);
Map<Integer, Portfolio> collectionOfPorts2 = this.createPortfolioObjects(numEntries, numEntries);
Map<Integer, Portfolio> collectionOfPorts3 = this.createPortfolioObjects(numEntries, numEntries * 2);
addPortfoliosToHashIndexSet(collectionOfPorts1, his);
addPortfoliosToHashIndexSet(collectionOfPorts2, his);
addPortfoliosToHashIndexSet(collectionOfPorts3, his);
assertEquals(numEntries * 3, his.size());
Iterator iterator = his.get(keyToLookup);
int numIterated = 0;
while (iterator.hasNext()) {
numIterated++;
// verify that the returned values match what we lookedup
assertEquals(keyToLookup, ((Portfolio) iterator.next()).indexKey);
}
assertEquals(3, numIterated);
// let's remove the second collision
his.remove(keyToLookup, collectionOfPorts2.get(keyToLookup));
iterator = his.get(keyToLookup);
numIterated = 0;
while (iterator.hasNext()) {
numIterated++;
// verify that the returned values match what we lookedup
assertEquals(keyToLookup, ((Portfolio) iterator.next()).indexKey);
}
assertEquals(2, numIterated);
// Add it back in and make sure we can iterate all 3 again
his.add(keyToLookup, collectionOfPorts2.get(keyToLookup));
iterator = his.get(keyToLookup);
numIterated = 0;
while (iterator.hasNext()) {
numIterated++;
// verify that the returned values match what we lookedup
assertEquals(keyToLookup, ((Portfolio) iterator.next()).indexKey);
}
assertEquals(3, numIterated);
}
Aggregations