I was having a ignite cache and doing sql queries as follows.
IgniteCache<String, ClassName> cache = ignite.cache(CACHE_NAME);
private static final String sql = "Select timestamp from cache1 where orderId = ? and timestamp <= ? and timestamp >= ? ";
SqlFieldsQuery sqlQ = new SqlFieldsQuery(sql).setArgs(id, t1, t2);
try (QueryCursor<List<?>> cursor = cache.query(sqlQ)) {
for (List<?> row : cursor) {
timestamps.add((Long) row.get(0));
}
Now I want to query from three different caches and get the union. I was able to successfully execute the SQL command in a SQL engine as follows and get results.
Select starttime from "unconfirmed_event_mc_79".unconfirmedevent union all Select starttime from "unconfirmed_event_urgent_mc_79".unconfirmedevent union all Select starttime from "confirmed_event_mc_79".confirmedevent order by starttime desc limit 1;
I want to add the timestamp results from three separate caches to a single arraylist. I tried following method and it was not successful.
EVENT_GET_RHYTHM_BY_ID = "Select timestamp from ConfirmedEvent where orderId = ? and startTime < ? and endTime > ? and type = %s UNION ALL " +
"Select timestamp from " + String.format(UNCONFIRMED_NON_URGENT_EVENT_CACHE,mcId) + ".UnconfirmedEvent where orderId = ? and startTime < ? and endTime > ? and type = %s " +
"Select timestamp from " + String.format(UNCONFIRMED_URGENT_EVENT_CACHE,mcId) + ".UnconfirmedEvent where orderId = ? and startTime < ? and endTime > ? and type = %s " + " order by startTime";
sql_Afib = new SqlFieldsQuery(String.format(EVENT_GET_RHYTHM_BY_ID, AnnotationConverter.StringToRhythmValue(AFIB), AnnotationConverter.StringToRhythmValue(AFIB),
AnnotationConverter.StringToRhythmValue(AFIB))).setArgs(orderId, endTimestamp, startTimestamp,
orderId, endTimestamp, startTimestamp, orderId, endTimestamp, startTimestamp);
try (QueryCursor<List<?>> cursor = confirmedEventCache.query(sql_Afib)) {
for (List<?> row : cursor) {
EventsEndTime.add(row.get(0));
}
}
I want to know how to use the query cursor? Now there are three caches and how to do the this part? (QueryCursor<List<?>> cursor = cache.query(sqlThreeCaches)) and how to write the SQL field in a java code?
Or is there any other way to do this?
Here is how I define the caches in a java code. There are three different caches, but column names in the cache tables are same.
public static final String EVENT_VIEW_RESERVED_EVENT_CACHE = "event_view_reserved_event_mc_%d";
public static final String UNCONFIRMED_NON_URGENT_EVENT_CACHE = "unconfirmed_event_mc_%d";
public static final String UNCONFIRMED_URGENT_EVENT_CACHE = "unconfirmed_event_urgent_mc_%d";
IgniteCache<String, ConfirmedEvent> confirmedEventCache = ignite.cache(String.format(CONFIRMED_EVENT_CACHE, mcId));
IgniteCache<String, UnconfirmedEvent> unconfirmedEventCache = ignite.cache(String.format(UNCONFIRMED_NON_URGENT_EVENT_CACHE,mcId));
IgniteCache<String, UnconfirmedEvent> unconfirmedUrgentEventCache = ignite.cache(String.format(UNCONFIRMED_URGENT_EVENT_CACHE,mcId));