Search in sources :

Example 21 with LogWriter

use of org.apache.geode.LogWriter in project geode by apache.

the class CompiledJunctionInternalsJUnitTest method testEqualConditionInRangeJunction_AND.

/**
   * Test presence of equal condition in a AND RangeJunction An equal condition if accompanied by
   * any other condition in a RangeJunction ( except not null) should always return the equal
   * condition or a boolean false indicating empty resultset
   */
@Test
public void testEqualConditionInRangeJunction_AND() {
    LogWriter logger = CacheUtils.getLogger();
    try {
        CompiledComparison[] cv = null;
        ExecutionContext context = new QueryExecutionContext(null, CacheUtils.getCache());
        this.bindIteratorsAndCreateIndex(context);
        /**
       * ******************For all LESS THAN OR LESS THAN EQUAL To ********************
       */
        // Case 1 : a = 7 and a !=4 and a != 5 and a != 8
        cv = new CompiledComparison[4];
        cv[0] = new CompiledComparison(new CompiledPath(new CompiledID("p"), "ID"), new CompiledLiteral(new Integer(7)), OQLLexerTokenTypes.TOK_EQ);
        cv[1] = new CompiledComparison(new CompiledPath(new CompiledID("p"), "ID"), new CompiledLiteral(new Integer(4)), OQLLexerTokenTypes.TOK_NE);
        cv[2] = new CompiledComparison(new CompiledPath(new CompiledID("p"), "ID"), new CompiledLiteral(new Integer(5)), OQLLexerTokenTypes.TOK_NE);
        cv[3] = new CompiledComparison(new CompiledPath(new CompiledID("p"), "ID"), new CompiledLiteral(new Integer(8)), OQLLexerTokenTypes.TOK_NE);
        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);
        assertEquals(oo1.filterOperand, cv[0]);
        // Case 2 : a > 7 and a !=4 and a != 5 and a = 8
        cv = new CompiledComparison[4];
        cv[0] = new CompiledComparison(new CompiledPath(new CompiledID("p"), "ID"), new CompiledLiteral(new Integer(7)), OQLLexerTokenTypes.TOK_GT);
        cv[1] = new CompiledComparison(new CompiledPath(new CompiledID("p"), "ID"), new CompiledLiteral(new Integer(4)), OQLLexerTokenTypes.TOK_NE);
        cv[2] = new CompiledComparison(new CompiledPath(new CompiledID("p"), "ID"), new CompiledLiteral(new Integer(5)), OQLLexerTokenTypes.TOK_NE);
        cv[3] = new CompiledComparison(new CompiledPath(new CompiledID("p"), "ID"), new CompiledLiteral(new Integer(8)), OQLLexerTokenTypes.TOK_EQ);
        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);
        assertEquals(oo1.filterOperand, cv[3]);
        // Case3 : a < 7 and a !=4 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_LT);
        cv[1] = new CompiledComparison(new CompiledPath(new CompiledID("p"), "ID"), new CompiledLiteral(new Integer(4)), OQLLexerTokenTypes.TOK_NE);
        cv[2] = new CompiledComparison(new CompiledPath(new CompiledID("p"), "ID"), new CompiledLiteral(new Integer(8)), OQLLexerTokenTypes.TOK_EQ);
        cv[3] = new CompiledComparison(new CompiledPath(new CompiledID("p"), "ID"), new CompiledLiteral(new Integer(5)), 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 !=4 and a !=8 and a = 14
        cv = new CompiledComparison[4];
        cv[0] = new CompiledComparison(new CompiledPath(new CompiledID("p"), "ID"), new CompiledLiteral(new Integer(7)), OQLLexerTokenTypes.TOK_GT);
        cv[1] = new CompiledComparison(new CompiledPath(new CompiledID("p"), "ID"), new CompiledLiteral(new Integer(4)), OQLLexerTokenTypes.TOK_NE);
        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(14)), OQLLexerTokenTypes.TOK_EQ);
        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 == cv[3]);
        // Case5 : a <= 14 and a !=4 and a !=8 and a = 14
        cv = new CompiledComparison[4];
        cv[0] = new CompiledComparison(new CompiledPath(new CompiledID("p"), "ID"), new CompiledLiteral(new Integer(14)), OQLLexerTokenTypes.TOK_LE);
        cv[1] = new CompiledComparison(new CompiledPath(new CompiledID("p"), "ID"), new CompiledLiteral(new Integer(4)), OQLLexerTokenTypes.TOK_NE);
        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(14)), OQLLexerTokenTypes.TOK_EQ);
        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 == cv[3]);
        // Case6 : a >= 14 and a !=4 and a !=8 and a = 14
        cv = new CompiledComparison[4];
        cv[0] = new CompiledComparison(new CompiledPath(new CompiledID("p"), "ID"), new CompiledLiteral(new Integer(14)), OQLLexerTokenTypes.TOK_GE);
        cv[1] = new CompiledComparison(new CompiledPath(new CompiledID("p"), "ID"), new CompiledLiteral(new Integer(4)), OQLLexerTokenTypes.TOK_NE);
        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(14)), OQLLexerTokenTypes.TOK_EQ);
        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 == cv[3]);
        // Case7 : a >= 14 and a !=4 and a =9 and a = 14
        cv = new CompiledComparison[4];
        cv[0] = new CompiledComparison(new CompiledPath(new CompiledID("p"), "ID"), new CompiledLiteral(new Integer(14)), OQLLexerTokenTypes.TOK_GE);
        cv[1] = new CompiledComparison(new CompiledPath(new CompiledID("p"), "ID"), new CompiledLiteral(new Integer(4)), OQLLexerTokenTypes.TOK_NE);
        cv[2] = new CompiledComparison(new CompiledPath(new CompiledID("p"), "ID"), new CompiledLiteral(new Integer(9)), OQLLexerTokenTypes.TOK_EQ);
        cv[3] = new CompiledComparison(new CompiledPath(new CompiledID("p"), "ID"), new CompiledLiteral(new Integer(14)), OQLLexerTokenTypes.TOK_EQ);
        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());
        // Case8 : a > 7 and a !=4 and a !=8 and a = 14 and a <18
        cv = new CompiledComparison[5];
        cv[0] = new CompiledComparison(new CompiledPath(new CompiledID("p"), "ID"), new CompiledLiteral(new Integer(7)), OQLLexerTokenTypes.TOK_GT);
        cv[1] = new CompiledComparison(new CompiledPath(new CompiledID("p"), "ID"), new CompiledLiteral(new Integer(4)), OQLLexerTokenTypes.TOK_NE);
        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(14)), OQLLexerTokenTypes.TOK_EQ);
        cv[4] = new CompiledComparison(new CompiledPath(new CompiledID("p"), "ID"), new CompiledLiteral(new Integer(18)), OQLLexerTokenTypes.TOK_LT);
        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 == cv[3]);
        // case9:a > 7 and a !=4 and a !=8 and a = 14 and a <14
        cv = new CompiledComparison[5];
        cv[0] = new CompiledComparison(new CompiledPath(new CompiledID("p"), "ID"), new CompiledLiteral(new Integer(14)), OQLLexerTokenTypes.TOK_GT);
        cv[1] = new CompiledComparison(new CompiledPath(new CompiledID("p"), "ID"), new CompiledLiteral(new Integer(4)), OQLLexerTokenTypes.TOK_NE);
        cv[2] = new CompiledComparison(new CompiledPath(new CompiledID("p"), "ID"), new CompiledLiteral(new Integer(9)), OQLLexerTokenTypes.TOK_EQ);
        cv[3] = new CompiledComparison(new CompiledPath(new CompiledID("p"), "ID"), new CompiledLiteral(new Integer(14)), OQLLexerTokenTypes.TOK_EQ);
        cv[4] = new CompiledComparison(new CompiledPath(new CompiledID("p"), "ID"), new CompiledLiteral(new Integer(14)), OQLLexerTokenTypes.TOK_LT);
        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());
    } catch (Exception e) {
        logger.error(e.toString());
    }
}
Also used : LogWriter(org.apache.geode.LogWriter) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 22 with LogWriter

