Hi,
Crossposting from the mail list, since looks like something is broken and
some messages don't get it here.
On Mon, Nov 27, 2017 at 1:48 AM, daniels wrote:
Hi dear afedotov.I have a question,related to your claim
"Indexes for nested collections and in particular for maps are not
supported.".
Is it true for complex(custom) objects
Namely ,can I make my custom type indexable ?
class Model {
//index=true
private CustomObject obj;
}
class CustomObject{
//index=true
private String objName;
}
can I do filter on cache(of Models) with "objName" ?
---
Hi,
Yes. It's possible. Please find a short example below:
Ignite ignite = Ignition.start("ignite.xml");
QueryEntity qe = new QueryEntity("java.lang.Long", Model.class.getName());
// The key point is to flatten the nested fields with aliases.
qe.addQueryField("obj", CustomObject.class.getName(), null)
.addQueryField("obj.objName", String.class.getName(), "obj_objName");
final String cacheName = "cache";
CacheConfiguration<Long, Model> ccfg = new CacheConfiguration<Long,
Model>(cacheName)
.setQueryEntities(Collections.singletonList(qe));
IgniteCache<Long, Model> cache = ignite.getOrCreateCache(ccfg);
for (long i = 0; i < 10; ++i) {
cache.put(i, new Model(new CustomObject(i % 2 == 0 ? "updateme" :
"CustomObject" + i)));
}
SqlFieldsQuery updateQry = new SqlFieldsQuery("update Model set obj_objName
= 'updated' where obj_objName = 'updateMe'");
cache.query(updateQry).getAll();
SqlFieldsQuery selectQry =
new SqlFieldsQuery("select obj, obj_objName from Model where obj_objName
like 'CustomObject%'");
cache.query(selectQry).getAll().forEach(objects -> {
System.out.println("Result:" + objects);
});
SqlFieldsQuery deleteQry = new SqlFieldsQuery(
"delete Model where obj_objName like 'CustomObject%'"
);
cache.query(deleteQry).getAll();
System.out.println("After DELETE");
cache.query(selectQry).getAll().forEach(objects -> {
System.out.println("Result:" + objects);
});
Kind regards,
Alex.
--
Sent from: http://apache-ignite-users.70518.x6.nabble.com/