首页 文章

Apache Iginte BinaryObject SqlFieldsQuery

提问于
浏览
2

有没有办法运行sql字段查询apache点燃二进制对象(没有定义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"});

但我有一个例外,那个字段没有定义:

Caused by: org.h2.jdbc.JdbcSQLException: Column "XXX" not found; SQL statement: select xxx from BinaryObject [42122-175]

1 回答

  • 2

    BinaryObject是一个没有任何索引定义的接口 . 您需要在客户端将域类的确切类定义传递给 CacheConfiguration.setIndexedTypes(...) ,它应具有类定义,Ignite将收集有关已设置的索引的信息 .

    如果您根本没有类(甚至在客户端),那么您可以直接使用QueryEntity定义索引,如here所述 .

    此外,不需要使对象成为 BinaryObject 的类型 . 您的对象将自动以这种格式存储在服务器端 . 唯一的例外是实现 Externalizable 或覆盖 Serializable.writeObject/readObject 方法的对象 - 这些对象可以以二进制格式存储,您必须在服务器端具有类定义 . 有关二进制格式的更多信息,请参见here .

    最后,我建议您查看作为Ignite版本的一部分提供的CacheQueryExample . 此示例中使用的对象模型以二进制格式存储 .

相关问题