use of org.apache.geode.LogWriter in project geode by apache.

the class CompiledJunctionInternalsJUnitTest method testNullorNotNullorUndefinedBehaviour.

/**
   * Tests if the presence of UNDEFINED operand is treated as a separate eval operand & not made a
   * part of SingleCondn or DoubleCondn evaluator
   */
@Test
public void testNullorNotNullorUndefinedBehaviour() {
    LogWriter logger = CacheUtils.getLogger();
    try {
        CompiledComparison[] cv = null;
        ExecutionContext context = new QueryExecutionContext(null, CacheUtils.getCache());
        this.bindIteratorsAndCreateIndex(context);
        // Case 1 : a >= 7 and a != null
        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(null), OQLLexerTokenTypes.TOK_EQ);
        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[] operands = ((GroupJunction) oo1.filterOperand)._operands;
        assertEquals(2, operands.length);
        assertTrue(operands[0] == cv[0] || operands[0] == cv[1]);
        assertTrue(operands[1] == cv[0] || operands[1] == cv[1]);
        // Case 2 : a >= 7 and a != null and a!=5
        cv = new CompiledComparison[3];
        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(null), OQLLexerTokenTypes.TOK_NE);
        cv[2] = new CompiledComparison(new CompiledPath(new CompiledID("p"), "ID"), new CompiledLiteral(new Integer(5)), 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 GroupJunction);
        operands = ((GroupJunction) oo1.filterOperand)._operands;
        assertEquals(2, operands.length);
        assertTrue(cv[1] == operands[0] || cv[1] == operands[1]);
        assertTrue(cv[0] == operands[0] || cv[0] == operands[1]);
        // Case 3 : a >= 7 and a != null and a!=7
        cv = new CompiledComparison[3];
        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(null), OQLLexerTokenTypes.TOK_NE);
        cv[2] = 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 GroupJunction);
        operands = ((GroupJunction) oo1.filterOperand)._operands;
        assertEquals(2, operands.length);
        assertTrue(cv[1] == operands[0] || cv[1] == operands[1]);
        assertTrue(RangeJunction.isInstanceOfSingleCondnEvaluator(operands[0]) || RangeJunction.isInstanceOfSingleCondnEvaluator(operands[1]));
        int x = -1;
        if (RangeJunction.isInstanceOfSingleCondnEvaluator(operands[0])) {
            x = 0;
        } else if (RangeJunction.isInstanceOfSingleCondnEvaluator(operands[1])) {
            x = 1;
        }
        Object key = RangeJunction.getSingleCondnEvaluatorKey(operands[x]);
        assertTrue(key.equals(new Integer(7)));
        assertTrue(RangeJunction.getSingleCondnEvaluatorOperator(operands[x]) == OQLLexerTokenTypes.TOK_GE);
        assertTrue(RangeJunction.getKeysToBeRemoved(operands[x]).size() == 1);
        assertTrue(RangeJunction.getKeysToBeRemoved(operands[x]).iterator().next().equals(new Integer(7)));
        // Case 4 : a >= 7 and a == null and a!=7 and a = undefined
        CompiledValue[] cv1 = new CompiledValue[4];
        cv1[0] = new CompiledComparison(new CompiledPath(new CompiledID("p"), "ID"), new CompiledLiteral(new Integer(7)), OQLLexerTokenTypes.TOK_GE);
        cv1[1] = new CompiledComparison(new CompiledPath(new CompiledID("p"), "ID"), new CompiledLiteral(null), OQLLexerTokenTypes.TOK_EQ);
        cv1[2] = new CompiledComparison(new CompiledPath(new CompiledID("p"), "ID"), new CompiledLiteral(new Integer(7)), OQLLexerTokenTypes.TOK_NE);
        cv1[3] = new CompiledUndefined(new CompiledPath(new CompiledID("p"), "ID"), false);
        oo = this.oganizedOperandsSingleRangeJunctionCreation(OQLLexerTokenTypes.LITERAL_and, cv1, 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 GroupJunction);
        assertEquals(((GroupJunction) oo1.filterOperand)._operands.length, 3);
        CompiledValue[] ops = ((GroupJunction) oo1.filterOperand)._operands;
        assertTrue(ops[0] == cv1[1] || ops[1] == cv1[1] || ops[2] == cv1[1]);
        assertTrue(ops[0] == cv1[3] || ops[1] == cv1[3] || ops[2] == cv1[3]);
        assertTrue(RangeJunction.isInstanceOfSingleCondnEvaluator(ops[0]) || RangeJunction.isInstanceOfSingleCondnEvaluator(ops[1]) || RangeJunction.isInstanceOfSingleCondnEvaluator(ops[2]));
        x = -1;
        if (RangeJunction.isInstanceOfSingleCondnEvaluator(ops[0])) {
            x = 0;
        } else if (RangeJunction.isInstanceOfSingleCondnEvaluator(ops[1])) {
            x = 1;
        } else if (RangeJunction.isInstanceOfSingleCondnEvaluator(ops[2])) {
            x = 2;
        }
        key = RangeJunction.getSingleCondnEvaluatorKey(ops[x]);
        assertTrue(key.equals(new Integer(7)));
        assertTrue(RangeJunction.getSingleCondnEvaluatorOperator(ops[x]) == OQLLexerTokenTypes.TOK_GE);
        assertTrue(RangeJunction.getKeysToBeRemoved(ops[x]).size() == 1);
        assertTrue(RangeJunction.getKeysToBeRemoved(ops[x]).iterator().next().equals(new Integer(7)));
        // Case 5 : a >= 7 and a == null and a == 6 and a = undefined and
        // createTime = 6
        cv1 = new CompiledValue[5];
        cv1[0] = new CompiledComparison(new CompiledPath(new CompiledID("p"), "ID"), new CompiledLiteral(new Integer(7)), OQLLexerTokenTypes.TOK_GE);
        cv1[1] = new CompiledComparison(new CompiledPath(new CompiledID("p"), "ID"), new CompiledLiteral(null), OQLLexerTokenTypes.TOK_EQ);
        cv1[2] = new CompiledComparison(new CompiledPath(new CompiledID("p"), "ID"), new CompiledLiteral(new Integer(6)), OQLLexerTokenTypes.TOK_EQ);
        cv1[3] = new CompiledUndefined(new CompiledPath(new CompiledID("p"), "ID"), false);
        cv1[4] = new CompiledComparison(new CompiledPath(new CompiledID("p"), "createTime"), new CompiledLiteral(new Long(6)), OQLLexerTokenTypes.TOK_EQ);
        oo = this.oganizedOperandsSingleRangeJunctionCreation(OQLLexerTokenTypes.LITERAL_and, cv1, 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());
        assertNull(oo1.iterateOperand);
        // Case 6 : a >= 7 and a == null and a == 8 and a = undefined and
        // createTime = 6
        cv1 = new CompiledValue[5];
        cv1[0] = new CompiledComparison(new CompiledPath(new CompiledID("p"), "ID"), new CompiledLiteral(new Integer(7)), OQLLexerTokenTypes.TOK_GE);
        cv1[1] = new CompiledComparison(new CompiledPath(new CompiledID("p"), "ID"), new CompiledLiteral(null), OQLLexerTokenTypes.TOK_EQ);
        cv1[2] = new CompiledComparison(new CompiledPath(new CompiledID("p"), "ID"), new CompiledLiteral(new Integer(8)), OQLLexerTokenTypes.TOK_EQ);
        cv1[3] = new CompiledUndefined(new CompiledPath(new CompiledID("p"), "ID"), false);
        cv1[4] = new CompiledComparison(new CompiledPath(new CompiledID("p"), "createTime"), new CompiledLiteral(new Long(6)), OQLLexerTokenTypes.TOK_EQ);
        oo = this.oganizedOperandsSingleRangeJunctionCreation(OQLLexerTokenTypes.LITERAL_and, cv1, 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 GroupJunction);
        operands = ((GroupJunction) oo1.filterOperand)._operands;
        assertEquals(operands.length, 3);
        assertTrue(cv1[1] == operands[0] || cv1[1] == operands[1] || cv1[1] == operands[2]);
        assertTrue(cv1[2] == operands[0] || cv1[2] == operands[1] || cv1[2] == operands[2]);
        assertTrue(cv1[3] == operands[0] || cv1[3] == operands[1] || cv1[3] == operands[2]);
        assertTrue(oo1.iterateOperand == cv1[4]);
    } catch (Exception e) {
        logger.error(e.toString());
        fail(e.toString());
    }
}
Also used : LogWriter(org.apache.geode.LogWriter) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 23 with LogWriter

