Cache Query Filter Logic

classic Classic list List threaded Threaded
6 messages Options
raja24 raja24
Reply | Threaded
Open this post in threaded view
|

Cache Query Filter Logic

Hi,

I'm new to Apache Ignite and doing a POC with Cache Query filter and didn't
work.
My code is as below and sure I'm missing the logic. Please help.

Config:
<bean class="org.apache.ignite.configuration.CacheConfiguration">
                                        <property name="name" value="service-cache"/>
                                        <property name="backups" value="1"/>
                                        <property name="cacheMode" value="PARTITIONED"/>
                                        <property name="atomicityMode" value="ATOMIC"/>
                                        <property name="expiryPolicyFactory">
                                                <bean parent="expiryPolicy"/>
                                        </property>
                                        <property name="indexedTypes">
                        <list>
                            <value>java.lang.Integer</value>
                            <value>org.apache.Fund</value>
                        </list>
                    </property>
                                </bean>

Java Code:
// get or create cache
                IgniteCache <Integer, Fund> cache =
ignite.getOrCreateCache("service-cache"); // put some cache elements
                               
            final int keyCnt = 10;

            // Create batch.
            Map<Integer, Fund> batch = new HashMap<>();
            for (int i = 0; i < keyCnt; i++){
            Fund fund = new Fund();
            fund.setName("test"+i);
                batch.put(i, fund);
            }

            // Bulk-store entries in cache.
            cache.putAll(batch);
            // Query for all people with "Master Degree" in their resumes.
                 TextQuery txt = new TextQuery(Fund.class, "name:test1");
                 
                 try (QueryCursor<Entry&lt;Integer, Fund>> masters = cache.query(txt)) {
                   for (Entry<Integer, Fund> e : masters)
                     System.out.println(e.getValue().getName());
                 }


Fund Class:
public class Fund implements Serializable{
        private static final long serialVersionUID = 1L;
                private String name;
       
       
       
        public void setName(String name) {
                this.name = name;
        }
        public String getName() {
                return name;
        }
}


Thanks,
Raja.




--
Sent from: http://apache-ignite-users.70518.x6.nabble.com/
ibelyakov ibelyakov
Reply | Threaded
Open this post in threaded view
|

Re: Cache Query Filter Logic

Hi Raja,

To use TextQuery you should apply @QueryTextField annotation for "name" field in your "Fund" model.

Regards,
Igor

On Tue, Jul 23, 2019 at 9:39 PM raja24 <[hidden email]> wrote:
Hi,

I'm new to Apache Ignite and doing a POC with Cache Query filter and didn't
work.
My code is as below and sure I'm missing the logic. Please help.

Config:
<bean class="org.apache.ignite.configuration.CacheConfiguration">
                                        <property name="name" value="service-cache"/>
                                        <property name="backups" value="1"/>
                                        <property name="cacheMode" value="PARTITIONED"/>
                                        <property name="atomicityMode" value="ATOMIC"/>
                                        <property name="expiryPolicyFactory">
                                                <bean parent="expiryPolicy"/>
                                        </property>
                                        <property name="indexedTypes">
                        <list>
                            <value>java.lang.Integer</value>
                            <value>org.apache.Fund</value>
                        </list>
                    </property>
                                </bean>

Java Code:
// get or create cache
                IgniteCache <Integer, Fund> cache =
ignite.getOrCreateCache("service-cache"); // put some cache elements

            final int keyCnt = 10;

            // Create batch.
            Map<Integer, Fund> batch = new HashMap<>();
            for (int i = 0; i < keyCnt; i++){
                Fund fund = new Fund();
                fund.setName("test"+i);
                batch.put(i, fund);
            }

            // Bulk-store entries in cache.
            cache.putAll(batch);
            // Query for all people with "Master Degree" in their resumes.
                 TextQuery txt = new TextQuery(Fund.class, "name:test1");

                 try (QueryCursor<Entry&lt;Integer, Fund>> masters = cache.query(txt)) {
                   for (Entry<Integer, Fund> e : masters)
                     System.out.println(e.getValue().getName());
                 }


Fund Class:
public class Fund implements Serializable{
        private static final long serialVersionUID = 1L;
                private String name;



        public void setName(String name) {
                this.name = name;
        }
        public String getName() {
                return name;
        }
}


Thanks,
Raja.




--
Sent from: http://apache-ignite-users.70518.x6.nabble.com/
raja24 raja24
Reply | Threaded
Open this post in threaded view
|

Re: Cache Query Filter Logic

Igor,

I have tries as per your suggestion still didn't work.

import org.apache.ignite.cache.query.annotations.QueryTextField;

public class Fund implements Serializable{
        private static final long serialVersionUID = 1L;
       
        private int reportingSeq;
       
        @QueryTextField
        private String name;
       
       
        public void setName(String name) {
                this.name = name;
        }
        public String getName() {
                return name;
        }
       
        public int getReportingSeq() {
                return reportingSeq;
        }
        public void setReportingSeq(int reportingSeq) {
                this.reportingSeq = reportingSeq;
        }

Thanks,
Raja.



--
Sent from: http://apache-ignite-users.70518.x6.nabble.com/
raja24 raja24
Reply | Threaded
Open this post in threaded view
|

Re: Cache Query Filter Logic

In reply to this post by raja24
I have fixed it and working fine.


Thanks,
Raja.



--
Sent from: http://apache-ignite-users.70518.x6.nabble.com/
dmagda dmagda
Reply | Threaded
Open this post in threaded view
|

Re: Cache Query Filter Logic

Could you please share the root cause and a solution with everyone? It might be the case that someone else stumbles upon the same issue.

-
Denis


On Tue, Jul 30, 2019 at 1:09 PM raja24 <[hidden email]> wrote:
I have fixed it and working fine.


Thanks,
Raja.



--
Sent from: http://apache-ignite-users.70518.x6.nabble.com/
raja24 raja24
Reply | Threaded
Open this post in threaded view
|

Re: Cache Query Filter Logic

The problem is I didn't put updated jar in the server.


Thanks,
Raja.



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