有没有办法在apache ignite上运行sql字段查询来获取二进制对象(无需定义java类)?
我想执行这样的事情:
CacheConfiguration<Integer, Object> cfg = new CacheConfiguration<>();
cfg.setName("test_bo");
cfg.setIndexedTypes(Integer.class, BinaryObject.class);
IgniteCache<Integer, Object> cache = ignite.getOrCreateCache(cfg);
BinaryObjectBuilder builder = ignite.binary().builder(BinaryObject.class.getName());
BinaryObject object = builder.setField("xxx", "yyy").build();
cache.put(1, object);
List<Object[]> collect = cache.withKeepBinary().query(
new SqlFieldsQuery("select xxx from BinaryObject")).getAll().stream()
.map(list -> list.toArray(new Object[list.size()]))
.collect(Collectors.toList());
assertThat(collect).containsExactly(new Object[]{"yyy"});
但我有一个异常(exception),即字段未定义:
Caused by: org.h2.jdbc.JdbcSQLException: Column "XXX" not found; SQL statement: select xxx from BinaryObject [42122-175]
最佳答案
BinaryObject 是一个没有任何索引定义的接口(interface)。您需要将域类的准确类定义传递给 CacheConfiguration.setIndexedTypes(...)
在客户端,应该有类定义,Ignite 将收集有关已设置索引的信息。
如果您根本没有类(即使在客户端),那么您可以直接使用 QueryEntity 定义索引,如所述 here .
也没有必要将对象设为 BinaryObject
的类型。您的对象将自动以这种格式存储在服务器端。唯一的异常(exception)是实现 Externalizable
的对象或覆盖 Serializable.writeObject/readObject
方法 - 此类对象可以以二进制格式存储,并且您必须在服务器端为它们提供类定义。提供了有关二进制格式的更多信息 here .
最后我建议看一下CacheQueryExample它作为 Ignite 版本的一部分提供。本例中使用的对象模型以二进制格式存储。
关于java - Apache Iginte BinaryObject SqlFieldsQuery,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37183066/