java - 三个 Ignite 缓存的 SQL Union All
问题描述
我有三个 Ignite 缓存,我想同时查询这三个缓存。我已经尝试过这种方法。
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, Annotations> annotationsCache = ignite.cache(String.format(ANNOTATION_CACHE, orderId));
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));
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);
List<Long> EventsEndTime = new ArrayList<>();
try (QueryCursor<List<?>> cursor = confirmedEventCache.query(sql_Afib)) {
for (List<?> row : cursor) {
EventsEndTime.add(row.get(0));
}
}
简单来说,我的 sql 查询就是这样。
private static final String sql = "select timestamp from ClassName1 UNION ALL select timestamp from table2.ClassName2 UNION ALL select timestamp from table3.ClassName3"; SqlFieldsQuery sqlQ = new SqlFieldsQuery(sql); try (QueryCursor<List<?>> cursor = cache1.query(sqlQ)) { ....
但我收到了这个错误。
CacheException: Failed to parse query. Schema "UNCONFIRMED_EVENT_MC_79" not found; SQL statement:
Select _val from ConfirmedEvent where orderId = ? and startTime < ? and endTime > ? and type = 7 UNION ALL Select _val from unconfirmed_event_mc_79.UnconfirmedEvent where orderId = ? and startTime < ? and endTime > ? and type = 7 Select _val from unconfirmed_event_urgent_mc_79.UnconfirmedEvent where orderId = ? and startTime < ? and endTime > ? and type = 7 order by startTime [90079-199]
javax.cache.CacheException: Failed to parse query. Schema "UNCONFIRMED_EVENT_MC_79" not found; SQL statement:
Select _val from ConfirmedEvent where orderId = ? and startTime < ? and endTime > ? and type = 7 UNION ALL Select _val from unconfirmed_event_mc_79.UnconfirmedEvent where orderId = ? and startTime < ? and endTime > ? and type = 7 Select _val from unconfirmed_event_urgent_mc_79.UnconfirmedEvent where orderId = ? and startTime < ? and endTime > ? and type = 7 order by startTime [90079-199]
at org.apache.ignite.internal.processors.cache.IgniteCacheProxyImpl.query(IgniteCacheProxyImpl.java:828)
at org.apache.ignite.internal.processors.cache.IgniteCacheProxyImpl.query(IgniteCacheProxyImpl.java:761)
at org.apache.ignite.internal.processors.cache.GatewayProtectedCacheProxy.query(GatewayProtectedCacheProxy.java:385)
从单个 sql 查询联合三个缓存的适当方法是什么?以及如何传递该查询的参数?
解决方案
根据错误,您正在尝试使用无效架构查询表:Schema "UNCONFIRMED_EVENT_MC_79" not found;
这与UNION ALL
操作无关。
看起来您的表定义在不同的缓存中。尝试执行以下操作:将这个并集分成 3 个部分并单独检查它们。特别检查此查询:
"Select timestamp from " + String.format(UNCONFIRMED_NON_URGENT_EVENT_CACHE,mcId) + ".UnconfirmedEvent where orderId = ? and startTime < ? and endTime > ? and type = %s "
推荐阅读
- reactjs - 无法拖动 React 引导选项卡 - React Beautiful dnd
- amazon-web-services - 容器化监控
- python - 如何在程序运行时进行 random.randint 刷新?
- ruby-on-rails - 在控制器中检测基本网址?
- python - 在 python 函数中使用库
- ruby-on-rails - ActiveModelSerializers:camel_lower 配置不起作用
- node.js - ts-jest 禁用 babel,babel 似乎仍在运行
- lambda - lambda 表达式中逗号的 F# 语法
- mysql - 在nodejs mysql的选择查询中将数组作为值传递
- linux - 如何确定 systemd EnvironmentFile 将设置的精确环境变量集?