如何使用SQL UNION与点燃缓存



我有一个点燃缓存和做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联合操作。

private static final String sqlTwoCaches = "Select timestamp from cache1 union all Select timestamp from cache2 order by timestamp";

我想把两个缓存的时间戳结果添加到一个数组列表中。我想知道如何使用查询游标?现在有两个缓存,这部分怎么做?(QueryCursor<List<?>> cursor = cache.query(sqlTwoCaches))

或者有其他方法可以做到这一点吗?

你需要"完全限定";第二个缓存名,否则,它应该是Just Work。

的例子:

IgniteCache<String, ClassName1> cache1 = ignite.cache("table1");
IgniteCache<String, ClassName2> cache2 = ignite.cache("table2");
private static final String sql = "select timestamp from ClassName1 UNION ALL select timestamp from table2.ClassName2 ";
SqlFieldsQuery sqlQ = new SqlFieldsQuery(sql);
try (QueryCursor<List<?>> cursor = cache1.query(sqlQ)) {
for (List<?> row : cursor) {
timestamps.add((Long) row.get(0));          
}
}

最新更新