You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ignite.apache.org by BinaryTree <bi...@foxmail.com> on 2019/03/08 08:28:42 UTC

Can I update specific field of a binaryobject

Hi Igniters - 


As far as I am known, igniteCache.put(K, V) will replace the value of K with V, but sometimes I just would like to update a specific field of V instead of the whole object.
I know that I can update the specific field via igniteCache.query(SqlFieldsQuery),  but how-ignite-sql-works writes that ignite will generate SELECT queries internally before UPDATE or DELETE a set of records, so it may not be as good as igniteCache.put(K, V), so is there a way can update a specific field without QUERY?

Re: Can I update specific field of a binaryobject

Posted by Ilya Kasnacheev <il...@gmail.com>.
Hello!

You can do cache.invoke() with a callback that will update a single field
in an object. It will be sent to a specific node in cluster and object in
question will not be transferred via network, but processed locally.

Note that UPDATE will probably only send request to node containing
relevant key if that is specified, and not broadcast it.

Regards,
-- 
Ilya Kasnacheev


пт, 8 мар. 2019 г. в 11:28, BinaryTree <bi...@foxmail.com>:

> Hi Igniters -
>
> As far as I am known, igniteCache.put(K, V) will replace the value of K
> with V, but sometimes I just would like to update a specific field of V
> instead of the whole object.
> I know that I can update the specific field via
> igniteCache.query(SqlFieldsQuery),  but how-ignite-sql-works
> <https://apacheignite-sql.readme.io/docs/how-ignite-sql-works> writes
> that ignite will generate SELECT queries internally before UPDATE or DELETE
> a set of records, so it may not be as good as igniteCache.put(K, V), so is
> there a way can update a specific field without QUERY?
>
>

Re: Can I update specific field of a binaryobject

Posted by Justin Ji <bi...@foxmail.com>.
Besides the question above, I have another question.
If I use a composed key like this:
public class DpKey implements Serializable {
    //key=devId + "_" + dpId
    private String key;
    @AffinityKeyMapped
    private String devId;
   //getter setter
}

Now I need to add records like this,
IgniteCache<DpKey, CacheEntry> cache = ignite.cache("cache");
cache.query(new SqlFieldsQuery("MERGE INTO t_cache(id, devId, dpId)" +
           " values (1, 'devId001', '001'), (2, 'devId002', '002')"));
And I also need to get value with igniteCache.get(key), but I do not know
what is the key.

Can I assign a key when inserting a record?







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