use of org.apache.geode.LogWriter in project geode by apache.

the class CompiledJunctionInternalsJUnitTest method testNotEqualConditionEvaluator_AND.

/**
   * Tests the correct creation of NotEqualConditionEvaluator For AND junction
   * 
   */
@Test
public void testNotEqualConditionEvaluator_AND() {
    LogWriter logger = CacheUtils.getLogger();
    try {
        CompiledComparison[] cv = null;
        ExecutionContext context = new QueryExecutionContext(null, CacheUtils.getCache());
        this.bindIteratorsAndCreateIndex(context);
        /**
       * ******************For all LESS THAN OR LESS THAN EQUAL To ********************
       */
        // Case 1 : a != 7 and a !=4 and a != 5 and a != 5
        cv = new CompiledComparison[4];
        cv[0] = new CompiledComparison(new CompiledPath(new CompiledID("p"), "ID"), new CompiledLiteral(new Integer(7)), OQLLexerTokenTypes.TOK_NE);
        cv[1] = new CompiledComparison(new CompiledPath(new CompiledID("p"), "ID"), new CompiledLiteral(new Integer(4)), OQLLexerTokenTypes.TOK_NE);
        cv[2] = new CompiledComparison(new CompiledPath(new CompiledID("p"), "ID"), new CompiledLiteral(new Integer(5)), OQLLexerTokenTypes.TOK_NE);
        cv[3] = new CompiledComparison(new CompiledPath(new CompiledID("p"), "ID"), new CompiledLiteral(new Integer(5)), OQLLexerTokenTypes.TOK_NE);
        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.isInstanceOfNotEqualConditionEvaluator(oo1.filterOperand));
        Set keysRemove = RangeJunction.getKeysToBeRemoved(oo1.filterOperand);
        assertTrue(keysRemove.size() == 3);
        assertTrue(keysRemove.contains(new Integer(5)));
        assertTrue(keysRemove.contains(new Integer(7)));
        assertTrue(keysRemove.contains(new Integer(4)));
        // Case 2 : a != 7 and a != null and a != undefined
        CompiledValue[] cv1 = new CompiledValue[3];
        cv1[0] = new CompiledComparison(new CompiledPath(new CompiledID("p"), "ID"), new CompiledLiteral(new Integer(7)), OQLLexerTokenTypes.TOK_NE);
        cv1[1] = new CompiledComparison(new CompiledPath(new CompiledID("p"), "ID"), new CompiledLiteral(null), OQLLexerTokenTypes.TOK_NE);
        cv1[2] = new CompiledUndefined(new CompiledPath(new CompiledID("p"), "ID"), false);
        oo = this.oganizedOperandsSingleRangeJunctionCreation(OQLLexerTokenTypes.LITERAL_and, cv1, 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 GroupJunction);
        CompiledValue[] ops = ((GroupJunction) oo1.filterOperand)._operands;
        // assertTrue(cv1[0] == ops[0] || cv1[0] == ops[1] || cv1[0] == ops[2]);
        if (RangeJunction.isInstanceOfNotEqualConditionEvaluator(ops[0])) {
            assertTrue(RangeJunction.getKeysToBeRemoved(ops[0]).iterator().next().equals(new Integer(7)));
        } else if (RangeJunction.isInstanceOfNotEqualConditionEvaluator(ops[1])) {
            assertTrue(RangeJunction.getKeysToBeRemoved(ops[1]).iterator().next().equals(new Integer(7)));
        } else if (RangeJunction.isInstanceOfNotEqualConditionEvaluator(ops[2])) {
            assertTrue(RangeJunction.getKeysToBeRemoved(ops[2]).iterator().next().equals(new Integer(7)));
        } else {
            fail("NotEqualConditionEvaluator not found");
        }
        assertTrue(cv1[1] == ops[0] || cv1[1] == ops[1] || cv1[1] == ops[2]);
        assertTrue(cv1[2] == ops[0] || cv1[2] == ops[1] || cv1[2] == ops[2]);
    } catch (Exception e) {
        logger.error(e.toString());
        fail(e.toString());
    }
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) LogWriter(org.apache.geode.LogWriter) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 24 with LogWriter

