I have configured a Datagrid Cache in apache ignite. the query fields are configured using CacheTypeMetada
.
But I cannot retrieve the values from the Cache using sql.
If I change the query fields configured to @QueryIndexType (index = true)
The query returns result.
My question is, is there any config I am missing to do sql query lookup into Cache configured using CacheTypeMetadata ?
Thankyou.
Providing my code snippet.
CacheConfiguration<TestKey, Test> testCacheCfg = new CacheConfiguration<>(TEST_CACHE);
The query firlds are configured using CacheTypeMetadata.
private static Collection<CacheTypeMetadata> testCacheMetadata(){
Collection<CacheTypeMetadata> types = new ArrayList<>();
CacheTypeMetadata type = new CacheTypeMetadata();
type.setKeyType(TestKey.class.getName());
type.setValueType(Test.class.getName());
Map<String, Class<?>> qryFlds = type.getQueryFields();
qryFlds.put("testId", int.class);
qryFlds.put("orgId", String.class);
qryFlds.put("md5", String.class);
Map<String, Class<?>> ascFlds = type.getAscendingFields();
ascFlds.put("testId", int.class);
ascFlds.put("orgId", String.class);
types.add(type);
return types;
}
Query called :
private static void sqlQuery(Ignite ignite, TestKey testKey) {
IgniteCache<TestKey, Test> cache = Ignition.ignite().cache(TEST_CACHE);
// SQL clause
String sql = "where testId = ? and orgId = ?";
// Execute query
System.out.println("query result" +
cache.query(new SqlQuery<TestKey, Test>(Test.class, sql).
setArgs(testKey.getTestId(), testKey.getOrgId())).getAll());
}
Your example works fine for me. Can you take a look at my code and see if there is any difference from yours (see link below)?
https://github.com/vkulichenko/ignite-tests/blob/master/src/main/java/org/vk/ignite/query/metadata1/Main.java
What version are you on?