use of com.hazelcast.query.Predicate in project hazelcast by hazelcast.
the class BetweenVisitorTest method whenPredicateIsExclusive_thenIsNotUsedToBuildBetween.
@Test
public void whenPredicateIsExclusive_thenIsNotUsedToBuildBetween() {
//(age >= 5 and age < 6) --> (age >= 5 and age < 6)
Predicate left = greaterThan("attribute", 5);
Predicate right = lessEqual("attribute", 6);
Predicate and = and(left, right);
Predicate result = visitor.visit((AndPredicate) and, mockIndexes);
assertSame(and, result);
}
use of com.hazelcast.query.Predicate in project hazelcast by hazelcast.
the class BetweenVisitorTest method whenPredicatesOtherThenGreatLess_thenDoNotAttemptToEliminateThem.
@Test
public void whenPredicatesOtherThenGreatLess_thenDoNotAttemptToEliminateThem() {
//(age >= 5 and age <= 6 and age <> 4) --> ( (age between 5 6) and (age <> 5) )
Predicate left = greaterEqual("attribute", 5);
Predicate right = lessEqual("attribute", 6);
Predicate other = notEqual("attribute", 4);
Predicate and = and(left, right, other);
AndPredicate result = (AndPredicate) visitor.visit((AndPredicate) and, mockIndexes);
Predicate[] inners = result.predicates;
assertThat(inners, hasItemInArray(other));
BetweenPredicate betweenPredicate = findFirstBetweenPredicate(inners);
assertBetweenPredicate(betweenPredicate, 5, 6);
}
use of com.hazelcast.query.Predicate in project microservices by pwillhan.
the class AverageCityPopulationCallable method call.
@Override
public Integer call() throws Exception {
System.err.println("Running task on: " + hz.getCluster().getLocalMember().toString());
IMap<CityKey, City> cities = hz.getMap("cities");
Predicate countryCityPredicate = Predicates.equal("country", country);
Collection<City> countryCities = cities.values(countryCityPredicate);
int totalPopulation = 0;
for (City countryCity : countryCities) {
totalPopulation += countryCity.getPopulation();
}
return totalPopulation / countryCities.size();
}
use of com.hazelcast.query.Predicate in project microservices by pwillhan.
the class AggregationCountryCityPopulation method main.
public static void main(String[] args) throws Exception {
Config conf = new Config();
HazelcastInstance hz = Hazelcast.newHazelcastInstance(conf);
IMap<CityKey, City> cities = hz.getMap("cities");
if (cities.isEmpty()) {
cities.put(new CityKey("London", "GB"), new City("London", "GB", 8416535, 1572));
cities.put(new CityKey("Southampton", "GB"), new City("Southampton", "GB", 242100, 51));
cities.put(new CityKey("Chicago", "US"), new City("Chicago", "US", 2718782, 606));
cities.put(new CityKey("Washington DC", "US"), new City("Washington DC", "US", 658893, 177));
cities.put(new CityKey("Seattle", "US"), new City("Seattle", "US", 652405, 370));
}
Supplier<CityKey, City, Integer> gbCityPopulation6 = Supplier.fromPredicate(new Predicate<CityKey, City>() {
@Override
public boolean apply(Map.Entry<CityKey, City> entry) {
return "GB".equals(entry.getValue().getCountry());
}
}, Supplier.<CityKey, City, Integer>all(new PropertyExtractor<City, Integer>() {
@Override
public Integer extract(City city) {
return city.getPopulation();
}
}));
int result6 = cities.aggregate(gbCityPopulation6, Aggregations.<CityKey, City>integerSum());
System.err.println(result6);
Supplier<CityKey, City, Integer> gbCityPopulation8 = Supplier.fromPredicate(entry -> "GB".equals(entry.getValue().getCountry()), Supplier.all(city -> city.getPopulation()));
int result8 = cities.aggregate(gbCityPopulation8, Aggregations.integerSum());
System.err.println(result8);
}
use of com.hazelcast.query.Predicate in project microservices by pwillhan.
the class MapSearchPredicateExample method main.
public static void main(String[] args) {
HazelcastInstance hz = Hazelcast.newHazelcastInstance();
IMap<String, City> capitals = hz.getMap("capitals");
capitals.addIndex("name", false);
capitals.addIndex("population", true);
capitals.put("GB", new City("London", "GB", 8174100));
capitals.put("FR", new City("Paris", "FR", 2268265));
capitals.put("US", new City("Washington DC", "US", 601723));
capitals.put("AU", new City("Canberra", "AU", 354644));
EntryObject c = new PredicateBuilder().getEntryObject();
Predicate londonPredicate = c.get("name").equal("London");
Collection<City> possibleLondons = capitals.values(londonPredicate);
System.err.println(possibleLondons);
Predicate largeCityPredicate = Predicates.greaterThan("population", 1000000);
Collection<City> largeCities = capitals.values(largeCityPredicate);
System.err.println(largeCities);
}
Aggregations