use of com.hazelcast.query.Predicate in project hazelcast by hazelcast.
the class QueryBasicTest method issue393SqlEq.
@Test(timeout = 1000 * 60)
public void issue393SqlEq() {
HazelcastInstance instance = createHazelcastInstance(getConfig());
IMap<String, Value> map = instance.getMap("default");
map.addIndex("name", true);
for (int i = 0; i < 4; i++) {
Value v = new Value("name" + i);
map.put("" + i, v);
}
Predicate predicate = new SqlPredicate("name='name0'");
Collection<Value> values = map.values(predicate);
String[] expectedValues = new String[] { "name0" };
assertEquals(expectedValues.length, values.size());
List<String> names = new ArrayList<String>();
for (Value configObject : values) {
names.add(configObject.getName());
}
String[] array = names.toArray(new String[names.size()]);
Arrays.sort(array);
assertArrayEquals(names.toString(), expectedValues, array);
}
use of com.hazelcast.query.Predicate in project hazelcast by hazelcast.
the class QueryBasicTest method issue393SqlInInteger.
@Test(timeout = 1000 * 60)
public void issue393SqlInInteger() {
HazelcastInstance instance = createHazelcastInstance(getConfig());
IMap<String, Value> map = instance.getMap("default");
map.addIndex("index", false);
for (int i = 0; i < 4; i++) {
Value v = new Value("name" + i, new ValueType("type" + i), i);
map.put("" + i, v);
}
Predicate predicate = new SqlPredicate("index IN (0, 2)");
Collection<Value> values = map.values(predicate);
String[] expectedValues = new String[] { "name0", "name2" };
assertEquals(expectedValues.length, values.size());
List<String> names = new ArrayList<String>();
for (Value configObject : values) {
names.add(configObject.getName());
}
String[] array = names.toArray(new String[names.size()]);
Arrays.sort(array);
assertArrayEquals(names.toString(), expectedValues, array);
}
use of com.hazelcast.query.Predicate in project hazelcast by hazelcast.
the class QueryBasicTest method issue393SqlIn.
@Test(timeout = 1000 * 60)
public void issue393SqlIn() {
HazelcastInstance instance = createHazelcastInstance(getConfig());
IMap<String, Value> map = instance.getMap("default");
map.addIndex("name", true);
for (int i = 0; i < 4; i++) {
Value v = new Value("name" + i);
map.put("" + i, v);
}
Predicate predicate = new SqlPredicate("name IN ('name0', 'name2')");
Collection<Value> values = map.values(predicate);
String[] expectedValues = new String[] { "name0", "name2" };
assertEquals(expectedValues.length, values.size());
List<String> names = new ArrayList<String>();
for (Value configObject : values) {
names.add(configObject.getName());
}
String[] array = names.toArray(new String[names.size()]);
Arrays.sort(array);
assertArrayEquals(names.toString(), expectedValues, array);
}
use of com.hazelcast.query.Predicate in project hazelcast by hazelcast.
the class NotPredicateTest method negate_thenReturnInnerPredicate.
@Test
public void negate_thenReturnInnerPredicate() {
Predicate inner = mock(Predicate.class);
NotPredicate notPredicate = new NotPredicate(inner);
Predicate negate = notPredicate.negate();
assertThat(negate, sameInstance(inner));
}
use of com.hazelcast.query.Predicate in project hazelcast by hazelcast.
the class OrPredicateTest method negate_whenContainsNonNegatablePredicate_thenReturnAndPredicateWithNotInside.
@Test
public void negate_whenContainsNonNegatablePredicate_thenReturnAndPredicateWithNotInside() {
// ~(foo or bar) --> (~foo and ~bar)
// this is testing the case where the inner predicate does NOT implement {@link Negatable}
Predicate nonNegatable = mock(Predicate.class);
OrPredicate or = (OrPredicate) or(nonNegatable);
AndPredicate result = (AndPredicate) or.negate();
Predicate[] inners = result.predicates;
assertThat(inners, arrayWithSize(1));
NotPredicate notPredicate = (NotPredicate) inners[0];
assertThat(nonNegatable, sameInstance(notPredicate.predicate));
}
Aggregations