use of org.apache.geode.LogWriter in project geode by apache.

the class CompiledJunctionInternalsJUnitTest method testOrganizedOperandsSingleCondnEvalMultipleGreaterThanInEqualities_AND.

/**
   * Tests the functionality of organizedOperands function of a RangeJunction for various
   * combinations of GREATER THAN and Not equal conditions etc which results in a
   * SingleCondnEvaluator or CompiledComparison for a AND junction. It checks the correctness of the
   * operator & the evaluated key
   * 
   */
@Test
public void testOrganizedOperandsSingleCondnEvalMultipleGreaterThanInEqualities_AND() {
    LogWriter logger = CacheUtils.getCache().getLogger();
    try {
        CompiledComparison[] cv = null;
        ExecutionContext context = new QueryExecutionContext(null, CacheUtils.getCache());
        this.bindIteratorsAndCreateIndex(context);
        /** **********For ALL greater or greater than combinations********* */
        // Case 1 : a >7 and a >=4 and a > 5 and a > 7
        cv = new CompiledComparison[4];
        cv[0] = new CompiledComparison(new CompiledPath(new CompiledID("p"), "ID"), new CompiledLiteral(new Integer(7)), OQLLexerTokenTypes.TOK_GT);
        cv[1] = new CompiledComparison(new CompiledPath(new CompiledID("p"), "ID"), new CompiledLiteral(new Integer(4)), OQLLexerTokenTypes.TOK_GE);
        cv[2] = new CompiledComparison(new CompiledPath(new CompiledID("p"), "ID"), new CompiledLiteral(new Integer(5)), OQLLexerTokenTypes.TOK_GT);
        cv[3] = new CompiledComparison(new CompiledPath(new CompiledID("p"), "ID"), new CompiledLiteral(new Integer(7)), OQLLexerTokenTypes.TOK_GT);
        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 == cv[0] || oo1.filterOperand == cv[3]);
        // Case2: a>=8 and a >4 and a>=6 and a>=8
        cv[0] = new CompiledComparison(new CompiledPath(new CompiledID("p"), "ID"), new CompiledLiteral(new Integer(8)), OQLLexerTokenTypes.TOK_GE);
        cv[1] = new CompiledComparison(new CompiledPath(new CompiledID("p"), "ID"), new CompiledLiteral(new Integer(4)), OQLLexerTokenTypes.TOK_GE);
        cv[2] = new CompiledComparison(new CompiledPath(new CompiledID("p"), "ID"), new CompiledLiteral(new Integer(6)), OQLLexerTokenTypes.TOK_GE);
        cv[3] = new CompiledComparison(new CompiledPath(new CompiledID("p"), "ID"), new CompiledLiteral(new Integer(8)), OQLLexerTokenTypes.TOK_GE);
        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 == cv[0] || oo1.filterOperand == cv[3]);
        cv = new CompiledComparison[5];
        // Case 3 : 7 < a and a >=4 and a > 5 and a >= 7 and a != 15
        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(4)), OQLLexerTokenTypes.TOK_GE);
        cv[2] = new CompiledComparison(new CompiledPath(new CompiledID("p"), "ID"), new CompiledLiteral(new Integer(5)), OQLLexerTokenTypes.TOK_GT);
        cv[3] = new CompiledComparison(new CompiledLiteral(new Integer(7)), new CompiledPath(new CompiledID("p"), "ID"), OQLLexerTokenTypes.TOK_LT);
        cv[4] = new CompiledComparison(new CompiledPath(new CompiledID("p"), "ID"), new CompiledLiteral(new Integer(15)), OQLLexerTokenTypes.TOK_NE);
        oo = this.oganizedOperandsSingleRangeJunctionCreation(OQLLexerTokenTypes.LITERAL_and, cv, context);
        rj = (RangeJunction) oo.filterOperand;
        oo1 = rj.organizeOperands(context);
        assertTrue(RangeJunction.isInstanceOfSingleCondnEvaluator(oo1.filterOperand));
        assertTrue(RangeJunction.getSingleCondnEvaluatorOperator(oo1.filterOperand) == OQLLexerTokenTypes.TOK_GT);
        assertTrue(RangeJunction.getSingleCondnEvaluatorKey(oo1.filterOperand).equals(new Integer(7)));
        assertTrue(RangeJunction.getIndex(oo1.filterOperand).getName().equals("idIndex"));
        assertTrue(RangeJunction.getKeysToBeRemoved(oo1.filterOperand).size() == 1 && RangeJunction.getKeysToBeRemoved(oo1.filterOperand).iterator().next().equals(new Integer(15)));
        // Case 4 : 7 < a and a >=7
        cv = new CompiledComparison[2];
        cv[0] = new CompiledComparison(new CompiledLiteral(new Integer(7)), new CompiledPath(new CompiledID("p"), "ID"), OQLLexerTokenTypes.TOK_LT);
        cv[1] = new CompiledComparison(new CompiledPath(new CompiledID("p"), "ID"), new CompiledLiteral(new Integer(7)), OQLLexerTokenTypes.TOK_GE);
        oo = this.oganizedOperandsSingleRangeJunctionCreation(OQLLexerTokenTypes.LITERAL_and, cv, context);
        rj = (RangeJunction) oo.filterOperand;
        oo1 = rj.organizeOperands(context);
        assertTrue(oo1.filterOperand == cv[0]);
        // Case 5 : a > 7 and a >=7
        cv = new CompiledComparison[2];
        cv[0] = new CompiledComparison(new CompiledPath(new CompiledID("p"), "ID"), new CompiledLiteral(new Integer(7)), OQLLexerTokenTypes.TOK_GT);
        cv[1] = new CompiledComparison(new CompiledPath(new CompiledID("p"), "ID"), new CompiledLiteral(new Integer(7)), OQLLexerTokenTypes.TOK_GE);
        oo = this.oganizedOperandsSingleRangeJunctionCreation(OQLLexerTokenTypes.LITERAL_and, cv, context);
        rj = (RangeJunction) oo.filterOperand;
        oo1 = rj.organizeOperands(context);
        assertTrue(oo1.filterOperand == cv[0]);
        // Case 6 : a >= 7 and a >7
        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(7)), OQLLexerTokenTypes.TOK_GT);
        oo = this.oganizedOperandsSingleRangeJunctionCreation(OQLLexerTokenTypes.LITERAL_and, cv, context);
        rj = (RangeJunction) oo.filterOperand;
        oo1 = rj.organizeOperands(context);
        assertTrue(oo1.filterOperand == cv[1]);
        // Case 7 : a >= 8 and a >7
        cv = new CompiledComparison[2];
        cv[0] = new CompiledComparison(new CompiledPath(new CompiledID("p"), "ID"), new CompiledLiteral(new Integer(8)), OQLLexerTokenTypes.TOK_GE);
        cv[1] = new CompiledComparison(new CompiledPath(new CompiledID("p"), "ID"), new CompiledLiteral(new Integer(7)), OQLLexerTokenTypes.TOK_GT);
        oo = this.oganizedOperandsSingleRangeJunctionCreation(OQLLexerTokenTypes.LITERAL_and, cv, context);
        rj = (RangeJunction) oo.filterOperand;
        oo1 = rj.organizeOperands(context);
        assertTrue(oo1.filterOperand == cv[0]);
        // Case 8 : a >=8 and a > =7
        cv = new CompiledComparison[2];
        cv[0] = new CompiledComparison(new CompiledPath(new CompiledID("p"), "ID"), new CompiledLiteral(new Integer(8)), OQLLexerTokenTypes.TOK_GE);
        cv[1] = new CompiledComparison(new CompiledPath(new CompiledID("p"), "ID"), new CompiledLiteral(new Integer(7)), OQLLexerTokenTypes.TOK_GE);
        oo = this.oganizedOperandsSingleRangeJunctionCreation(OQLLexerTokenTypes.LITERAL_and, cv, context);
        rj = (RangeJunction) oo.filterOperand;
        oo1 = rj.organizeOperands(context);
        assertTrue(oo1.filterOperand == cv[0]);
        // Case 9 : a >=7 and a > =8
        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(8)), OQLLexerTokenTypes.TOK_GE);
        oo = this.oganizedOperandsSingleRangeJunctionCreation(OQLLexerTokenTypes.LITERAL_and, cv, context);
        rj = (RangeJunction) oo.filterOperand;
        oo1 = rj.organizeOperands(context);
        assertTrue(oo1.filterOperand == cv[1]);
        // Case 10 : 7 < a and a >=7 and a != 13
        cv = new CompiledComparison[3];
        cv[0] = new CompiledComparison(new CompiledLiteral(new Integer(7)), new CompiledPath(new CompiledID("p"), "ID"), OQLLexerTokenTypes.TOK_LT);
        cv[1] = new CompiledComparison(new CompiledPath(new CompiledID("p"), "ID"), new CompiledLiteral(new Integer(7)), OQLLexerTokenTypes.TOK_GE);
        cv[2] = new CompiledComparison(new CompiledPath(new CompiledID("p"), "ID"), new CompiledLiteral(new Integer(13)), OQLLexerTokenTypes.TOK_NE);
        oo = this.oganizedOperandsSingleRangeJunctionCreation(OQLLexerTokenTypes.LITERAL_and, cv, context);
        rj = (RangeJunction) oo.filterOperand;
        oo1 = rj.organizeOperands(context);
        assertTrue(RangeJunction.getSingleCondnEvaluatorKey(oo1.filterOperand).equals(new Integer(7)));
        assertTrue(RangeJunction.getSingleCondnEvaluatorOperator(oo1.filterOperand) == OQLLexerTokenTypes.TOK_GT);
        // Case 11 : a > 7 and a >=7 and a != 13
        cv = new CompiledComparison[3];
        cv[0] = new CompiledComparison(new CompiledPath(new CompiledID("p"), "ID"), new CompiledLiteral(new Integer(7)), OQLLexerTokenTypes.TOK_GT);
        cv[1] = new CompiledComparison(new CompiledPath(new CompiledID("p"), "ID"), new CompiledLiteral(new Integer(7)), OQLLexerTokenTypes.TOK_GE);
        cv[2] = new CompiledComparison(new CompiledPath(new CompiledID("p"), "ID"), new CompiledLiteral(new Integer(13)), OQLLexerTokenTypes.TOK_NE);
        oo = this.oganizedOperandsSingleRangeJunctionCreation(OQLLexerTokenTypes.LITERAL_and, cv, context);
        rj = (RangeJunction) oo.filterOperand;
        oo1 = rj.organizeOperands(context);
        assertTrue(RangeJunction.getSingleCondnEvaluatorKey(oo1.filterOperand).equals(new Integer(7)));
        assertTrue(RangeJunction.getSingleCondnEvaluatorOperator(oo1.filterOperand) == OQLLexerTokenTypes.TOK_GT);
        // Case 12 : a >= 7 and a >7 and a != 13
        cv = new CompiledComparison[3];
        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(7)), OQLLexerTokenTypes.TOK_GT);
        cv[2] = new CompiledComparison(new CompiledPath(new CompiledID("p"), "ID"), new CompiledLiteral(new Integer(13)), OQLLexerTokenTypes.TOK_NE);
        oo = this.oganizedOperandsSingleRangeJunctionCreation(OQLLexerTokenTypes.LITERAL_and, cv, context);
        rj = (RangeJunction) oo.filterOperand;
        oo1 = rj.organizeOperands(context);
        assertTrue(RangeJunction.getSingleCondnEvaluatorKey(oo1.filterOperand).equals(new Integer(7)));
        assertTrue(RangeJunction.getSingleCondnEvaluatorOperator(oo1.filterOperand) == OQLLexerTokenTypes.TOK_GT);
        // Case 13 : a >= 8 and a >7 and a != 13
        cv = new CompiledComparison[3];
        cv[0] = new CompiledComparison(new CompiledPath(new CompiledID("p"), "ID"), new CompiledLiteral(new Integer(8)), OQLLexerTokenTypes.TOK_GE);
        cv[1] = new CompiledComparison(new CompiledPath(new CompiledID("p"), "ID"), new CompiledLiteral(new Integer(7)), OQLLexerTokenTypes.TOK_GT);
        cv[2] = new CompiledComparison(new CompiledPath(new CompiledID("p"), "ID"), new CompiledLiteral(new Integer(13)), OQLLexerTokenTypes.TOK_NE);
        oo = this.oganizedOperandsSingleRangeJunctionCreation(OQLLexerTokenTypes.LITERAL_and, cv, context);
        rj = (RangeJunction) oo.filterOperand;
        oo1 = rj.organizeOperands(context);
        assertTrue(RangeJunction.getSingleCondnEvaluatorKey(oo1.filterOperand).equals(new Integer(8)));
        assertTrue(RangeJunction.getSingleCondnEvaluatorOperator(oo1.filterOperand) == OQLLexerTokenTypes.TOK_GE);
        // Case 14 : a >=8 and a > =7 and a !=13
        cv = new CompiledComparison[3];
        cv[0] = new CompiledComparison(new CompiledPath(new CompiledID("p"), "ID"), new CompiledLiteral(new Integer(8)), OQLLexerTokenTypes.TOK_GE);
        cv[1] = new CompiledComparison(new CompiledPath(new CompiledID("p"), "ID"), new CompiledLiteral(new Integer(7)), OQLLexerTokenTypes.TOK_GE);
        cv[2] = new CompiledComparison(new CompiledPath(new CompiledID("p"), "ID"), new CompiledLiteral(new Integer(13)), OQLLexerTokenTypes.TOK_NE);
        oo = this.oganizedOperandsSingleRangeJunctionCreation(OQLLexerTokenTypes.LITERAL_and, cv, context);
        rj = (RangeJunction) oo.filterOperand;
        oo1 = rj.organizeOperands(context);
        assertTrue(RangeJunction.getSingleCondnEvaluatorKey(oo1.filterOperand).equals(new Integer(8)));
        assertTrue(RangeJunction.getSingleCondnEvaluatorOperator(oo1.filterOperand) == OQLLexerTokenTypes.TOK_GE);
        // Case 15 : a >=7 and a > =8 and a != 13
        cv = new CompiledComparison[3];
        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(8)), OQLLexerTokenTypes.TOK_GE);
        cv[2] = new CompiledComparison(new CompiledPath(new CompiledID("p"), "ID"), new CompiledLiteral(new Integer(13)), OQLLexerTokenTypes.TOK_NE);
        oo = this.oganizedOperandsSingleRangeJunctionCreation(OQLLexerTokenTypes.LITERAL_and, cv, context);
        rj = (RangeJunction) oo.filterOperand;
        oo1 = rj.organizeOperands(context);
        assertTrue(RangeJunction.getSingleCondnEvaluatorKey(oo1.filterOperand).equals(new Integer(8)));
        assertTrue(RangeJunction.getSingleCondnEvaluatorOperator(oo1.filterOperand) == OQLLexerTokenTypes.TOK_GE);
        // Case 15 : a >=7 and a > =8 and a != 8
        cv = new CompiledComparison[3];
        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(8)), OQLLexerTokenTypes.TOK_GE);
        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);
        rj = (RangeJunction) oo.filterOperand;
        oo1 = rj.organizeOperands(context);
        assertTrue(RangeJunction.getSingleCondnEvaluatorKey(oo1.filterOperand).equals(new Integer(8)));
        assertTrue(RangeJunction.getSingleCondnEvaluatorOperator(oo1.filterOperand) == OQLLexerTokenTypes.TOK_GE);
        assertTrue(RangeJunction.getKeysToBeRemoved((oo1.filterOperand)).iterator().next().equals(new Integer(8)));
        // Case 16 : a >=7 and a > =8 and a != 7
        cv = new CompiledComparison[3];
        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(8)), OQLLexerTokenTypes.TOK_GE);
        cv[2] = new CompiledComparison(new CompiledPath(new CompiledID("p"), "ID"), new CompiledLiteral(new Integer(7)), OQLLexerTokenTypes.TOK_NE);
        oo = this.oganizedOperandsSingleRangeJunctionCreation(OQLLexerTokenTypes.LITERAL_and, cv, context);
        rj = (RangeJunction) oo.filterOperand;
        oo1 = rj.organizeOperands(context);
        assertTrue(oo1.filterOperand == cv[1]);
        // Case 17 : a >=7 and a > =8 and a != 7 and a!=4 and a != 3
        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(8)), OQLLexerTokenTypes.TOK_GE);
        cv[2] = new CompiledComparison(new CompiledPath(new CompiledID("p"), "ID"), new CompiledLiteral(new Integer(7)), OQLLexerTokenTypes.TOK_NE);
        cv[3] = new CompiledComparison(new CompiledPath(new CompiledID("p"), "ID"), new CompiledLiteral(new Integer(4)), OQLLexerTokenTypes.TOK_NE);
        cv[4] = new CompiledComparison(new CompiledPath(new CompiledID("p"), "ID"), new CompiledLiteral(new Integer(3)), OQLLexerTokenTypes.TOK_NE);
        oo = this.oganizedOperandsSingleRangeJunctionCreation(OQLLexerTokenTypes.LITERAL_and, cv, context);
        rj = (RangeJunction) oo.filterOperand;
        oo1 = rj.organizeOperands(context);
        assertTrue(oo1.filterOperand == cv[1]);
        // Case 18 : a >=7 and a > =8 and a != 7 and a!=4 and a != 3 and a != 20
        // and a != 8
        cv = new CompiledComparison[7];
        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(8)), OQLLexerTokenTypes.TOK_GE);
        cv[2] = new CompiledComparison(new CompiledPath(new CompiledID("p"), "ID"), new CompiledLiteral(new Integer(7)), OQLLexerTokenTypes.TOK_NE);
        cv[3] = new CompiledComparison(new CompiledPath(new CompiledID("p"), "ID"), new CompiledLiteral(new Integer(4)), OQLLexerTokenTypes.TOK_NE);
        cv[4] = new CompiledComparison(new CompiledPath(new CompiledID("p"), "ID"), new CompiledLiteral(new Integer(3)), OQLLexerTokenTypes.TOK_NE);
        cv[5] = new CompiledComparison(new CompiledPath(new CompiledID("p"), "ID"), new CompiledLiteral(new Integer(20)), OQLLexerTokenTypes.TOK_NE);
        cv[6] = new CompiledComparison(new CompiledPath(new CompiledID("p"), "ID"), new CompiledLiteral(new Integer(8)), OQLLexerTokenTypes.TOK_NE);
        oo = this.oganizedOperandsSingleRangeJunctionCreation(OQLLexerTokenTypes.LITERAL_and, cv, context);
        rj = (RangeJunction) oo.filterOperand;
        oo1 = rj.organizeOperands(context);
        assertTrue(RangeJunction.getSingleCondnEvaluatorKey(oo1.filterOperand).equals(new Integer(8)));
        assertTrue(RangeJunction.getSingleCondnEvaluatorOperator(oo1.filterOperand) == OQLLexerTokenTypes.TOK_GE);
        Iterator itr = RangeJunction.getKeysToBeRemoved((oo1.filterOperand)).iterator();
        Object temp;
        assertTrue((temp = itr.next()).equals(new Integer(8)) || temp.equals(new Integer(20)));
        assertTrue((temp = itr.next()).equals(new Integer(8)) || temp.equals(new Integer(20)));
        assertFalse(itr.hasNext());
    // //////////////////////////////////////////////////////////////
    } catch (Exception e) {
        logger.error(e);
        fail(e.toString());
    }
}
Also used : LogWriter(org.apache.geode.LogWriter) Iterator(java.util.Iterator) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 25 with LogWriter

