use of com.hazelcast.query.SampleTestObjects.Employee in project hazelcast by hazelcast.
the class QueryBasicTest method testMultipleOrPredicates.
private void testMultipleOrPredicates(IMap<Integer, Employee> map) {
for (int i = 0; i < 10; i++) {
map.put(i, new Employee(i, "name" + i, "city" + i, i, true, i));
}
Collection<Employee> values;
values = map.values(Predicates.sql("name = 'name1' OR name = 'name2' OR name LIKE 'name3'"));
assertEquals(3, values.size());
values = map.values(Predicates.sql("name = 'name1' OR name LIKE 'name2%' OR name LIKE 'name3'"));
assertEquals(3, values.size());
values = map.values(Predicates.sql("name = 'name1' OR name LIKE 'name2%' OR name == 'name3'"));
assertEquals(3, values.size());
values = map.values(Predicates.sql("name LIKE '%name1' OR name LIKE 'name2%' OR name LIKE '%name3%'"));
assertEquals(3, values.size());
values = map.values(Predicates.sql("name == 'name1' OR name == 'name2' OR name = 'name3'"));
assertEquals(3, values.size());
values = map.values(Predicates.sql("name = 'name1' OR name = 'name2' OR city LIKE 'city3'"));
assertEquals(3, values.size());
values = map.values(Predicates.sql("name = 'name1' OR name LIKE 'name2%' OR city LIKE 'city3'"));
assertEquals(3, values.size());
values = map.values(Predicates.sql("name = 'name1' OR name LIKE 'name2%' OR city == 'city3'"));
assertEquals(3, values.size());
values = map.values(Predicates.sql("name LIKE '%name1' OR name LIKE 'name2%' OR city LIKE '%city3%'"));
assertEquals(3, values.size());
values = map.values(Predicates.sql("name == 'name1' OR name == 'name2' OR city = 'city3'"));
assertEquals(3, values.size());
}
use of com.hazelcast.query.SampleTestObjects.Employee in project hazelcast by hazelcast.
the class QueryBasicTest method negativeDouble.
@Test(timeout = 1000 * 90)
public void negativeDouble() {
HazelcastInstance instance = createHazelcastInstance(getConfig());
IMap<String, Employee> map = instance.getMap("default");
map.addIndex(IndexType.HASH, "salary");
map.put("" + 4, new Employee(1, "default", 1, true, -70D));
map.put("" + 3, new Employee(1, "default", 1, true, -60D));
map.put("" + 1, new Employee(1, "default", 1, true, -10D));
map.put("" + 2, new Employee(2, "default", 2, true, 10D));
Predicate predicate = Predicates.sql("salary >= -60");
Collection<Employee> values = map.values(predicate);
assertEquals(3, values.size());
predicate = Predicates.sql("salary between -20 and 20");
values = map.values(predicate);
assertEquals(2, values.size());
}
use of com.hazelcast.query.SampleTestObjects.Employee in project hazelcast by hazelcast.
the class QueryAdvancedTest method testTwoNodesWithIndexes.
@Test
public void testTwoNodesWithIndexes() {
Config config = getConfig();
TestHazelcastInstanceFactory nodeFactory = createHazelcastInstanceFactory(2);
HazelcastInstance instance1 = nodeFactory.newHazelcastInstance(config);
HazelcastInstance instance2 = nodeFactory.newHazelcastInstance(config);
IMap<String, Employee> map = instance1.getMap("employees");
map.addIndex(IndexType.HASH, "name");
map.addIndex(IndexType.HASH, "city");
map.addIndex(IndexType.SORTED, "age");
map.addIndex(IndexType.HASH, "active");
for (int i = 0; i < 5000; i++) {
Employee employee = new Employee(i, "name" + i % 100, "city" + (i % 100), i % 60, ((i & 1) == 1), i);
map.put(String.valueOf(i), employee);
}
assertClusterSize(2, instance1, instance2);
map = instance2.getMap("employees");
map.addIndex(IndexType.HASH, "name");
map.addIndex(IndexType.HASH, "city");
map.addIndex(IndexType.SORTED, "age");
map.addIndex(IndexType.HASH, "active");
Collection<Employee> entries = map.values(Predicates.sql("name='name3' and city='city3' and age > 2"));
assertEquals(50, entries.size());
for (Employee employee : entries) {
assertEquals("name3", employee.getName());
assertEquals("city3", employee.getCity());
}
entries = map.values(Predicates.sql("name LIKE '%name3' and city like '%city3' and age > 2"));
assertEquals(50, entries.size());
for (Employee employee : entries) {
assertEquals("name3", employee.getName());
assertEquals("city3", employee.getCity());
assertTrue(employee.getAge() > 2);
}
entries = map.values(Predicates.sql("name LIKE '%name3%' and city like '%city30%'"));
assertEquals(50, entries.size());
for (Employee employee : entries) {
assertTrue(employee.getName().startsWith("name3"));
assertTrue(employee.getCity().startsWith("city3"));
}
}
use of com.hazelcast.query.SampleTestObjects.Employee in project hazelcast by hazelcast.
the class QueryAdvancedTest method testTwoMembersWithIndexes.
@Test
public void testTwoMembersWithIndexes() {
Config config = getConfig();
TestHazelcastInstanceFactory nodeFactory = createHazelcastInstanceFactory(2);
HazelcastInstance instance = nodeFactory.newHazelcastInstance(config);
nodeFactory.newHazelcastInstance(config);
IMap<String, Employee> map = instance.getMap("employees");
map.addIndex(IndexType.HASH, "name");
map.addIndex(IndexType.SORTED, "age");
map.addIndex(IndexType.HASH, "active");
QueryBasicTest.doFunctionalQueryTest(map);
}
use of com.hazelcast.query.SampleTestObjects.Employee in project hazelcast by hazelcast.
the class QueryAdvancedTest method testOneMemberSQLWithIndex.
@Test
public void testOneMemberSQLWithIndex() {
HazelcastInstance instance = createHazelcastInstance(getConfig());
IMap<String, Employee> map = instance.getMap("employees");
map.addIndex(IndexType.HASH, "name");
map.addIndex(IndexType.SORTED, "age");
map.addIndex(IndexType.HASH, "active");
QueryBasicTest.doFunctionalSQLQueryTest(map);
}
Aggregations