Search code examples
javadistributed-computingignitegridgain

Apache Ignite SqlFieldQuery on top of cache storing BinaryObject


I cannot seem to get this to work, and have scoured the net for documentation or examples to no avail

Goal

To run a simple aggregation query on an Ignite Cache backed by BinaryObject values with UUID as the key

Put Operation Code

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);
            }
          

Read Operation Code

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);

Error

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

EDIT

I've since added a QueryEntity to the cache configuration to make the problem disappear

 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;

However, it is unclear to me how QueryEntity's setValueType and setValueFieldName does? My value type is an arbitrary Binary object with arbitrary key, values

I would like to declare these via fields.put(<colName>, <colType>); ...

I am able to get everything to work using POJOs, but not BinaryObject as the value type

Is there anything I am doing wrong?


Solution

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

    Cache name is a schema name, and class name (Row) is a table name. Looks like you have incorrect table name.

    Also make sure that ROW in binary.builder(ROW) equals to QueryEntity.valueType.