use of org.apache.geode.LogWriter in project geode by apache.

the class CompiledJunctionInternalsJUnitTest method testOrganizedOperandsSingleRangeJunctionCreationWithNoIterOperandForAND.

// Tests for plain creation of RangeJunction ( single or within a Group or CompositeGroup or
// AllGroup )
// which is agnostic of whether the RangeJunction is of type AND or OR
//////////////////////////////////////////////////////////////////////////////////////
/**
   * Tests the creation of a single RangeJunction if the CompiledJunction only contains same index
   * condition without iter operand for AND
   */
@Test
public void testOrganizedOperandsSingleRangeJunctionCreationWithNoIterOperandForAND() {
    LogWriter logger = CacheUtils.getLogger();
    try {
        ExecutionContext context = new QueryExecutionContext(null, CacheUtils.getCache());
        this.bindIteratorsAndCreateIndex(context);
        CompiledComparison[] cv = null;
        cv = new CompiledComparison[12];
        cv[0] = new CompiledComparison(new CompiledPath(new CompiledID("p"), "ID"), new CompiledLiteral(new Integer(2)), OQLLexerTokenTypes.TOK_EQ);
        cv[1] = new CompiledComparison(new CompiledPath(new CompiledID("p"), "ID"), new CompiledLiteral(new Integer(5)), OQLLexerTokenTypes.TOK_LE);
        cv[2] = new CompiledComparison(new CompiledPath(new CompiledID("p"), "ID"), new CompiledLiteral(new Integer(7)), OQLLexerTokenTypes.TOK_LT);
        cv[3] = new CompiledComparison(new CompiledPath(new CompiledID("p"), "ID"), new CompiledLiteral(new Integer(7)), OQLLexerTokenTypes.TOK_GT);
        cv[4] = new CompiledComparison(new CompiledPath(new CompiledID("p"), "ID"), new CompiledLiteral(new Integer(7)), OQLLexerTokenTypes.TOK_GE);
        cv[5] = new CompiledComparison(new CompiledPath(new CompiledID("p"), "ID"), new CompiledLiteral(new Integer(7)), OQLLexerTokenTypes.TOK_NE);
        cv[6] = new CompiledComparison(new CompiledPath(new CompiledID("p"), "ID"), new CompiledLiteral(new Integer(2)), OQLLexerTokenTypes.TOK_EQ);
        cv[7] = new CompiledComparison(new CompiledPath(new CompiledID("p"), "ID"), new CompiledLiteral(new Integer(5)), OQLLexerTokenTypes.TOK_LE);
        cv[8] = new CompiledComparison(new CompiledPath(new CompiledID("p"), "ID"), new CompiledLiteral(new Integer(7)), OQLLexerTokenTypes.TOK_LT);
        cv[9] = new CompiledComparison(new CompiledPath(new CompiledID("p"), "ID"), new CompiledLiteral(new Integer(7)), OQLLexerTokenTypes.TOK_GT);
        cv[10] = new CompiledComparison(new CompiledPath(new CompiledID("p"), "ID"), new CompiledLiteral(new Integer(7)), OQLLexerTokenTypes.TOK_GE);
        cv[11] = new CompiledComparison(new CompiledPath(new CompiledID("p"), "ID"), new CompiledLiteral(new Integer(7)), 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());
    } catch (Exception e) {
        logger.error(e);
        fail(e.toString());
    }
}
Also used : LogWriter(org.apache.geode.LogWriter) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Aggregations

LogWriter (org.apache.geode.LogWriter)87 Test (org.junit.Test)34 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)18 InternalDistributedSystem (org.apache.geode.distributed.internal.InternalDistributedSystem)17 Host (org.apache.geode.test.dunit.Host)17 Region (org.apache.geode.cache.Region)15 DistributedSystem (org.apache.geode.distributed.DistributedSystem)15 SerializableRunnable (org.apache.geode.test.dunit.SerializableRunnable)15 VM (org.apache.geode.test.dunit.VM)13 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)12 Iterator (java.util.Iterator)11 Set (java.util.Set)11 Cache (org.apache.geode.cache.Cache)11 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)11 CacheSerializableRunnable (org.apache.geode.cache30.CacheSerializableRunnable)10 LocalRegion (org.apache.geode.internal.cache.LocalRegion)9 Properties (java.util.Properties)8 InternalLogWriter (org.apache.geode.internal.logging.InternalLogWriter)8 IOException (java.io.IOException)7 HashSet (java.util.HashSet)7