无法使用 SQL 工具查询现有的 Ignite 缓存

Cannot query existing Ignite cache using SQL tooling

我正在尝试查询我通过 Java 脚本创建的 Apache Ignite 缓存(版本 2.2):

    TcpDiscoverySpi spi = new TcpDiscoverySpi();
    TcpDiscoveryVmIpFinder ipFinder=new TcpDiscoveryMulticastIpFinder();
    List<String> adresses=new ArrayList<String>();
    adresses.add("127.0.0.1:48500..48520");
    ipFinder.setAddresses(adresses);
    spi.setIpFinder(ipFinder);

    IgniteConfiguration cfg=new IgniteConfiguration().setDiscoverySpi(spi).setClientMode(true);

    CacheConfiguration cache_conf=new CacheConfiguration<String,Custom_Class>().setCacheMode(CacheMode.PARTITIONED).setAtomicityMode(CacheAtomicityMode.ATOMIC).setBackups(1).
            setIndexedTypes(String.class,Custom_Class.class).setName("Spark_Ignite");

    Ignite ignite=Ignition.getOrStart(cfg);

    ignite.getOrCreateCache(cache_conf);

    System.out.println("[INFO] CACHE CREATED");
    ignite.close();

我正在使用 DBeaver 对此缓存执行简单的 SQL 查询。

问题是,当我尝试进行查询时,出现此错误:

SELECT * FROM Custom_Class;

 Table "Custom_Class" not found; SQL statement:SELECT * FROM Custom_Class

如果我 运行 这个查询也一样:

SELECT * FROM Spark_Ignite;

 Table "Spark_Ignite" not found; SQL statement:SELECT * FROM Spark_Ignite

但是,如果我按照这里提到的说明进行操作:https://apacheignite-sql.readme.io/docs/sql-tooling,我得到的查询结果没有问题。

我运行ignitevisor.sh,果然缓存都在,而且都有记录:

这里可能有什么问题?

谢谢。

更新

使用答案中提到的引号我可以查询 table,但它没有显示任何记录,而 ignitevisor 显示 63。 这是我用于 class:

的脚本
public class Custom_Class implements Serializable {
@QuerySqlField(index = true)
private String a;

@QuerySqlField(index = true)
private String b;

@QuerySqlField(index = true)
private String c;

@QuerySqlField(index = true)
private String d;

@QuerySqlField(index = true)
private String e;

@QuerySqlField(index = true)
private String f;

@QuerySqlField(index = true)
private String g;

@QuerySqlField(index = true)
private String h;
}

为了能够将缓存与 SQL 一起使用,它需要是:

  • 使用 CREATE TABLE DML 创建。在这种情况下,模式是 PUBLIC,这通常是默认值。
  • 在其 cacheConfiguration 中指定 indexedTypes,并附上这些类型的注释。在这种情况下,模式是 "cacheName",引号很重要,table 名称是 VALUETYPEINCAPS。如果键是原始类型,它的字段名称是 _key,如果值是原始类型,它将是 _val,它们被排除在 *.
  • 之外
  • 在其 cacheConfiguration 中指定 queryEntities。在这种情况下,您可以为基本类型指定 table 名称和列名称,但架构是 "cacheName".

如果在没有 SQL 支持的情况下创建缓存,则只能通过销毁和重新创建缓存来添加它。

我可以看到你的缓存有索引类型。现在,怎么样:

INSERT INTO "Spark_Ignite".CUSTOM_CLASS(_key, id) VALUES ('foo', 1);
SELECT _key, * FROM "Spark_Ignite".CUSTOM_CLASS;

您也可以尝试在 Apache Ignite 附带的 sqlline 工具中调用 !tables。

您应该将 CacheConfiguration#sqlSchema 属性 设置为 PUBLIC,或者使用带引号的缓存名称作为 DBeaver 中的架构名称。

有关详细信息,请参阅文档中的以下页面:https://apacheignite-sql.readme.io/docs/schema-and-indexes