java - Apache Iginte BinaryObject SqlFieldsQuery

标签 java ignite

有没有办法在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/

相关文章:

java - 使用 "Discouraged Access"规则引用 jar 文件内定义的 (org.eclipse.ui.internal) 类型有何影响?

java - 从 Instant App 下载并安装 apk(无需在 Playstore 中发布)

java - 是否有可行的手写识别库/程序?

java - 在 Ignite 缓存中插入数据时出现以下错误?

java - 使用 DataStream 的 addData 点燃事务。可能的?

java - java中创建数组时new操作符是干什么用的?

Java/可序列化 - 仅覆盖已更改的对象

java - 如何将经过身份验证的 WebSession 存储在分布式内存缓存中

java - 运行 ignite 服务器节点

java - Apache Ignite SqlFieldQuery 位于存储 BinaryObject 的缓存之上