Reputation: 2604
I have a collection, a List of Map, the map is Map<String, String>
. I need to query this collection with comparison, logical, like, not in operators. Something like SQL.
I will be populating the list from a database stored procedure, so I am not sure about the size. But, I guess the size should not be more than 10,000 records.
While posting this I am having a look at Apache functors, I don't know if they will help here.
Other way that I am thinking of is using the in-memory database Derby to achieve this.
Please let me know of any Java library or any other way of doing this.
The maps in the list will be like below:
Map<String, String> m1 = new Map<String, String>();
m1.put("name","Mark");
m1.put("age","21");
m1.put("city","some city");
Map<String, String> m1 = new Map<String, String>();
m1.put("name","David");
m1.put("age","25");
m1.put("city","other city");
I need to query the list to get Map which has:
name=Mark
name=Mark and age > 30
city not in "other city"
Upvotes: 1
Views: 3849
Reputation: 3028
Take a look at CQEngine - Collection Query Engine.
I'm biased as the author, but this will outperform and scale better than approaches which rely on iterating and filtering.
It provides an implementation of java.util.Set
(IndexedCollection) which allows objects to be retrieved based on (arbitrarily complex) queries on their attributes.
Upvotes: 3
Reputation: 2604
I found JFilter which helps you with filtering in-memory data (java objects ). Below is the description from JFilter website.
JFilter is a simple and high performance open source library to filter (query), map (select) and reduce (aggregate) objects in a Java collection. Query is given in json format like Mongodb queries.
I have written a post on using JFilter with Maps, which I am using as a generic way of storing data and querying/filtering using JFilter
Here is the link to the post Using JFilter to query/filter in-memory data
Upvotes: 0
Reputation: 24801
You can use Google Collections/Gauva. It provides collection filtering with predicates as :
Iterables.filter(Iterable, Predicate)
See this answer for an example of filtering using predicates.
Upvotes: 2
Reputation: 11256
Quaere can query collections. You should have a look before going for an in-memory db based solution.
Upvotes: 0