Unable to query nested objects in portable array

385 views
Skip to first unread message

gtit...@gmail.com

unread,
Mar 8, 2016, 9:31:25 AM3/8/16
to Hazelcast
Hi,

I have the following portable classes:

public class Agreement implements Portable {
    public final static int ID = 10;
    
    private String aid;
    private List<AgreementEntity> agreementEntities;


public class AgreementEntity implements Portable {
    public final static int ID = 5;
    
    public static enum TYPE {PRODUCT, INFOOBJECT};
    public static enum PAYMENTMODEL{TICS};
    
    private String aid;
    private TYPE type;
    private PAYMENTMODEL paymentModel;


The portable objects are working correctly when searching for attributes in Agreement object, however I want to do a nested query:

public List<Agreement> findAllAgreementsByCustomerNumberAndEntityId(String customerNumber, String entityId) throws ServiceException {
        EntryObject e = new PredicateBuilder().getEntryObject();
        Predicate p_customerNumber = Predicates.equal("customerNumber", customerNumber);
        Predicate p_entityId = Predicates.equal("agreementEntities[any].id", "1");        
        Predicate predicate = Predicates.and( p_customerNumber, p_entityId );
        
        Collection<Agreement> agreementEntities = agreementCache.values(predicate);
        return new ArrayList<>(agreementEntities);
    }

But it fails with the following exception:

Caused by: com.hazelcast.query.QueryException: java.lang.IllegalArgumentException: Unknown field: agreementEntities[any]
        at com.hazelcast.query.impl.QueryableEntry.extractViaPortable(QueryableEntry.java:166)
        at com.hazelcast.query.impl.QueryableEntry.extractAttributeValueFromTargetObject(QueryableEntry.java:147)
        at com.hazelcast.query.impl.QueryableEntry.extractAttributeValue(QueryableEntry.java:82)
        at com.hazelcast.query.impl.QueryableEntry.getAttributeValue(QueryableEntry.java:48)
        at com.hazelcast.query.impl.predicates.AbstractPredicate.readAttributeValue(AbstractPredicate.java:130)
        at com.hazelcast.query.impl.predicates.AbstractPredicate.apply(AbstractPredicate.java:55)


It seems like it can't recognize the  [any] semantics, I have also tried with agreementEntities.aid  in my predicate and the result is the same.

Is it possible to use portable and nested query together? If so I would gladly appreciate any help in how to do it right.

According to documentation for 3.6.1 (used):

It is also possible to query a collection / array using the any semantic as shown below:

// it matches all motorbikes where any wheel's name is 'front-wheel'
Predicate p = Predicates.equals('wheels[any].name', 'front');
Collection<Motorbike> result = map.values(p);

t...@hazelcast.com

unread,
Mar 8, 2016, 9:40:03 AM3/8/16
to Hazelcast, gtit...@gmail.com
Hi,

Querying in arrays of Portables or nested queries in Portables are not supported for now but I've been intensively working on it for the last two weeks.

I think I may publish a snapshot branch in a couple of days - you'll be able to run your test cases against it.

This functionality will be added in the next planned release - 3.6.2.

Cheers,
Tom

--
Software Engineer @ Hazelcast

gtit...@gmail.com

unread,
Mar 8, 2016, 10:30:14 AM3/8/16
to Hazelcast, gtit...@gmail.com
Thanks for the (very) fast reply, I will wait for release 3.6.2 then :-)

regards 

Tomas

t...@hazelcast.com

unread,
Apr 11, 2016, 9:49:22 AM4/11/16
to Hazelcast, gtit...@gmail.com
Unfortunately this feature didn't make it to 3.6.2
It's still an on-going work and I've been working on it very intensively. 
I'll keep you updated once it's available in the snapshot.

Cheers
Tom

victo...@gmail.com

unread,
May 10, 2016, 6:10:59 AM5/10/16
to Hazelcast, gtit...@gmail.com
Hi,

I had two questions related to this:
 - will it go into 3.6.3? :)
 - is there the same problem with DataSerializable (and IdentifiedDataSerializable)?

Thanks!

t...@hazelcast.com

unread,
May 10, 2016, 6:52:53 AM5/10/16
to Hazelcast, gtit...@gmail.com
hi

Yes it will go to 3.6.3
No there's no problem with that.

Cheers
Tom

victo...@gmail.com

unread,
May 10, 2016, 7:34:11 AM5/10/16
to Hazelcast, gtit...@gmail.com
Great, thanks for the quick answer :)

t...@hazelcast.com

unread,
May 28, 2016, 12:23:37 PM5/28/16
to Hazelcast, gtit...@gmail.com
Hi guys,

This feature should work in 3.6.3 which should be released anytime soon.
Please follow the release announcements!

Cheers
Tom

victo...@gmail.com

unread,
Jun 2, 2016, 9:30:07 AM6/2/16
to Hazelcast, gtit...@gmail.com
FYI it seems to work well in my setup :)

I'm just using a Portable that contains strings and also an array of Strings, I didn't test other more complex cases.

Portable does not support enum as DataSerializable does through writeObject, no?
I noticed that if I write the name of the enum (with name() and not toString()) then I still can do queries by passing an instance of the enum to an EqualPredicate.
I guess it is because the Predicate converts the enum to a string, but it does it with toString and not name() in EnumConverter

Two interesting improvements could be:
 - use name() inside the EnumConverter because it is meant to be a value that is more stable than toString()
 - support enums in PortableWriter/Reader

I will open an issue if these make sense.

Victor

Tom Bujok

unread,
Jun 2, 2016, 11:15:20 AM6/2/16
to haze...@googlegroups.com

Hi Victor

Thanks for your feedback! I'm happy it works fine in your use case.

I agree that using name() would be more clean but I'm afraid of loosing backward compatibility by introducing this change. Opening a ticket to track it would be great though.

Supporting enums in portable is a bit broader topic. I'm not sure if there's any explicit plan to extend the portable format. IMHO not in 3.x release roadmap. And as you said, it's relatively easy to work it around. Thx for this hint anyway!

Cheers
Tom

--
You received this message because you are subscribed to a topic in the Google Groups "Hazelcast" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/hazelcast/ZjMaxNMAzFU/unsubscribe.
To unsubscribe from this group and all its topics, send an email to hazelcast+...@googlegroups.com.
To post to this group, send email to haze...@googlegroups.com.
Visit this group at https://groups.google.com/group/hazelcast.
To view this discussion on the web visit https://groups.google.com/d/msgid/hazelcast/90baa2ac-9eb2-4d31-9afa-fa7dfa8469c1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages