java - 如何将 SQL UNION 与三个独立的 Ignite 缓存一起使用
问题描述
我有一个点燃缓存并按如下方式执行 sql 查询。
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));
}
现在我想从三个不同的缓存中查询并获得联合。我能够如下在 SQL 引擎中成功执行 SQL 命令并获得结果。
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;
我想将来自三个单独缓存的时间戳结果添加到单个数组列表中。我尝试了以下方法,但没有成功。
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));
}
}
我想知道如何使用查询游标?现在有三个缓存,这部分怎么做?(QueryCursor<List<?>> cursor = cache.query(sqlThreeCaches)) 以及如何在java代码中编写SQL字段?
或者有没有其他方法可以做到这一点?
这是我在 java 代码中定义缓存的方式。存在三种不同的缓存,但缓存表中的列名相同。
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));
解决方案
推荐阅读
- stata - foreach - 循环遍历特定的观察值以获得特定的输出
- html - 如何从 Angular 7 的组件列表中预先选择默认项
- postgresql - PostgreSQL 模式匹配 LIKE 子句返回不正确的结果
- assembly - 如何在 MIPS 中实现 if(condition1 && condition2)?
- odbc - 64 位 DBeaver 无法连接到 ODBC 源 - “参数编号超出范围”。
- algorithm - 如果 n=100 的 O(lg(n)) 算法需要 1s 才能运行,那么如何计算 n=1000 需要多长时间?
- reactjs - 使用 react-pdf 在新窗口中从 Base64 数据渲染 PDF
- c - 二分法 - 循环中断
- c - 有没有办法将转义序列变成字符串?
- python - 根据其他行值填充 Pandas DataFrame NaN 值的最佳方法是什么?