use of org.apache.geode.cache.AttributesFactory in project geode by apache.
the class IndexWithSngleFrmAndMultCondQryJUnitTest method testIndexUsageIfOneFieldIndexedAndMoreThanOneUnindexed_Bug38032.
/**
* BugTest for Bug # 38032 Test index usage on PR region & Local region if the where clause
* contains three conditions but only one condition is indexed & the total number of from clause
* iterators is 1.
*
*/
@Test
public void testIndexUsageIfOneFieldIndexedAndMoreThanOneUnindexed_Bug38032() throws Exception {
AttributesFactory af = new AttributesFactory();
af.setValueConstraint(Portfolio.class);
RegionAttributes ra = af.createRegionAttributes();
Region region = CacheUtils.getCache().createRegion("pos", ra);
for (int i = 0; i < 5; i++) {
region.put("" + i, new Portfolio(i));
}
// As default generation of Portfolio objects
// The status is active for key =0 & key =2 & key =4
// The description is XXXX for key =1, key =3
// Let us make explitly
// Set createTime as 5 for three Portfolio objects of key =0 & key =1 & key=2;
// Description as XXXX for key =2 only.
// Thus out of 4 objects created only 1 object ( key =2 ) will have
// description = XXXX , status = active & time = 5
((Portfolio) region.get("0")).setCreateTime(5);
((Portfolio) region.get("1")).setCreateTime(5);
((Portfolio) region.get("2")).setCreateTime(5);
((Portfolio) region.get("2")).description = "XXXX";
int numSatisfyingOurCond = 0;
for (int i = 0; i < 5; i++) {
Portfolio pf = (Portfolio) region.get("" + i);
if (pf.description != null && pf.description.equals("XXXX") && pf.getCreateTime() == 5 && pf.isActive()) {
++numSatisfyingOurCond;
}
}
assertEquals(1, numSatisfyingOurCond);
executeQuery_2(region, true);
region.destroyRegion();
CacheUtils.closeCache();
CacheUtils.restartCache();
af = new AttributesFactory();
af.setValueConstraint(Portfolio.class);
PartitionAttributesFactory pfa = new PartitionAttributesFactory();
pfa.setRedundantCopies(0);
pfa.setTotalNumBuckets(1);
af.setPartitionAttributes(pfa.create());
ra = af.createRegionAttributes();
region = CacheUtils.getCache().createRegion("pos", ra);
for (int i = 0; i < 5; i++) {
region.put("" + i, new Portfolio(i));
}
// As default generation of Portfolio objects
// The status is active for key =0 & key =2 & key =4
// The description is XXXX for key =1, key =3
// Let us make explitly
// Set createTime as 5 for three Portfolio objects of key =0 & key =1 & key=2;
// Description as XXXX for key =2 only.
// Thus out of 4 objects created only 1 object ( key =2 ) will have
// description = XXXX , status = active & time = 5
Portfolio x = (Portfolio) region.get("0");
x.setCreateTime(5);
region.put("0", x);
x = (Portfolio) region.get("1");
x.setCreateTime(5);
region.put("1", x);
x = (Portfolio) region.get("2");
x.setCreateTime(5);
x.description = "XXXX";
region.put("2", x);
numSatisfyingOurCond = 0;
for (int i = 0; i < 5; i++) {
Portfolio pf = (Portfolio) region.get("" + i);
if (pf.description != null && pf.description.equals("XXXX") && pf.getCreateTime() == 5 && pf.isActive()) {
++numSatisfyingOurCond;
}
}
assertEquals(1, numSatisfyingOurCond);
executeQuery_2(region, false);
region.destroyRegion();
}
use of org.apache.geode.cache.AttributesFactory in project geode by apache.
the class IndexWithSngleFrmAndMultCondQryJUnitTest method testIndexUsageIfIndexesGreaterThanFieldsInQueryWhereClauseWithOneIterator.
/**
* Test index usage on PR region & Local region if the total number of indexes created are more
* than the fields used in the where clause of the query and the number of from clause iterators
* is One
*/
@Test
public void testIndexUsageIfIndexesGreaterThanFieldsInQueryWhereClauseWithOneIterator() throws Exception {
AttributesFactory af = new AttributesFactory();
af.setValueConstraint(Portfolio.class);
RegionAttributes ra = af.createRegionAttributes();
Region region = CacheUtils.getCache().createRegion("pos", ra);
for (int i = 0; i < 4; i++) {
region.put("" + i, new Portfolio(i));
}
executeQuery_1(region, true);
region.destroyRegion();
CacheUtils.closeCache();
CacheUtils.restartCache();
af = new AttributesFactory();
af.setValueConstraint(Portfolio.class);
PartitionAttributesFactory pfa = new PartitionAttributesFactory();
pfa.setRedundantCopies(0);
pfa.setTotalNumBuckets(1);
af.setPartitionAttributes(pfa.create());
ra = af.createRegionAttributes();
region = CacheUtils.getCache().createRegion("pos", ra);
for (int i = 0; i < 4; i++) {
Portfolio x = new Portfolio(i);
region.put("" + i, x);
}
executeQuery_1(region, false);
region.destroyRegion();
}
use of org.apache.geode.cache.AttributesFactory in project geode by apache.
the class LikePredicateJUnitTest method enhancedNotLike.
/**
* Tests with combination of % and _ and NOT with LIKE Supported from 6.6
*
* @throws Exception
*/
private void enhancedNotLike(boolean useBindPrms, boolean useIndex) throws Exception {
Cache cache = CacheUtils.getCache();
AttributesFactory attributesFactory = new AttributesFactory();
RegionAttributes regionAttributes = attributesFactory.create();
Region region = cache.createRegion("pos", regionAttributes);
String[] values = new String[] { "active", "inactive" };
String[] likePredicates1 = new String[] { "active", "act%%ve", "a%e", "activ_", "ac_ive", "act__e", "a%iv_", "a_tiv%", "ac%" };
String[] likePredicates2 = new String[] { "%ctiv%", "%c%iv%", "%ctive", "%%ti%", "%" };
String[] likePredicates3 = new String[] { "___ctive", "___c_iv_", "___ctiv%", "____tive" };
for (int i = 0; i < values.length; i++) {
region.put(new Integer(i), values[i]);
}
QueryService qs = cache.getQueryService();
if (useIndex) {
qs.createIndex("p", IndexType.FUNCTIONAL, "p", "/pos.values p");
}
Query q;
SelectResults results;
for (int i = 0; i < likePredicates1.length; i++) {
if (!useBindPrms) {
q = qs.newQuery("select p from /pos p where NOT (p like '" + likePredicates1[i] + "')");
results = (SelectResults) q.execute();
} else {
q = qs.newQuery("select p from /pos p where NOT (p like $1)");
results = (SelectResults) q.execute(new Object[] { likePredicates1[i] });
}
List r = results.asList();
if (r.size() != 1 || !r.get(0).equals(values[1])) {
fail("Unexprected result. expected :" + values[1] + " for the like predicate1: " + likePredicates1[i] + " found : " + (r.size() == 1 ? r.get(0) : "Result size not equal to 1"));
}
}
for (int i = 0; i < likePredicates2.length; i++) {
if (!useBindPrms) {
q = qs.newQuery("select p from /pos p where NOT (p like '" + likePredicates2[i] + "')");
results = (SelectResults) q.execute();
} else {
q = qs.newQuery("select p from /pos p where NOT (p like $1)");
results = (SelectResults) q.execute(new Object[] { likePredicates2[i] });
}
List r = results.asList();
if (r.size() != 0) {
fail("Unexprected result. expected nothing for the like predicate2: " + likePredicates2[i] + " found : " + (r.size() != 0 ? r.get(0) + " Result size not equal to 0" : ""));
}
}
for (int i = 0; i < likePredicates3.length; i++) {
if (!useBindPrms) {
q = qs.newQuery("select p from /pos p where NOT (p like '" + likePredicates3[i] + "')");
results = (SelectResults) q.execute();
} else {
q = qs.newQuery("select p from /pos p where NOT (p like $1)");
results = (SelectResults) q.execute(new Object[] { likePredicates3[i] });
}
List r = results.asList();
if (r.size() != 1 || !r.get(0).equals(values[0])) {
fail("Unexprected result. expected :" + values[0] + " for the like predicate3: " + likePredicates3[i] + " found : " + (r.size() == 1 ? r.get(0) : "Result size not equal to 1"));
}
}
}
use of org.apache.geode.cache.AttributesFactory in project geode by apache.
the class LikePredicateJUnitTest method likePercentageTerminated_5.
private void likePercentageTerminated_5(boolean useBindPrm) throws Exception {
Cache cache = CacheUtils.getCache();
AttributesFactory attributesFactory = new AttributesFactory();
RegionAttributes regionAttributes = attributesFactory.create();
Region region = cache.createRegion("pos", regionAttributes);
char ch = 'd';
String base = "abc";
for (int i = 1; i < 6; ++i) {
Portfolio pf = new Portfolio(i);
pf.status = base + ch;
ch += 1;
region.put(new Integer(i), pf);
}
QueryService qs = cache.getQueryService();
Query q;
SelectResults results;
SelectResults expectedResults;
String predicate = "";
if (useBindPrm) {
predicate = "$1";
} else {
predicate = " 'a%c%'";
}
q = qs.newQuery("SELECT distinct * FROM /pos ps WHERE ps.status like " + predicate);
if (useBindPrm) {
results = (SelectResults) q.execute(new Object[] { "a%bc%" });
} else {
results = (SelectResults) q.execute();
}
ResultsBag bag = new ResultsBag(null);
for (int i = 1; i < 6; ++i) {
bag.add(region.get(new Integer(i)));
}
expectedResults = new ResultsCollectionWrapper(new ObjectTypeImpl(Object.class), bag.asSet());
SelectResults[][] rs = new SelectResults[][] { { results, expectedResults } };
CacheUtils.compareResultsOfWithAndWithoutIndex(rs, this);
// Create Index
qs.createIndex("status", IndexType.FUNCTIONAL, "ps.status", "/pos ps");
q = qs.newQuery("SELECT distinct * FROM /pos ps WHERE ps.status like " + predicate);
if (useBindPrm) {
results = (SelectResults) q.execute(new Object[] { "a%bc%" });
} else {
results = (SelectResults) q.execute();
}
rs = new SelectResults[][] { { results, expectedResults } };
CacheUtils.compareResultsOfWithAndWithoutIndex(rs, this);
if (useBindPrm) {
predicate = "$1";
} else {
predicate = "'abc_'";
}
q = qs.newQuery("SELECT distinct * FROM /pos ps WHERE ps.status like " + predicate);
if (useBindPrm) {
results = (SelectResults) q.execute(new Object[] { "abc_" });
} else {
results = (SelectResults) q.execute();
}
rs = new SelectResults[][] { { results, expectedResults } };
CacheUtils.compareResultsOfWithAndWithoutIndex(rs, this);
if (useBindPrm) {
predicate = "$1";
} else {
predicate = "'_bc_'";
}
q = qs.newQuery("SELECT distinct * FROM /pos ps WHERE ps.status like " + predicate);
if (useBindPrm) {
results = (SelectResults) q.execute(new Object[] { "_bc_" });
} else {
results = (SelectResults) q.execute();
}
rs = new SelectResults[][] { { results, expectedResults } };
CacheUtils.compareResultsOfWithAndWithoutIndex(rs, this);
}
use of org.apache.geode.cache.AttributesFactory in project geode by apache.
the class IndexWithSngleFrmAndMultCondQryJUnitTest method testIndexUsageIfTwoFieldsIndexedAndOneUnindexed.
/**
* Test index usage on PR region & Local region if the where clause contains three conditions with
* two conditions indexed & the total number of from clause iterators is 1.
*/
@Test
public void testIndexUsageIfTwoFieldsIndexedAndOneUnindexed() throws Exception {
AttributesFactory af = new AttributesFactory();
af.setValueConstraint(Portfolio.class);
RegionAttributes ra = af.createRegionAttributes();
Region region = CacheUtils.getCache().createRegion("pos", ra);
for (int i = 0; i < 5; i++) {
region.put("" + i, new Portfolio(i));
}
// As default generation of Portfolio objects
// The status is active for key =0 & key =2 & key =4
// The description is XXXX for key =1, key =3
// Let us make explitly
// Set createTime as 5 for three Portfolio objects of key =0 & key =1 & key=2;
// Description as XXXX for key =2 only.
// Thus out of 4 objects created only 1 object ( key =2 ) will have
// description = XXXX , status = active & time = 5
((Portfolio) region.get("0")).setCreateTime(5);
((Portfolio) region.get("1")).setCreateTime(5);
((Portfolio) region.get("2")).setCreateTime(5);
((Portfolio) region.get("2")).description = "XXXX";
int numSatisfyingOurCond = 0;
for (int i = 0; i < 5; i++) {
Portfolio pf = (Portfolio) region.get("" + i);
if (pf.description != null && pf.description.equals("XXXX") && pf.getCreateTime() == 5 && pf.isActive()) {
++numSatisfyingOurCond;
}
}
assertEquals(1, numSatisfyingOurCond);
executeQuery_3(region, true);
region.destroyRegion();
CacheUtils.closeCache();
CacheUtils.restartCache();
af = new AttributesFactory();
af.setValueConstraint(Portfolio.class);
PartitionAttributesFactory pfa = new PartitionAttributesFactory();
pfa.setRedundantCopies(0);
pfa.setTotalNumBuckets(1);
af.setPartitionAttributes(pfa.create());
ra = af.createRegionAttributes();
region = CacheUtils.getCache().createRegion("pos", ra);
for (int i = 0; i < 5; i++) {
region.put("" + i, new Portfolio(i));
}
// As default generation of Portfolio objects
// The status is active for key =0 & key =2 & key =4
// The description is XXXX for key =1, key =3
// Let us make explitly
// Set createTime as 5 for three Portfolio objects of key =0 & key =1 & key=2;
// Description as XXXX for key =2 only.
// Thus out of 4 objects created only 1 object ( key =2 ) will have
// description = XXXX , status = active & time = 5
Portfolio x = (Portfolio) region.get("0");
x.setCreateTime(5);
region.put("0", x);
x = (Portfolio) region.get("1");
x.setCreateTime(5);
region.put("1", x);
x = (Portfolio) region.get("2");
x.setCreateTime(5);
x.description = "XXXX";
region.put("2", x);
numSatisfyingOurCond = 0;
for (int i = 0; i < 5; i++) {
Portfolio pf = (Portfolio) region.get("" + i);
if (pf.description != null && pf.description.equals("XXXX") && pf.getCreateTime() == 5 && pf.isActive()) {
++numSatisfyingOurCond;
}
}
assertEquals(1, numSatisfyingOurCond);
executeQuery_3(region, false);
region.destroyRegion();
}
Aggregations