use of org.apache.geode.LogWriter in project geode by apache.
the class CompiledJunctionInternalsJUnitTest method oganizedOperandsSingleRangeJunctionCreation.
/**
* Tests the creation of a single RangeJunction if the CompiledJunction only contains same index
* condition with or without iter operand
*/
private OrganizedOperands oganizedOperandsSingleRangeJunctionCreation(int junctionType, CompiledValue[] operandsForCJ, ExecutionContext context) {
LogWriter logger = CacheUtils.getCache().getLogger();
OrganizedOperands oo = null;
try {
CompiledJunction cj = new CompiledJunction(operandsForCJ, junctionType);
context.addDependencies(new CompiledID("dummy"), cj.computeDependencies(context));
cj.getPlanInfo(context);
oo = cj.testOrganizedOperands(context);
return oo;
} catch (Exception e) {
logger.error(e);
fail(e.toString());
}
return oo;
}
use of org.apache.geode.LogWriter in project geode by apache.
the class CompiledJunctionInternalsJUnitTest method testOrganizedOperandsOfSingleRangeJunctionWithTwoIterOperandsForAND_3.
/**
* Tests the functionality of organizedOperands function of a RangeJunction which is an AND with
* two IterOperands but where the operator needs reflection. as the condition is Key > Path (
* which means Path less than Key) The RangeJunction boils down to a condition and a NOT EQUAL
* which will be evalauted as a SingleCondnEvaluator so the filter operand will be a
* SingleCondnEvaluator. Its Iter operand will be a CompiledJunction
*
*/
@Test
public void testOrganizedOperandsOfSingleRangeJunctionWithTwoIterOperandsForAND_3() {
LogWriter logger = CacheUtils.getCache().getLogger();
try {
CompiledComparison[] cv = null;
ExecutionContext context = new QueryExecutionContext(null, CacheUtils.getCache());
this.bindIteratorsAndCreateIndex(context);
// case1: a <7 and a<=5 and 2>a and 2> createTime and "xyz" > pid
// and 100 != a and 200 !=a and 1 != a
cv = new CompiledComparison[8];
cv[0] = new CompiledComparison(new CompiledPath(new CompiledID("p"), "ID"), new CompiledLiteral(new Integer(7)), OQLLexerTokenTypes.TOK_LT);
cv[1] = new CompiledComparison(new CompiledPath(new CompiledID("p"), "ID"), new CompiledLiteral(new Integer(5)), OQLLexerTokenTypes.TOK_LE);
cv[2] = new CompiledComparison(new CompiledLiteral(new Integer(2)), new CompiledPath(new CompiledID("p"), "ID"), OQLLexerTokenTypes.TOK_GT);
cv[3] = new CompiledComparison(new CompiledLiteral(new Integer(2)), new CompiledPath(new CompiledID("p"), "createTime"), OQLLexerTokenTypes.TOK_GT);
cv[4] = new CompiledComparison(new CompiledLiteral(new String("xyz")), new CompiledPath(new CompiledID("p"), "getPk"), OQLLexerTokenTypes.TOK_GT);
cv[5] = new CompiledComparison(new CompiledLiteral(new Integer(100)), new CompiledPath(new CompiledID("p"), "ID"), OQLLexerTokenTypes.TOK_NE);
cv[6] = new CompiledComparison(new CompiledLiteral(new Integer(200)), new CompiledPath(new CompiledID("p"), "ID"), OQLLexerTokenTypes.TOK_NE);
cv[7] = new CompiledComparison(new CompiledLiteral(new Integer(1)), new CompiledPath(new CompiledID("p"), "ID"), OQLLexerTokenTypes.TOK_NE);
OrganizedOperands oo = this.oganizedOperandsSingleRangeJunctionCreation(OQLLexerTokenTypes.LITERAL_and, cv, context);
assertNotNull("OrganizedOperand object is null", oo);
assertTrue("Filter Openad of OrganizedOperand is not of type RangeJunction", oo.filterOperand instanceof RangeJunction);
RangeJunction rj = (RangeJunction) oo.filterOperand;
assertEquals(cv.length, rj.getOperands().size());
OrganizedOperands oo1 = rj.organizeOperands(context);
assertNotNull(oo1);
assertTrue(oo1.iterateOperand instanceof CompiledJunction);
assertTrue(oo1.iterateOperand.getChildren().size() == 2);
assertTrue(oo1.iterateOperand.getChildren().get(0) == cv[3]);
assertTrue(oo1.iterateOperand.getChildren().get(1) == cv[4]);
assertTrue(RangeJunction.isInstanceOfSingleCondnEvaluator(oo1.filterOperand));
Set keysToRemove = RangeJunction.getKeysToBeRemoved(oo1.filterOperand);
assertEquals(1, keysToRemove.size());
assertTrue(keysToRemove.contains(new Integer(1)));
} catch (Exception e) {
logger.error(e);
fail(e.toString());
}
}
use of org.apache.geode.LogWriter in project geode by apache.
the class CompiledJunctionInternalsJUnitTest method testDoubleCondnRangeJunctionEvaluator_AND.
/**
* Tests the genuine range condition evaluator ( having a upper and lower bound) formed from a
* RangeJunction of type AND
*/
@Test
public void testDoubleCondnRangeJunctionEvaluator_AND() {
LogWriter logger = CacheUtils.getLogger();
try {
CompiledComparison[] cv = null;
ExecutionContext context = new QueryExecutionContext(null, CacheUtils.getCache());
this.bindIteratorsAndCreateIndex(context);
// Case 1 : a >= 7 and a <=10
cv = new CompiledComparison[2];
cv[0] = new CompiledComparison(new CompiledPath(new CompiledID("p"), "ID"), new CompiledLiteral(new Integer(7)), OQLLexerTokenTypes.TOK_GE);
cv[1] = new CompiledComparison(new CompiledPath(new CompiledID("p"), "ID"), new CompiledLiteral(new Integer(10)), OQLLexerTokenTypes.TOK_LE);
OrganizedOperands oo = this.oganizedOperandsSingleRangeJunctionCreation(OQLLexerTokenTypes.LITERAL_and, cv, context);
assertTrue("Filter Openad of OrganizedOperand is not of type RangeJunction", oo.filterOperand instanceof RangeJunction);
RangeJunction rj = (RangeJunction) oo.filterOperand;
OrganizedOperands oo1 = rj.organizeOperands(context);
assertTrue(RangeJunction.isInstanceOfDoubleCondnRangeJunctionEvaluator((oo1.filterOperand)));
assertTrue(RangeJunction.getDoubleCondnEvaluatorGreaterKey((oo1.filterOperand)).equals(new Integer(7)));
assertTrue(RangeJunction.getDoubleCondnEvaluatorOperatorOfGreaterType((oo1.filterOperand)) == OQLLexerTokenTypes.TOK_GE);
assertTrue(RangeJunction.getDoubleCondnEvaluatorLESSKey((oo1.filterOperand)).equals(new Integer(10)));
assertTrue(RangeJunction.getDoubleCondnEvaluatorOperatorOfLessType((oo1.filterOperand)) == OQLLexerTokenTypes.TOK_LE);
assertTrue(RangeJunction.getKeysToBeRemoved((oo1.filterOperand)) == null);
// Case2 : a >= 7 and a <=10 a >=5 and a <=11 and a != 7
cv = new CompiledComparison[5];
cv[0] = new CompiledComparison(new CompiledPath(new CompiledID("p"), "ID"), new CompiledLiteral(new Integer(7)), OQLLexerTokenTypes.TOK_GE);
cv[1] = new CompiledComparison(new CompiledPath(new CompiledID("p"), "ID"), new CompiledLiteral(new Integer(10)), OQLLexerTokenTypes.TOK_LE);
cv[2] = new CompiledComparison(new CompiledPath(new CompiledID("p"), "ID"), new CompiledLiteral(new Integer(5)), OQLLexerTokenTypes.TOK_GE);
cv[3] = new CompiledComparison(new CompiledPath(new CompiledID("p"), "ID"), new CompiledLiteral(new Integer(11)), OQLLexerTokenTypes.TOK_LE);
cv[4] = new CompiledComparison(new CompiledPath(new CompiledID("p"), "ID"), new CompiledLiteral(new Integer(7)), OQLLexerTokenTypes.TOK_NE);
oo = this.oganizedOperandsSingleRangeJunctionCreation(OQLLexerTokenTypes.LITERAL_and, cv, context);
assertTrue("Filter Openad of OrganizedOperand is not of type RangeJunction", oo.filterOperand instanceof RangeJunction);
rj = (RangeJunction) oo.filterOperand;
oo1 = rj.organizeOperands(context);
assertTrue(RangeJunction.isInstanceOfDoubleCondnRangeJunctionEvaluator((oo1.filterOperand)));
assertTrue(RangeJunction.getDoubleCondnEvaluatorGreaterKey((oo1.filterOperand)).equals(new Integer(7)));
assertTrue(RangeJunction.getDoubleCondnEvaluatorOperatorOfGreaterType((oo1.filterOperand)) == OQLLexerTokenTypes.TOK_GE);
assertTrue(RangeJunction.getDoubleCondnEvaluatorLESSKey((oo1.filterOperand)).equals(new Integer(10)));
assertTrue(RangeJunction.getDoubleCondnEvaluatorOperatorOfLessType((oo1.filterOperand)) == OQLLexerTokenTypes.TOK_LE);
Set keysToRemove = RangeJunction.getKeysToBeRemoved((oo1.filterOperand));
assertTrue(keysToRemove.size() == 1);
assertTrue(keysToRemove.iterator().next().equals(new Integer(7)));
// Case3 : a >= 7 and a <=6 and a >=8 and a <=5 and a != 7
cv = new CompiledComparison[5];
cv[0] = new CompiledComparison(new CompiledPath(new CompiledID("p"), "ID"), new CompiledLiteral(new Integer(7)), OQLLexerTokenTypes.TOK_GE);
cv[1] = new CompiledComparison(new CompiledPath(new CompiledID("p"), "ID"), new CompiledLiteral(new Integer(6)), OQLLexerTokenTypes.TOK_LE);
cv[2] = new CompiledComparison(new CompiledPath(new CompiledID("p"), "ID"), new CompiledLiteral(new Integer(8)), OQLLexerTokenTypes.TOK_GE);
cv[3] = new CompiledComparison(new CompiledPath(new CompiledID("p"), "ID"), new CompiledLiteral(new Integer(5)), OQLLexerTokenTypes.TOK_LE);
cv[4] = new CompiledComparison(new CompiledPath(new CompiledID("p"), "ID"), new CompiledLiteral(new Integer(7)), OQLLexerTokenTypes.TOK_NE);
oo = this.oganizedOperandsSingleRangeJunctionCreation(OQLLexerTokenTypes.LITERAL_and, cv, context);
assertTrue("Filter Openad of OrganizedOperand is not of type RangeJunction", oo.filterOperand instanceof RangeJunction);
rj = (RangeJunction) oo.filterOperand;
oo1 = rj.organizeOperands(context);
assertTrue(oo1.filterOperand instanceof CompiledLiteral);
assertFalse(((Boolean) ((CompiledLiteral) oo1.filterOperand).evaluate(context)).booleanValue());
// Case4 : a >= 7 and a <=6 and a >=8 and a <=5
cv = new CompiledComparison[4];
cv[0] = new CompiledComparison(new CompiledPath(new CompiledID("p"), "ID"), new CompiledLiteral(new Integer(7)), OQLLexerTokenTypes.TOK_GE);
cv[1] = new CompiledComparison(new CompiledPath(new CompiledID("p"), "ID"), new CompiledLiteral(new Integer(6)), OQLLexerTokenTypes.TOK_LE);
cv[2] = new CompiledComparison(new CompiledPath(new CompiledID("p"), "ID"), new CompiledLiteral(new Integer(8)), OQLLexerTokenTypes.TOK_GE);
cv[3] = new CompiledComparison(new CompiledPath(new CompiledID("p"), "ID"), new CompiledLiteral(new Integer(5)), OQLLexerTokenTypes.TOK_LE);
oo = this.oganizedOperandsSingleRangeJunctionCreation(OQLLexerTokenTypes.LITERAL_and, cv, context);
assertTrue("Filter Openad of OrganizedOperand is not of type RangeJunction", oo.filterOperand instanceof RangeJunction);
rj = (RangeJunction) oo.filterOperand;
oo1 = rj.organizeOperands(context);
assertTrue(oo1.filterOperand instanceof CompiledLiteral);
assertFalse(((Boolean) ((CompiledLiteral) oo1.filterOperand).evaluate(context)).booleanValue());
// Case5 : a >= 1 and a <=6 and a !=8
cv = new CompiledComparison[3];
cv[0] = new CompiledComparison(new CompiledPath(new CompiledID("p"), "ID"), new CompiledLiteral(new Integer(1)), OQLLexerTokenTypes.TOK_GE);
cv[1] = new CompiledComparison(new CompiledPath(new CompiledID("p"), "ID"), new CompiledLiteral(new Integer(6)), OQLLexerTokenTypes.TOK_LE);
cv[2] = new CompiledComparison(new CompiledPath(new CompiledID("p"), "ID"), new CompiledLiteral(new Integer(8)), OQLLexerTokenTypes.TOK_NE);
oo = this.oganizedOperandsSingleRangeJunctionCreation(OQLLexerTokenTypes.LITERAL_and, cv, context);
assertTrue("Filter Openad of OrganizedOperand is not of type RangeJunction", oo.filterOperand instanceof RangeJunction);
rj = (RangeJunction) oo.filterOperand;
oo1 = rj.organizeOperands(context);
assertTrue(RangeJunction.isInstanceOfDoubleCondnRangeJunctionEvaluator((oo1.filterOperand)));
assertTrue(RangeJunction.getDoubleCondnEvaluatorGreaterKey((oo1.filterOperand)).equals(new Integer(1)));
assertTrue(RangeJunction.getDoubleCondnEvaluatorOperatorOfGreaterType((oo1.filterOperand)) == OQLLexerTokenTypes.TOK_GE);
assertTrue(RangeJunction.getDoubleCondnEvaluatorLESSKey((oo1.filterOperand)).equals(new Integer(6)));
assertTrue(RangeJunction.getDoubleCondnEvaluatorOperatorOfLessType((oo1.filterOperand)) == OQLLexerTokenTypes.TOK_LE);
keysToRemove = RangeJunction.getKeysToBeRemoved((oo1.filterOperand));
assertTrue(keysToRemove == null);
// Case6 : a >= 1 and a <=6 and a !=8 and a!=2
cv = new CompiledComparison[4];
cv[0] = new CompiledComparison(new CompiledPath(new CompiledID("p"), "ID"), new CompiledLiteral(new Integer(1)), OQLLexerTokenTypes.TOK_GE);
cv[1] = new CompiledComparison(new CompiledPath(new CompiledID("p"), "ID"), new CompiledLiteral(new Integer(6)), OQLLexerTokenTypes.TOK_LE);
cv[2] = new CompiledComparison(new CompiledPath(new CompiledID("p"), "ID"), new CompiledLiteral(new Integer(8)), OQLLexerTokenTypes.TOK_NE);
cv[3] = new CompiledComparison(new CompiledPath(new CompiledID("p"), "ID"), new CompiledLiteral(new Integer(2)), OQLLexerTokenTypes.TOK_NE);
oo = this.oganizedOperandsSingleRangeJunctionCreation(OQLLexerTokenTypes.LITERAL_and, cv, context);
assertTrue("Filter Openad of OrganizedOperand is not of type RangeJunction", oo.filterOperand instanceof RangeJunction);
rj = (RangeJunction) oo.filterOperand;
oo1 = rj.organizeOperands(context);
assertTrue(RangeJunction.isInstanceOfDoubleCondnRangeJunctionEvaluator((oo1.filterOperand)));
assertTrue(RangeJunction.getDoubleCondnEvaluatorGreaterKey((oo1.filterOperand)).equals(new Integer(1)));
assertTrue(RangeJunction.getDoubleCondnEvaluatorOperatorOfGreaterType((oo1.filterOperand)) == OQLLexerTokenTypes.TOK_GE);
assertTrue(RangeJunction.getDoubleCondnEvaluatorLESSKey((oo1.filterOperand)).equals(new Integer(6)));
assertTrue(RangeJunction.getDoubleCondnEvaluatorOperatorOfLessType((oo1.filterOperand)) == OQLLexerTokenTypes.TOK_LE);
keysToRemove = RangeJunction.getKeysToBeRemoved((oo1.filterOperand));
assertTrue(keysToRemove.size() == 1);
assertTrue(keysToRemove.iterator().next().equals(new Integer(2)));
// Case7 : a >= 1 and a <=6 and a !=6 and a!=0
cv = new CompiledComparison[4];
cv[0] = new CompiledComparison(new CompiledPath(new CompiledID("p"), "ID"), new CompiledLiteral(new Integer(1)), OQLLexerTokenTypes.TOK_GE);
cv[1] = new CompiledComparison(new CompiledPath(new CompiledID("p"), "ID"), new CompiledLiteral(new Integer(6)), OQLLexerTokenTypes.TOK_LE);
cv[2] = new CompiledComparison(new CompiledPath(new CompiledID("p"), "ID"), new CompiledLiteral(new Integer(6)), OQLLexerTokenTypes.TOK_NE);
cv[3] = new CompiledComparison(new CompiledPath(new CompiledID("p"), "ID"), new CompiledLiteral(new Integer(0)), OQLLexerTokenTypes.TOK_NE);
oo = this.oganizedOperandsSingleRangeJunctionCreation(OQLLexerTokenTypes.LITERAL_and, cv, context);
assertTrue("Filter Openad of OrganizedOperand is not of type RangeJunction", oo.filterOperand instanceof RangeJunction);
rj = (RangeJunction) oo.filterOperand;
oo1 = rj.organizeOperands(context);
assertTrue(RangeJunction.isInstanceOfDoubleCondnRangeJunctionEvaluator((oo1.filterOperand)));
assertTrue(RangeJunction.getDoubleCondnEvaluatorGreaterKey((oo1.filterOperand)).equals(new Integer(1)));
assertTrue(RangeJunction.getDoubleCondnEvaluatorOperatorOfGreaterType((oo1.filterOperand)) == OQLLexerTokenTypes.TOK_GE);
assertTrue(RangeJunction.getDoubleCondnEvaluatorLESSKey((oo1.filterOperand)).equals(new Integer(6)));
assertTrue(RangeJunction.getDoubleCondnEvaluatorOperatorOfLessType((oo1.filterOperand)) == OQLLexerTokenTypes.TOK_LE);
keysToRemove = RangeJunction.getKeysToBeRemoved((oo1.filterOperand));
assertTrue(keysToRemove.size() == 1);
assertTrue(keysToRemove.iterator().next().equals(new Integer(6)));
} catch (Exception e) {
logger.error(e);
fail(e.toString());
}
}
use of org.apache.geode.LogWriter in project geode by apache.
the class CompiledJunctionInternalsJUnitTest method testOrganizeOpsOfRangeJunctionForNonRangeEvaluatableOperand.
@Test
public void testOrganizeOpsOfRangeJunctionForNonRangeEvaluatableOperand() {
LogWriter logger = CacheUtils.getLogger();
try {
CompiledValue[] cv = null;
ExecutionContext context = new QueryExecutionContext(null, CacheUtils.getCache());
this.bindIteratorsAndCreateIndex(context);
// Case 1 : a != null and a != null and a != undefined
cv = new CompiledValue[3];
cv[0] = new CompiledComparison(new CompiledPath(new CompiledID("p"), "ID"), new CompiledLiteral(null), OQLLexerTokenTypes.TOK_NE);
cv[1] = new CompiledComparison(new CompiledPath(new CompiledID("p"), "ID"), new CompiledLiteral(null), OQLLexerTokenTypes.TOK_NE);
cv[2] = new CompiledUndefined(new CompiledPath(new CompiledID("p"), "ID"), false);
OrganizedOperands oo = this.oganizedOperandsSingleRangeJunctionCreation(OQLLexerTokenTypes.LITERAL_and, cv, context);
assertTrue("Filter Openad of OrganizedOperand is not of type RangeJunction", oo.filterOperand instanceof RangeJunction);
RangeJunction rj = (RangeJunction) oo.filterOperand;
OrganizedOperands oo1 = rj.organizeOperands(context);
assertTrue(oo1.filterOperand instanceof GroupJunction);
CompiledValue[] ops = ((GroupJunction) oo1.filterOperand)._operands;
assertTrue(ops[0] == cv[0] || ops[0] == cv[1] || ops[0] == cv[2]);
assertTrue(ops[1] == cv[0] || ops[1] == cv[1] || ops[1] == cv[2]);
assertTrue(ops[2] == cv[0] || ops[2] == cv[1] || ops[2] == cv[2]);
} catch (Exception e) {
logger.error(e);
fail(e.toString());
}
}
use of org.apache.geode.LogWriter in project geode by apache.
the class CompiledJunctionInternalsJUnitTest method testOrganizedOperandsOfSingleRangeJunctionWithTwoIterOperandsForAND_2.
/**
* Tests the functionality of organizedOperands function of a RangeJunction which is an AND with
* two IterOperands but where the operator needs reflection. as the condition is Key > Path (
* which means Path less than Key) The RangeJunction boils down to a single condition which can be
* evalauted as a CompiledComparison so the filter operand will be a CompiledComparison. Thus the
* organizdeOperand's filter operand will be a CompiledComparison while its Iteroperand will be a
* CompiledJunction
*
*/
@Test
public void testOrganizedOperandsOfSingleRangeJunctionWithTwoIterOperandsForAND_2() {
LogWriter logger = CacheUtils.getCache().getLogger();
try {
CompiledComparison[] cv = null;
ExecutionContext context = new QueryExecutionContext(null, CacheUtils.getCache());
this.bindIteratorsAndCreateIndex(context);
cv = new CompiledComparison[5];
cv[0] = new CompiledComparison(new CompiledPath(new CompiledID("p"), "ID"), new CompiledLiteral(new Integer(7)), OQLLexerTokenTypes.TOK_LT);
cv[1] = new CompiledComparison(new CompiledPath(new CompiledID("p"), "ID"), new CompiledLiteral(new Integer(5)), OQLLexerTokenTypes.TOK_LE);
cv[2] = new CompiledComparison(new CompiledLiteral(new Integer(2)), new CompiledPath(new CompiledID("p"), "ID"), OQLLexerTokenTypes.TOK_GT);
cv[3] = new CompiledComparison(new CompiledLiteral(new Integer(2)), new CompiledPath(new CompiledID("p"), "createTime"), OQLLexerTokenTypes.TOK_GT);
cv[4] = new CompiledComparison(new CompiledLiteral(new String("xyz")), new CompiledPath(new CompiledID("p"), "getPk"), OQLLexerTokenTypes.TOK_GT);
OrganizedOperands oo = this.oganizedOperandsSingleRangeJunctionCreation(OQLLexerTokenTypes.LITERAL_and, cv, context);
assertNotNull("OrganizedOperand object is null", oo);
assertTrue("Filter Openad of OrganizedOperand is not of type RangeJunction", oo.filterOperand instanceof RangeJunction);
RangeJunction rj = (RangeJunction) oo.filterOperand;
assertEquals(cv.length, rj.getOperands().size());
OrganizedOperands oo1 = rj.organizeOperands(context);
assertNotNull(oo1);
assertTrue(oo1.iterateOperand instanceof CompiledJunction);
assertTrue(oo1.iterateOperand.getChildren().size() == 2);
assertTrue(oo1.iterateOperand.getChildren().get(0) == cv[3]);
assertTrue(oo1.iterateOperand.getChildren().get(1) == cv[4]);
assertEquals(oo1.filterOperand, cv[2]);
} catch (Exception e) {
logger.error(e);
fail(e.toString());
}
}
Aggregations