You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ignite.apache.org by daniels <ra...@gmail.com> on 2017/11/14 16:53:50 UTC

QueryEntity Based Configuration

Hi everyone. I want to use "QueryEntity Based Configuration."

my  model (i.e. valueType) is wrapedMap -

*class Model {

 Map<String,Object> data;

Object  get(String key){}


}*
I want that my "indexes" to be my "data" 's some keys. Can I use it for my
case? And how?


Will following config properly in my case`

<bean class="org.apache.ignite.configuration.CacheConfiguration">
    <property name="name" value="mycache"/>
    
    <property name="queryEntities">
        <list>
            <bean class="org.apache.ignite.cache.QueryEntity">
                
                <property name="keyType" value="java.lang.String"/>
              
                
                <property name="valueType"
                          value="org.examples.Model"/>

                
                <property name="fields">
                    <map>
                     * ????????????????? What shall I put here? my "data"?*
                    </map>
                </property>

                
                <property name="indexes">
                    <list>
                        
                        <bean class="org.apache.ignite.cache.QueryIndex">
                            <constructor-arg value="id"/> *????? Can I put
here my "data" some key?*
                        </bean>
                      
                        
                        <bean class="org.apache.ignite.cache.QueryIndex">
                            <constructor-arg>
                                <list>
                                    <value>id</value> . ????? Can I put here
my "data" some key?*
                                    <value>salary</value>????? Can I put
here my "data" some key?*
                                </list>
                            </constructor-arg>
                            <constructor-arg value="SORTED"/>
                        </bean>
                    </list>
                </property>
            </bean>
        </list>
    </property>
</bean>







--
Sent from: http://apache-ignite-users.70518.x6.nabble.com/

Re: QueryEntity Based Configuration

Posted by daniels <ra...@gmail.com>.
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" ? 



--
Sent from: http://apache-ignite-users.70518.x6.nabble.com/

Re: QueryEntity Based Configuration

Posted by daniels <ra...@gmail.com>.
Thank you ,it works.



--
Sent from: http://apache-ignite-users.70518.x6.nabble.com/

Re: QueryEntity Based Configuration

Posted by afedotov <al...@gmail.com>.
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/

Re: QueryEntity Based Configuration

Posted by daniels <ra...@gmail.com>.
Thank you,it's so clear.



--
Sent from: http://apache-ignite-users.70518.x6.nabble.com/

Re: QueryEntity Based Configuration

Posted by afedotov <al...@gmail.com>.
You could introduce an additional Model data cache that will store *data* for
each Model as it is usually done in a regular ORM systems
(http://docs.jboss.org/hibernate/orm/5.2/userguide/html_single/Hibernate_User_Guide.html#collections-map)

The key for the Model data cache should include the key of a corresponding
model and a key of the original *data* field. The Model key of the
ModelDataKey should be collocated with the corresponding Model key.
Please check  affinity collocation documentation section
<https://apacheignite.readme.io/docs/affinity-collocation>  
Having collocated the Model and its ModelData, you could use distributed
collocated queries to fetch related data with index support.
More info on distributed queries and indexing setup could be found here. 
https://apacheignite.readme.io/docs/cache-queries#sql-queries




--
Sent from: http://apache-ignite-users.70518.x6.nabble.com/

Re: QueryEntity Based Configuration

Posted by daniels <ra...@gmail.com>.
Thank you for response.
I cant do the first offer(flatten map).
And that about the second one  I didnt understand ,can you please explain it
in details?


p.s. My cache value is List of Models. And I want get Models with sorting
(by some fields ) quikly. And therefore I decided to use indexes and cache
queries.If ignite not supported my case ,how xan I solve my problem with
another way?



--
Sent from: http://apache-ignite-users.70518.x6.nabble.com/

Re: QueryEntity Based Configuration

Posted by afedotov <al...@gmail.com>.
Hi,

Indexes for nested collections and in particular for maps are not supported.

If you need indexes for data please consider analyzing and refactoring the
problem domain.
You could either flatten map so that its keys become fields of the Model or
move data into separate 
cache/caches related to Model.



--
Sent from: http://apache-ignite-users.70518.x6.nabble.com/