sqlpredicate expression and normal java list/set/collection inside hazelcast map

1,205 views
Skip to first unread message

corba

unread,
Nov 5, 2013, 12:04:37 PM11/5/13
to haze...@googlegroups.com

I try to make sql predicate,

I define  in ojbect like customer sample a normal list or set inside a map of customer

class Currency() {
   int isoCode;
   String isoAlpha;

}
class Customer {

  private   Set<Currency> currencySupported
  private int id;
 private  String name;
}

How make predicate because i see only  the usage of simple assessor in hazelcast but not on normal collection/list/set object

mapCustomer.values(new SqlPredicate(" country = 'USA' AND currencySupported.isoCode = 850 ")

But i get exception on it, on normal assessor class, that run, only if i try to use on single element of set/list/collection of object

need specific syntaxe for use assesor of element ojbect class of collection on it or it is not supported ? if yes can i have a sample code.

Caused by: com.hazelcast.query.impl.QueryException: java.lang.NullPointerException
    at com.hazelcast.query.impl.ReflectionHelper.createGetter(ReflectionHelper.java:138)

Thank for help









corba

unread,
Nov 5, 2013, 12:37:08 PM11/5/13
to haze...@googlegroups.com

Note,  if i use   currencySupported.size > 1 in the sql predicate, that run  but not with currencySupported.isoCode = 850



Peter Veentjer

unread,
Nov 5, 2013, 1:07:47 PM11/5/13
to haze...@googlegroups.com
On Tue, Nov 5, 2013 at 7:04 PM, corba <jpc...@gmail.com> wrote:

I try to make sql predicate,

I define  in ojbect like customer sample a normal list or set inside a map of customer

class Currency() {
   int isoCode;
   String isoAlpha;

}
class Customer {

  private   Set<Currency> currencySupported
  private int id;
 private  String name;
}

How make predicate because i see only  the usage of simple assessor in hazelcast but not on normal collection/list/set object

mapCustomer.values(new SqlPredicate(" country = 'USA' AND currencySupported.isoCode = 850 ")

But i get exception on it, on normal assessor class, that run, only if i try to use on single element of set/list/collection of object

need specific syntaxe for use assesor of element ojbect class of collection on it or it is not supported ?

Currently that isn't supported but I think it will be relatively easy to add to the SQLPredicate and I think it would be nice feature to have.

The sql syntax should be extended so you can do a:

somemethod(arg1, arg2, ...)

or a 

somefield[arg1, arg2,..]

If you want to have the feature fast, I would suggest implementing it yourself, offer it as a pull request and we'll merge it in.

If we need to implement it ourselves, it will probably end up and the end of the list even though this is a nice feature to have.
 
if yes can i have a sample code.

Caused by: com.hazelcast.query.impl.QueryException: java.lang.NullPointerException
    at com.hazelcast.query.impl.ReflectionHelper.createGetter(ReflectionHelper.java:138)

Thank for help









--
You received this message because you are subscribed to the Google Groups "Hazelcast" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hazelcast+...@googlegroups.com.
To post to this group, send email to haze...@googlegroups.com.
Visit this group at http://groups.google.com/group/hazelcast.
For more options, visit https://groups.google.com/groups/opt_out.

Peter Veentjer

unread,
Nov 5, 2013, 1:09:28 PM11/5/13
to haze...@googlegroups.com
You can of course write your own predicate.

You can't make use of the SQLPredicate anymore if you do so (since it doesn't know about your predicate), but your predicate you can add in perhaps 10 minutes.

corba

unread,
Nov 5, 2013, 3:09:10 PM11/5/13
to haze...@googlegroups.com

Thanks for your answer 

                i switch to Predicatebuilder for create my own predicat

EntryObject e = new PredicateBuilder () getEntryObject ().;

PredicateBuilder sql = new PredicateBuilder ();

                //  Predicat prédicat = e.get ("currencySupported.isoCode").equal(850);
Predicat prédicat = e.get ("currencySupported").get ("iscoCode») equal(850);

Set <Customer> customer = (Set <Customer>) mapCustomers.values ​​(predicat);

 Seem also to be a problem, how is the syntax correct for access to a local Set/list/collect with predicat.


Caused by: java.lang.IllegalArgumentException: There is no suitable accessor for 'iscoCode'
at com.hazelcast.query.impl.ReflectionHelper.createGetter(ReflectionHelper.java:128)
... 15 more
 
if i use 
  Predicat prédicat = e.get ("currencySupported.isoCode").equal(850);

it get stack trace wit null pointer exception

 cus : Picsou
 currency : 978 Euros
 currency : 850 USD
 cus : Daisy
 currency : 978 Euros
 cus : Donald
 currency : 850 USD
 cus : Dingo
 currency : 850 USD
 cus : Rapetou
 currency : 978 Euros
 cus : TEST
 currency : 850 USD
nov. 05, 2013 9:07:25 PM com.hazelcast.map.operation.QueryOperation
SEVERE: [192.168.0.10]:5704 [dev] com.hazelcast.query.impl.QueryException: com.hazelcast.query.impl.QueryException: java.lang.NullPointerException
java.util.concurrent.ExecutionException: com.hazelcast.query.impl.QueryException: com.hazelcast.query.impl.QueryException: java.lang.NullPointerException
at java.util.concurrent.FutureTask$Sync.innerGet(FutureTask.java:252)
at java.util.concurrent.FutureTask.get(FutureTask.java:111)
at com.hazelcast.map.operation.QueryOperation.runParallel(QueryOperation.java:124)
at com.hazelcast.map.operation.QueryOperation.run(QueryOperation.java:70)
at com.hazelcast.spi.impl.OperationServiceImpl.doRunOperation(OperationServiceImpl.java:274)
at com.hazelcast.spi.impl.OperationServiceImpl.runOperation(OperationServiceImpl.java:184)
at com.hazelcast.spi.impl.InvocationImpl.doInvoke(InvocationImpl.java:169)
at com.hazelcast.spi.impl.InvocationImpl.invoke(InvocationImpl.java:103)
at com.hazelcast.map.proxy.MapProxySupport.query(MapProxySupport.java:675)
at com.hazelcast.map.proxy.MapProxyImpl.values(MapProxyImpl.java:461)
at hazelcast.GettingStartedClientTest.main(GettingStartedClientTest.java:55)
Caused by: com.hazelcast.query.impl.QueryException: com.hazelcast.query.impl.QueryException: java.lang.NullPointerException
at com.hazelcast.query.impl.QueryEntry.extractViaReflection(QueryEntry.java:88)
at com.hazelcast.query.impl.QueryEntry.getAttribute(QueryEntry.java:78)


corba

unread,
Nov 5, 2013, 3:31:34 PM11/5/13
to haze...@googlegroups.com
the display is the list is before  predicate execution for  get filter of customer list having a currency 850

corba

unread,
Nov 5, 2013, 4:31:32 PM11/5/13
to haze...@googlegroups.com

for test, i change the predicate by the sample line demo, that run in this case

Predicate predicate = e.is("activ").and(e.get("age").lessThan(30)); 


but that is not i expect.  with predicate  i cannot access to java set/list/collection in my object and i dont see method in predicate builder to do that.

Peter Veentjer

unread,
Nov 6, 2013, 2:15:15 AM11/6/13
to haze...@googlegroups.com
I don't know if it is possible using the predicatebuilder (it could be.. don't know sure).

But you need to write your own predicate implementation; something I didn't see in your previous posts. 

Look up the predicate interface. 


corba

unread,
Nov 6, 2013, 2:40:40 PM11/6/13
to haze...@googlegroups.com
Thanks,

i got today,  the solution  for write my self my own predicate implementation with the interface 

KR

corba

unread,
Nov 6, 2013, 3:34:39 PM11/6/13
to haze...@googlegroups.com
for test, i get  allcustomer having a currency 850 existing in currencysupported list. the basic usage is very limited, if we need something
more "complex" we must implement the method apply from interface Predicate.

Set<Customer> customer = (Set<Customer>) mapCustomers.values(new MyPredicate());

public class MyPredicate implements Predicate {

@Override
public boolean apply(Entry mapEntry) {

System.out.println("keyvalue: "+mapEntry.getKey());
Customer cus=(Customer) mapEntry.getValue();
Set<Currency> currencySupported=cus.getcurrencySupported();
for (  Currency cur : currencySupported  ){
if ( cur.getIsoCode().equals(new Integer(850)) == true) {
return true;
}
}
return false;
}
}



andrei...@gmail.com

unread,
Aug 10, 2017, 3:27:17 AM8/10/17
to Hazelcast
Now we can do it to to access attribute of one element from collection or array:

Predicate p = Predicates.equal('wheels[0].name', 'front-wheel'); Collection<Motorbike> result = map.values(p);

or it to access attribute from all items of collection:

Predicate p = Predicates.equal('wheels[any].name', 'front'); Collection<Motorbike> result = map.values(p);

Reply all
Reply to author
Forward
0 new messages