I have a Postgres database configured as my persistence layer and would like to execute SQL queries against the Postgres tables cached in Ignite.
Ideally, I’d like to execute a query on these caches and be returned the Value objects represented by these tables.
SqlQuery gives me the functionality that I am looking for but is deprecated.
SqlFieldsQuery
would work, but I would prefer not to have to deal with the row data a List<?>. Is there a way to get SqlFieldsQuery
to return the value as an object and now as a list of its Fields?
I thought Continuous query could be a possible alternative but I am not interested in listening to cache updates and it is not compatible with SqlFieldsQuery
.
Advertisement
Answer
Use _key
and _val
keywords to retrieve the entire key and/or value objects.
IgniteCache<Long, Person> cache = ignite.cache("Person"); SqlFieldsQuery sql = new SqlFieldsQuery( "select _val from Person where age > ?", 28); try (QueryCursor<List<?>> cursor = cache.query(sql)) { for (List<?> row : cursor) { Person p = (Person) row.get(0); System.out.println(p); } }