Search in sources :

Example 1 with AndPredicate

use of com.hazelcast.query.impl.predicates.AndPredicate in project hazelcast by hazelcast.

the class IndexTest method testIndex.

@Test
public void testIndex() throws QueryException {
    Indexes is = new Indexes(ss, Extractors.empty());
    Index dIndex = is.addOrGetIndex("d", false);
    Index boolIndex = is.addOrGetIndex("bool", false);
    Index strIndex = is.addOrGetIndex("str", false);
    for (int i = 0; i < 1000; i++) {
        Data key = ss.toData(i);
        Data value = ss.toData(new MainPortable(i % 2 == 0, -10.34d, "joe" + i));
        is.saveEntryIndex(new QueryEntry(ss, key, value, Extractors.empty()), null);
    }
    assertEquals(1000, dIndex.getRecords(-10.34d).size());
    assertEquals(1, strIndex.getRecords("joe23").size());
    assertEquals(500, boolIndex.getRecords(true).size());
    clearIndexes(dIndex, boolIndex, strIndex);
    for (int i = 0; i < 1000; i++) {
        Data key = ss.toData(i);
        Data value = ss.toData(new MainPortable(false, 11.34d, "joe"));
        is.saveEntryIndex(new QueryEntry(ss, key, value, Extractors.empty()), null);
    }
    assertEquals(0, dIndex.getRecords(-10.34d).size());
    assertEquals(0, strIndex.getRecords("joe23").size());
    assertEquals(1000, strIndex.getRecords("joe").size());
    assertEquals(1000, boolIndex.getRecords(false).size());
    assertEquals(0, boolIndex.getRecords(true).size());
    clearIndexes(dIndex, boolIndex, strIndex);
    for (int i = 0; i < 1000; i++) {
        Data key = ss.toData(i);
        Data value = ss.toData(new MainPortable(false, -1 * (i + 1), "joe" + i));
        is.saveEntryIndex(new QueryEntry(ss, key, value, Extractors.empty()), null);
    }
    assertEquals(0, dIndex.getSubRecordsBetween(1d, 1001d).size());
    assertEquals(1000, dIndex.getSubRecordsBetween(-1d, -1001d).size());
    clearIndexes(dIndex, boolIndex, strIndex);
    for (int i = 0; i < 1000; i++) {
        Data key = ss.toData(i);
        Data value = ss.toData(new MainPortable(false, 1 * (i + 1), "joe" + i));
        is.saveEntryIndex(new QueryEntry(ss, key, value, Extractors.empty()), null);
    }
    assertEquals(1000, dIndex.getSubRecordsBetween(1d, 1001d).size());
    assertEquals(0, dIndex.getSubRecordsBetween(-1d, -1001d).size());
    assertEquals(400, dIndex.getSubRecords(ComparisonType.GREATER, 600d).size());
    assertEquals(401, dIndex.getSubRecords(ComparisonType.GREATER_EQUAL, 600d).size());
    assertEquals(9, dIndex.getSubRecords(ComparisonType.LESSER, 10d).size());
    assertEquals(10, dIndex.getSubRecords(ComparisonType.LESSER_EQUAL, 10d).size());
    assertEquals(1, is.query(new AndPredicate(new EqualPredicate("d", 1d), new EqualPredicate("bool", "false"))).size());
    assertEquals(1, is.query(new AndPredicate(new EqualPredicate("d", 1), new EqualPredicate("bool", Boolean.FALSE))).size());
    assertEquals(1, is.query(new AndPredicate(new EqualPredicate("d", "1"), new EqualPredicate("bool", false))).size());
}
Also used : AndPredicate(com.hazelcast.query.impl.predicates.AndPredicate) EqualPredicate(com.hazelcast.query.impl.predicates.EqualPredicate) TestUtil.toData(com.hazelcast.instance.TestUtil.toData) Data(com.hazelcast.nio.serialization.Data) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 2 with AndPredicate

use of com.hazelcast.query.impl.predicates.AndPredicate in project hazelcast by hazelcast.

the class SqlPredicateTest method testAndWithRegex_stackOverflowIssue.

@Test
public // http://stackoverflow.com/questions/37382505/hazelcast-imap-valuespredicate-miss-data
void testAndWithRegex_stackOverflowIssue() {
    SqlPredicate sqlPredicate = new SqlPredicate("nextExecuteTime < 1463975296703 AND autoIncrementId REGEX '.*[5,6,7,8,9]$'");
    Predicate predicate = sqlPredicate.predicate;
    AndPredicate andPredicate = (AndPredicate) predicate;
    assertEquals(GreaterLessPredicate.class, andPredicate.getPredicates()[0].getClass());
    assertEquals(RegexPredicate.class, andPredicate.getPredicates()[1].getClass());
}
Also used : AndPredicate(com.hazelcast.query.impl.predicates.AndPredicate) RegexPredicate(com.hazelcast.query.impl.predicates.RegexPredicate) OrPredicate(com.hazelcast.query.impl.predicates.OrPredicate) GreaterLessPredicate(com.hazelcast.query.impl.predicates.GreaterLessPredicate) AndPredicate(com.hazelcast.query.impl.predicates.AndPredicate) QuickTest(com.hazelcast.test.annotation.QuickTest) DateHelperTest(com.hazelcast.query.impl.DateHelperTest) Test(org.junit.Test)

