Search code examples
ignite

Ignite SqlQuery for complex java objects


In my cache I have a complex java object as below -

class Person{
  private Department d;
  ...
}

class Department {
  private Department code;
  ...
}

I am using below SQLQuery to read it:

SqlQuery<Short, BinaryObject> query = new SqlQuery<>(Person.class, "d.code = ?");
String args="101"; // department code
QueryCursor<Cache.Entry<Short, BinaryObject>> resultSet = personCache.query(query.setArgs(args))

I am getting below error:

Caused by: class org.apache.ignite.internal.processors.query.IgniteSQLException: Failed to parse query: SELECT "PERSON_CACHE"."PERSONENTITY"._KEY, "TPERSON_CACHE"."PERSONENTITY"._VAL FROM "PERSON_CACHE"."PERSONENTITY" WHERE id.code = ?

Am I doing anything wrong here ?


Solution

  • I resolved it by using predicate.

    IgniteBiPredicate<Long, BinaryObject> predicate = new IgniteBiPredicate<Long, BinaryObject>() {
            @Override
            public boolean apply(Long e1, BinaryObject e2) {
              Person p= e2.deserialize();
              short s = (short) args[0];
              return p.getId().getCode == s;
            }
          };