use of com.hazelcast.query.SqlPredicate in project hazelcast by hazelcast.
the class QueryBasicTest method testQueryPortableField.
@Test(expected = QueryException.class)
public void testQueryPortableField() {
Config config = getConfig();
HazelcastInstance instance = createHazelcastInstance(config);
IMap<Object, Object> map = instance.getMap(randomMapName());
map.put(1, new GrandParentPortableObject(1, new ParentPortableObject(1L, new ChildPortableObject(1L))));
Collection<Object> values = map.values(new SqlPredicate("child > 0"));
values.size();
}
use of com.hazelcast.query.SqlPredicate in project hazelcast by hazelcast.
the class QueryBasicTest method testWithDashInTheNameAndSqlPredicate.
@Test(timeout = 1000 * 60)
public void testWithDashInTheNameAndSqlPredicate() {
HazelcastInstance instance = createHazelcastInstance(getConfig());
IMap<String, Employee> map = instance.getMap("employee");
Employee toto = new Employee("toto", 23, true, 165765.0);
map.put("1", toto);
Employee toto2 = new Employee("toto-super+hero", 23, true, 165765.0);
map.put("2", toto2);
// works well
Set<Map.Entry<String, Employee>> entries = map.entrySet(new SqlPredicate("name='toto-super+hero'"));
assertTrue(entries.size() > 0);
for (Map.Entry<String, Employee> entry : entries) {
Employee e = entry.getValue();
assertEquals(e, toto2);
}
}
use of com.hazelcast.query.SqlPredicate in project hazelcast by hazelcast.
the class QueryBasicTest method testQueryUsingPortableObject.
private void testQueryUsingPortableObject(Config config, String mapName) {
addPortableFactories(config);
TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
HazelcastInstance instance1 = factory.newHazelcastInstance(config);
HazelcastInstance instance2 = factory.newHazelcastInstance(config);
IMap<Object, Object> map = instance2.getMap(mapName);
Object key = generateKeyOwnedBy(instance1);
map.put(key, new ParentPortableObject(1L));
waitAllForSafeState(instance1, instance2);
Collection<Object> values = map.values(new SqlPredicate("timestamp > 0"));
assertEquals(1, values.size());
}
use of com.hazelcast.query.SqlPredicate in project hazelcast by hazelcast.
the class QueryBasicTest method testIndexingEnumAttributeWithSqlIssue597.
/**
* see pull request 616
*/
@Test(timeout = 1000 * 60)
public void testIndexingEnumAttributeWithSqlIssue597() {
HazelcastInstance instance = createHazelcastInstance(getConfig());
IMap<Integer, Value> map = instance.getMap("default");
map.addIndex("state", true);
for (int i = 0; i < 4; i++) {
Value v = new Value(i % 2 == 0 ? State.STATE1 : State.STATE2, new ValueType(), i);
map.put(i, v);
}
Collection<Value> values = map.values(new SqlPredicate("state = 'STATE1'"));
int[] expectedValues = new int[] { 0, 2 };
assertEquals(expectedValues.length, values.size());
int[] indexes = new int[2];
int index = 0;
for (Value configObject : values) {
indexes[index++] = configObject.getIndex();
}
Arrays.sort(indexes);
assertArrayEquals(indexes, expectedValues);
}
use of com.hazelcast.query.SqlPredicate 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);
}
Aggregations