如何解决 Ignite SqlQuery 上的"Failed to find SQL table for type"异常?



在 Ignite 缓存上执行 SQL 查询时出现异常"找不到类型的 SQL 表"。 等效的扫描查询在同一缓存上成功执行。

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 over Employee cache:

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

未在缓存配置中指定查询实体。可以使用 CacheConfiguration#indexedType 属性来配置它们。

以下行应修复您的示例:

empCacheCfg.setIndexedTypes(Integer.class, Employee.class);

文档:https://apacheignite.readme.io/docs/cache-queries#section-query-configuration-by-annotations

最新更新