You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ignite.apache.org by begineer <re...@gmail.com> on 2018/12/12 15:15:17 UTC
How to run Ignite REST API scan query with predicate
Hi Guys,
I have an ignite cache of type <String, TradeObject>distributed over several
nodes. I want to query its data using ignite REST APIS as mentioned
https://apacheignite.readme.io/v2.6/docs/rest-api#sql-scan-query-execute
I am able to query the cache without predicate and page size
http://host:port/ignite?cmd=qryscanexe&pageSize=10&cacheName=myCacheName
but I would like to do a bit more and add predicate to query. Something like
this
http://host:port/ignite?cmd=qryscanexe&pageSize=10&cacheName=Person&className=myprojectpackage.TradeObjectPredicate
class TradeObjectPredicate implements IgniteBiPredicate<String, TradeObject>
{
private final String tradeObjectField1;
private final Set<String> tradeObjectField2List;
}
How do i pass this predicate so that I can get matching results.
Thanks in Advance
--
Sent from: http://apache-ignite-users.70518.x6.nabble.com/
Re: How to run Ignite REST API scan query with predicate
Posted by Ilya Kasnacheev <il...@gmail.com>.
Hello!
I understand your concern but REST does not support such use case out of
box.
You could try implementing your own *ConnectorMessageInterceptor* to read
additional params from request, put them to thread-local, get them from
thread-local in constructor.
But I think you will be served better by either ComputeTask invocation or
SQL query.
Regards,
--
Ilya Kasnacheev
сб, 15 дек. 2018 г. в 08:21, begineer <re...@gmail.com>:
> OK, May be I wasn't clear before. Lets say cache contains entries
> 1. Trade1-> TradeObject{field1 =2, other fields....}
> Trade2-> TradeObject{field1 =3, other fields....}
> Trade3-> TradeObject{field1 =2, other fields....}
>
> Now if I run scan query without filter, it will return above 3 entries.
> But lets say I want to fetch only record 1 and 3. So I create a Predicate
> with below field and values
> String tradeObjectField1 = 2,
> Set<String> tradeObjectField2List = {Trade1, Trade3}
>
> Now, with default constructor, how will these values be set
>
>
>
> --
> Sent from: http://apache-ignite-users.70518.x6.nabble.com/
>
Re: How to run Ignite REST API scan query with predicate
Posted by begineer <re...@gmail.com>.
OK, May be I wasn't clear before. Lets say cache contains entries
1. Trade1-> TradeObject{field1 =2, other fields....}
Trade2-> TradeObject{field1 =3, other fields....}
Trade3-> TradeObject{field1 =2, other fields....}
Now if I run scan query without filter, it will return above 3 entries.
But lets say I want to fetch only record 1 and 3. So I create a Predicate
with below field and values
String tradeObjectField1 = 2,
Set<String> tradeObjectField2List = {Trade1, Trade3}
Now, with default constructor, how will these values be set
--
Sent from: http://apache-ignite-users.70518.x6.nabble.com/
Re: How to run Ignite REST API scan query with predicate
Posted by Ilya Kasnacheev <il...@gmail.com>.
Hello!
You don't. It will be initialized from empty constructor.
Regards,
--
Ilya Kasnacheev
чт, 13 дек. 2018 г. в 16:43, begineer <re...@gmail.com>:
> Ok Even if i add default constructor, how do I pass parameters of this
> class
> to query ?
>
>
>
> --
> Sent from: http://apache-ignite-users.70518.x6.nabble.com/
>
Re: How to run Ignite REST API scan query with predicate
Posted by begineer <re...@gmail.com>.
Ok Even if i add default constructor, how do I pass parameters of this class
to query ?
--
Sent from: http://apache-ignite-users.70518.x6.nabble.com/
Re: How to run Ignite REST API scan query with predicate
Posted by Ilya Kasnacheev <il...@gmail.com>.
Hello!
I guess your class should have default constructor. This means it has to
define its data statically or take it from some pre-defined location.
Relevant code snippet from QueryCommandHandler:
case SCAN:
IgniteBiPredicate pred = null;
if (req.className() != null)
pred = instance(IgniteBiPredicate.class, req.className());
qry = new ScanQuery(pred);
break;
Regards,
--
Ilya Kasnacheev
ср, 12 дек. 2018 г. в 20:58, begineer <re...@gmail.com>:
> Yes, Predicate class is public and implement appy(). But I am trying to
> understand how to set the fields of the predicate class.
>
> It has a constructor which takes two parameters
>
> public TradeObjectPredicate(String tradeObjectField1, Set<String>
> tradeObjectField2List){
> .....
> }
> How to pass these values from REST API.
>
> This is the error I am getting
>
> {"successStatus":1,"error":"Failed to find constructor for provided
> arguments
>
> [clsName=myprojectpackage.TradeObjectPredicate]","sessionToken":null,"response":null}
>
> Does it mean I have add default constructor to this class or add JSON
> annotations for serialization. But If I add default constructor, predicate
> filters will be null.
>
> Please advise
>
>
>
> --
> Sent from: http://apache-ignite-users.70518.x6.nabble.com/
>
Re: How to run Ignite REST API scan query with predicate
Posted by begineer <re...@gmail.com>.
Yes, Predicate class is public and implement appy(). But I am trying to
understand how to set the fields of the predicate class.
It has a constructor which takes two parameters
public TradeObjectPredicate(String tradeObjectField1, Set<String>
tradeObjectField2List){
.....
}
How to pass these values from REST API.
This is the error I am getting
{"successStatus":1,"error":"Failed to find constructor for provided
arguments
[clsName=myprojectpackage.TradeObjectPredicate]","sessionToken":null,"response":null}
Does it mean I have add default constructor to this class or add JSON
annotations for serialization. But If I add default constructor, predicate
filters will be null.
Please advise
--
Sent from: http://apache-ignite-users.70518.x6.nabble.com/
Re: How to run Ignite REST API scan query with predicate
Posted by Ilya Kasnacheev <il...@gmail.com>.
Hello!
Your example should be working all right. Note that the class should be
public (and not package private) and implementapply() method.
Do you get any specific errors when you try that?
Regards,
--
Ilya Kasnacheev
ср, 12 дек. 2018 г. в 18:15, begineer <re...@gmail.com>:
> Hi Guys,
> I have an ignite cache of type <String, TradeObject>distributed over
> several
> nodes. I want to query its data using ignite REST APIS as mentioned
>
> https://apacheignite.readme.io/v2.6/docs/rest-api#sql-scan-query-execute
>
> I am able to query the cache without predicate and page size
> http://host:port/ignite?cmd=qryscanexe&pageSize=10&cacheName=myCacheName
>
> but I would like to do a bit more and add predicate to query. Something
> like
> this
>
> http://host:port
> /ignite?cmd=qryscanexe&pageSize=10&cacheName=Person&className=myprojectpackage.TradeObjectPredicate
>
> class TradeObjectPredicate implements IgniteBiPredicate<String,
> TradeObject>
> {
> private final String tradeObjectField1;
> private final Set<String> tradeObjectField2List;
> }
>
> How do i pass this predicate so that I can get matching results.
>
> Thanks in Advance
>
>
>
>
> --
> Sent from: http://apache-ignite-users.70518.x6.nabble.com/
>