在Ignite缓存上执行SQL查询时,出现异常“无法找到类型的SQL表”。等效的ScanQuery在相同的缓存上成功执行。
nb-从我的代码中注意到,我在启动Ignite之后创建了缓存。这是有意的,因为我希望能够动态创建缓存。
员工类别:
public class Employee implements Serializable {
@QuerySqlField (index = true)
private final Integer empNo;
@QuerySqlField
private String name;
@QuerySqlField
private Department dept;
@QuerySqlField
private Integer salary;
创建并填充员工缓存:
CacheConfiguration<Integer, Employee> empCacheCfg = new CacheConfiguration<>();
empCacheCfg.setName("Employee");
IgniteCache<Integer, Employee> empCache = ignite.getOrCreateCache(empCacheCfg);
empCache.put(0, new Employee(0, "Bill", deptCache.get("POT"), 20000));
empCache.put(1, new Employee(1, "Ben", deptCache.get("POT"), 21000));
empCache.put(2, new Employee(2, "Little Weed", deptCache.get("PLANT"), 15000));
empCache.put(3, new Employee(3, "The Gardner", deptCache.get("SVC"), 30000));
通过雇员缓存的SQLQuery:
SqlQuery sql = new SqlQuery("Employee", "salary > ?");
try (QueryCursor<Cache.Entry<Integer, Employee>> cursor2 =
empCache.query(sql.setArgs(20000)))
{
for(var e2 : cursor2)
{
System.out.println(String.format("Employee: %s", e2.getValue().getName()));
}
}
catch(Exception e)
{
String exmsg = e.getMessage();
System.out.println(exmsg);
}
答案 0 :(得分:2)
您没有在缓存配置中指定查询实体。可以使用CacheConfiguration#indexedTypes属性对其进行配置。
以下行应解决您的示例:
empCacheCfg.setIndexedTypes(Integer.class, Employee.class);
文档:https://apacheignite.readme.io/docs/cache-queries#section-query-configuration-by-annotations