Example 3 with AndPredicate

use of com.hazelcast.query.impl.predicates.AndPredicate in project hazelcast by hazelcast.

the class SqlPredicateTest method testAnd_whenLeftPredicateAnd.

@Test
public void testAnd_whenLeftPredicateAnd() {
    AndPredicate predicate1 = new AndPredicate(new SqlPredicate("a == 1"), new SqlPredicate("a == 2"));
    TruePredicate predicate2 = new TruePredicate();
    AndPredicate concatenatedOr = SqlPredicate.flattenCompound(predicate1, predicate2, AndPredicate.class);
    assertEquals(3, concatenatedOr.getPredicates().length);
    assertInstanceOf(SqlPredicate.class, concatenatedOr.getPredicates()[0]);
    assertInstanceOf(SqlPredicate.class, concatenatedOr.getPredicates()[1]);
    assertSame(predicate2, concatenatedOr.getPredicates()[2]);
}
Also used : AndPredicate(com.hazelcast.query.impl.predicates.AndPredicate) QuickTest(com.hazelcast.test.annotation.QuickTest) DateHelperTest(com.hazelcast.query.impl.DateHelperTest) Test(org.junit.Test)

Example 4 with AndPredicate

use of com.hazelcast.query.impl.predicates.AndPredicate in project hazelcast by hazelcast.

the class SqlPredicateTest method testFlattenOr_withAndOrPredicates.

// (OR (AND A B) (OR C D)) is flattened to (OR (AND A B) C D)
@Test
public void testFlattenOr_withAndOrPredicates() {
    OrPredicate orPredicate = new OrPredicate(leftOfOr, rightOfOr);
    AndPredicate andPredicate = new AndPredicate(leftOfAnd, rightOfAnd);
    OrPredicate flattenedCompoundOr = SqlPredicate.flattenCompound(andPredicate, orPredicate, OrPredicate.class);
    assertSame(andPredicate, flattenedCompoundOr.getPredicates()[0]);
    assertSame(leftOfOr, flattenedCompoundOr.getPredicates()[1]);
    assertSame(rightOfOr, flattenedCompoundOr.getPredicates()[2]);
}
Also used : OrPredicate(com.hazelcast.query.impl.predicates.OrPredicate) AndPredicate(com.hazelcast.query.impl.predicates.AndPredicate) QuickTest(com.hazelcast.test.annotation.QuickTest) DateHelperTest(com.hazelcast.query.impl.DateHelperTest) Test(org.junit.Test)

Example 5 with AndPredicate

use of com.hazelcast.query.impl.predicates.AndPredicate in project hazelcast by hazelcast.

the class SqlPredicateTest method testAnd_whenRightPredicateAnd.

@Test
public void testAnd_whenRightPredicateAnd() {
    TruePredicate predicate1 = new TruePredicate();
    AndPredicate predicate2 = new AndPredicate(new SqlPredicate("a == 1"), new SqlPredicate("a == 2"));
    AndPredicate concatenatedOr = SqlPredicate.flattenCompound(predicate1, predicate2, AndPredicate.class);
    assertEquals(3, concatenatedOr.getPredicates().length);
    assertSame(predicate1, concatenatedOr.getPredicates()[0]);
    assertInstanceOf(SqlPredicate.class, concatenatedOr.getPredicates()[1]);
    assertInstanceOf(SqlPredicate.class, concatenatedOr.getPredicates()[2]);
}
Also used : AndPredicate(com.hazelcast.query.impl.predicates.AndPredicate) QuickTest(com.hazelcast.test.annotation.QuickTest) DateHelperTest(com.hazelcast.query.impl.DateHelperTest) Test(org.junit.Test)

Aggregations

AndPredicate (com.hazelcast.query.impl.predicates.AndPredicate)12 QuickTest (com.hazelcast.test.annotation.QuickTest)12 Test (org.junit.Test)12 DateHelperTest (com.hazelcast.query.impl.DateHelperTest)11 OrPredicate (com.hazelcast.query.impl.predicates.OrPredicate)7 TestUtil.toData (com.hazelcast.instance.TestUtil.toData)1 Data (com.hazelcast.nio.serialization.Data)1 EqualPredicate (com.hazelcast.query.impl.predicates.EqualPredicate)1 GreaterLessPredicate (com.hazelcast.query.impl.predicates.GreaterLessPredicate)1 RegexPredicate (com.hazelcast.query.impl.predicates.RegexPredicate)1