SQL Query to Value

classic Classic list List threaded Threaded
2 messages Options
PunxsutawneyPhil3 PunxsutawneyPhil3
Reply | Threaded
Open this post in threaded view
|

SQL Query to Value

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 t 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?

It looks like Continuous query is a possible alternative but I am not
interested in listening to cache updates.

Thanks.  



--
Sent from: http://apache-ignite-users.70518.x6.nabble.com/
ptupitsyn ptupitsyn
Reply | Threaded
Open this post in threaded view
|

Re: SQL Query to Value

Copying my reply from StackOveflow [1] here.

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);
    }
}



On Wed, Feb 17, 2021 at 8:59 PM PunxsutawneyPhil3 <[hidden email]> wrote:
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 t 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?

It looks like Continuous query is a possible alternative but I am not
interested in listening to cache updates.

Thanks. 



--
Sent from: http://apache-ignite-users.70518.x6.nabble.com/