【问题标题】:How to resolve "Failed to find SQL table for type" exception on Ignite SqlQuery?如何解决 Ignite SqlQuery 上的“找不到类型的 SQL 表”异常?
【发布时间】:2019-04-14 11:16:30
【问题描述】:

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

【问题讨论】:

    标签: sql ignite


    【解决方案1】:

    您没有在缓存配置中指定查询实体。它们可以使用CacheConfiguration#indexedTypes 属性进行配置。

    以下行应该修复您的示例:

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

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

    【讨论】:

    • 谢谢,丹尼斯。确实如此!
    猜你喜欢
    • 2013-03-07
    • 1970-01-01
    • 2013-07-08
    • 1970-01-01
    • 2016-06-08
    • 2010-09-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多