You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ignite.apache.org by Marasoiu Nicolae <Ni...@cegeka.com> on 2017/04/04 04:43:36 UTC

continuous query equivalent to cache.get ?

Hi,


I want to get continuous updates of the value of a certain key on a certain cache, so I thought of a continuous query based on an initial query like this:

SELECT _value from CACHE where _key=KEY

Questions:

- is this possible with this syntax?

- is this an SQL Query (the initial query I mean)?

- does it need any configuration added on the cacheConfiguration?

I added setIndexedTypes(String,Object) since String is the key type.

I however get: "CacheException: Failed to find SQL table for type: String".


Another way to get a stream of updates on a key is to listen to cache events, however that is listening to all the caches. Even listening locally (since we are listening to a replicated cache updates and a low writes one), it would still be listening to a lot of updates just for a small fraction of them.


What would be other alternatives, to get a stream of updates on a key?


Thank you


Met vriendelijke groeten / Meilleures salutations / Best regards


Nicolae Marasoiu
Agile Developer

[http://signature.cegeka.com/2016/stripe-small.jpg]


E  Nicolae.Marasoiu@cegeka.com<ma...@cegeka.com>


[http://signature.cegeka.com/2016/stripe-large.jpg]


[http://signature.cegeka.com/2016/logo.jpg]     CEGEKA 15-17 Ion Mihalache Blvd. Tower Center Building, 4th,5th,6th,8th,9th fl
RO-011171 Bucharest (RO), Romania
T +40 21 336 20 65
WWW.CEGEKA.COM<http://www.cegeka.com>   [LinkedIn]  <https://www.linkedin.com/company/cegeka-romania>



Re: continuous query equivalent to cache.get ?

Posted by Nikolai Tikhonov <nt...@apache.org>.
Hi,

You can use any SQL query as initianl query. Look at the following Ignite
example [1] and doc [2]. In your case you can start the following
Continuous Query which will be received events for specified key.

ContinuousQuery<Integer, String> qry = new ContinuousQuery<>();

qry.setInitialQuery(new SqlQuery<String, Object>("_key = 'key1'"));

// This filter will be evaluated remotely on all nodes.
// Entry that pass this filter will be sent to the caller.
qry.setRemoteFilterFactory(new Factory<CacheEntryEventFilter<Integer,
String>>() {
@Override public CacheEntryEventFilter<Integer, String> create() {
return new CacheEntryEventFilter<Integer, String>() {
@Override public boolean evaluate(CacheEntryEvent<? extends Integer, ?
extends String> e) {
                return e.getKey().equals("key1");
            }
        };
    }
});

qry.setLocalListener(new CacheEntryUpdatedListener<Integer, String>() {
    @Override public void onUpdated(Iterable<CacheEntryEvent<? extends
Integer, ? extends String>> evts) {
        for (CacheEntryEvent<? extends Integer, ? extends String> e : evts)
            System.out.println("Updated entry [key=" + e.getKey() + ",
val=" + e.getValue() + ']');
    }
});



1.
https://github.com/apache/ignite/blob/master/examples/src/main/java/org/apache/ignite/examples/datagrid/CacheContinuousQueryExample.java
2.https://apacheignite.readme.io/docs/continuous-queries

On Tue, Apr 4, 2017 at 7:43 AM, Marasoiu Nicolae <
Nicolae.Marasoiu@cegeka.com> wrote:

> Hi,
>
>
> I want to get continuous updates of the value of a certain key on a
> certain cache, so I thought of a continuous query based on an initial query
> like this:
>
> SELECT _value from CACHE where _key=KEY
>
> Questions:
>
> - is this possible with this syntax?
>
> - is this an SQL Query (the initial query I mean)?
>
> - does it need any configuration added on the cacheConfiguration?
>
> I added setIndexedTypes(String,Object) since String is the key type.
>
> I however get: "CacheException: Failed to find SQL table for type: String
> ".
>
>
> Another way to get a stream of updates on a key is to listen to cache
> events, however that is listening to all the caches. Even listening locally
> (since we are listening to a replicated cache updates and a low writes
> one), it would still be listening to a lot of updates just for a small
> fraction of them.
>
>
> What would be other alternatives, to get a stream of updates on a key?
>
>
> Thank you
>
>
> Met vriendelijke groeten / Meilleures salutations / Best regards
>
> *Nicolae Marasoiu*
> *Agile Developer*
>
> *E*  *Nicolae.Marasoiu@cegeka.com <Ni...@cegeka.com>*
>
> CEGEKA 15-17 Ion Mihalache Blvd. Tower Center Building,
> 4th,5th,6th,8th,9th fl
> RO-011171 Bucharest (RO), Romania
> *T* +40 21 336 20 65
> *WWW.CEGEKA.COM <http://www.cegeka.com>*  [image: LinkedIn]
> <https://www.linkedin.com/company/cegeka-romania>
>