Apache Ignite SqlFieldQuery存储在BinaryObject

时间:2017-07-29 17:27:14

标签: apache distributed-computing ignite gridgain

Hello GridGain / Ignite pros -

我似乎无法让这个工作,并搜索网络文件或示例无济于事

目标

BinaryObject值支持的Ignite Cache上以UUID为关键字运行简单聚合查询

输入操作代码

IgniteBinary binary = ignite.binary();
            IgniteCache<UUID, BinaryObject> rowCache = ignite.getOrCreateCache(CACHE_NAME).withKeepBinary();

            // put

            final int NUM_ROW = 100000;
            final int NUM_COL = 100;
            for (int i = 0; i < NUM_ROW; i++) {
                BinaryObjectBuilder builder = binary.builder(ROW);
                for (int j = 0; j < NUM_COL; j++) {
                    builder.setField("col" + j, Math.random(), Double.class);
                }
                BinaryObject obj = builder.build();
                rowCache.put(UUID.randomUUID(), obj);
            }

读取操作代码

IgniteCache<UUID, BinaryObject> cache = ignite.cache(CACHE_NAME).withKeepBinary();
final SqlFieldsQuery sqlFieldsQuery = new SqlFieldsQuery("SELECT COUNT(col1)" + cache.getName());
FieldsQueryCursor<List<?>> result = cache.query(sqlFieldsQuery);

错误

org.h2.jdbc.JdbcSQLException: Column "COL1" not found; SQL statement

修改

我已经在缓存配置中添加QueryEntity以使问题消失

 final QueryEntity queryEntity = new QueryEntity();
        queryEntity.setTableName(CACHE_NAME);
        queryEntity.setKeyFieldName("key");
        queryEntity.setKeyType(String.class.getName());
        queryEntity.setValueType(Row.class.getName());
        LinkedHashMap<String, String> fields = new LinkedHashMap<>();
        fields.put("key", String.class.getName());
        for (int i = 0; i < 55; i++) {
            fields.put("col" + i, Double.class.getName());
        }
        queryEntity.setFields(fields);
        return queryEntity;

但是,我不清楚QueryEntity的{​​{1}}和setValueType是如何做到的?我的值类型是任意二进制对象,具有任意键,值

我想通过setValueFieldName ...

宣布这些内容

我可以使用POJO使所有内容工作,但不能fields.put(<colName>, <colType>);作为值类型

我有什么问题吗?

1 个答案:

答案 0 :(得分:1)

new SqlFieldsQuery("SELECT COUNT(col1)" + cache.getName())

缓存名称是模式名称,类名(Row)是表名。看起来你的表名不正确。

另请确保ROW中的binary.builder(ROW)等于QueryEntity.valueType