【问题标题】:Apache Ignite - querying a cache through an sql driverApache Ignite - 通过 sql 驱动程序查询缓存
【发布时间】:2018-07-21 07:02:12
【问题描述】:

我在 Ignite 中创建了一个缓存,现在我尝试通过 ignite 包中提供的 sqlline 查询它。在文档中,它只讨论了创建表、索引、查询这些表等。但没有涉及以这种方式查询通过ignite.getOrCreateCache() 创建的缓存。鉴于 ignite 功能如此丰富,我认为这是可能的。

我错过了什么?

注意事项:

  • 点燃版本 = 2.3.0
  • 通过 ignite Sql 机制的 SqlFieldsQuery 在我的代码中运行良好。
  • 这看起来与this issue 非常相似,但我的发行版只有一个 h2 jar,h2-1.4.196.jar,虽然我使用的是 spring-boot

创建缓存的java代码

cacheConfig.setName("eventCache");
cacheConfig.setTypes(TenantKey.class, EventCachePojo.class);
cacheConfig.setIndexedTypes(TenantKey.class, EventCachePojo.class);
Cache<String, EventCachePojo> cache = ignite.getOrCreateCache(cacheConfig);

然后运行sqlline

# i tried jdbcUrl jdbc:ignite:thin://127.0.0.1/ and jdbc:ignite:thin://127.0.0.1/eventCache
$ ./sqlline.sh --color=true --verbose=true -u jdbc:ignite:thin://127.0.0.1/
issuing: !connect jdbc:ignite:thin://127.0.0.1/ '' '' org.apache.ignite.IgniteJdbcThinDriver
Connecting to jdbc:ignite:thin://127.0.0.1/
Connected to: Apache Ignite (version 2.3.0#20171028-sha1:8add7fd5)
Driver: Apache Ignite Thin JDBC Driver (version 2.3.0#20171028-sha1:8add7fd5)
Autocommit status: true
Transaction isolation: TRANSACTION_REPEATABLE_READ
sqlline version 1.3.0
0: jdbc:ignite:thin://127.0.0.1/> !tables
+--------------------------------+--------------------------------+--------------------------------+--------------------------------+-----------------------------+
|           TABLE_CAT            |          TABLE_SCHEM           |           TABLE_NAME           |           TABLE_TYPE           |            REMARKS          |
+--------------------------------+--------------------------------+--------------------------------+--------------------------------+-----------------------------+
|                                | eventCache                     | EVENTCACHEPOJO                 | TABLE                          |                             |
|                                | eventCache                     | EVENTCACHEPOJO                 | TABLE                          |                             |
+--------------------------------+--------------------------------+--------------------------------+--------------------------------+-----------------------------+
0: jdbc:ignite:thin://127.0.0.1/> select count(*) from eventCache.EVENTCACHEPOJO;
Error: Failed to parse query: select count(*) from eventCache.EVENTCACHEPOJO (state=42000,code=0)
java.sql.SQLException: Failed to parse query: select count(*) from eventCache.EVENTCACHEPOJO
    at org.apache.ignite.internal.jdbc.thin.JdbcThinConnection.sendRequest(JdbcThinConnection.java:671)
    at org.apache.ignite.internal.jdbc.thin.JdbcThinStatement.execute0(JdbcThinStatement.java:130)
    at org.apache.ignite.internal.jdbc.thin.JdbcThinStatement.execute(JdbcThinStatement.java:299)
    at sqlline.Commands.execute(Commands.java:823)
    at sqlline.Commands.sql(Commands.java:733)
    at sqlline.SqlLine.dispatch(SqlLine.java:795)
    at sqlline.SqlLine.begin(SqlLine.java:668)
    at sqlline.SqlLine.start(SqlLine.java:373)
    at sqlline.SqlLine.main(SqlLine.java:265)
0: jdbc:ignite:thin://127.0.0.1/> select count(*) from eventCache.EVENTCACHEPOJO;
Error: Failed to parse query: select count(*) from eventCache.EVENTCACHEPOJO (state=42000,code=0)
java.sql.SQLException: Failed to parse query: select count(*) from eventCache.EVENTCACHEPOJO
    at org.apache.ignite.internal.jdbc.thin.JdbcThinConnection.sendRequest(JdbcThinConnection.java:671)
    at org.apache.ignite.internal.jdbc.thin.JdbcThinStatement.execute0(JdbcThinStatement.java:130)
    at org.apache.ignite.internal.jdbc.thin.JdbcThinStatement.execute(JdbcThinStatement.java:299)
    at sqlline.Commands.execute(Commands.java:823)
    at sqlline.Commands.sql(Commands.java:733)
    at sqlline.SqlLine.dispatch(SqlLine.java:795)
    at sqlline.SqlLine.begin(SqlLine.java:668)
    at sqlline.SqlLine.start(SqlLine.java:373)
    at sqlline.SqlLine.main(SqlLine.java:265)

0: jdbc:ignite:thin://127.0.0.1/> select count(*) from EVENTCACHEPOJO;
Error: Failed to parse query: select count(*) from EVENTCACHEPOJO (state=42000,code=0)
java.sql.SQLException: Failed to parse query: select count(*) from EVENTCACHEPOJO
    at org.apache.ignite.internal.jdbc.thin.JdbcThinConnection.sendRequest(JdbcThinConnection.java:671)
    at org.apache.ignite.internal.jdbc.thin.JdbcThinStatement.execute0(JdbcThinStatement.java:130)
    at org.apache.ignite.internal.jdbc.thin.JdbcThinStatement.execute(JdbcThinStatement.java:299)
    at sqlline.Commands.execute(Commands.java:823)
    at sqlline.Commands.sql(Commands.java:733)
    at sqlline.SqlLine.dispatch(SqlLine.java:795)
    at sqlline.SqlLine.begin(SqlLine.java:668)
    at sqlline.SqlLine.start(SqlLine.java:373)
    at sqlline.SqlLine.main(SqlLine.java:265)

【问题讨论】:

    标签: ignite


    【解决方案1】:

    我终于明白了。 This Post 引导我找到答案。每个 h2 db 都需要引用 schemaName 和 table。

    语法如下:

    $ ./sqlline.sh --color=true --verbose=true -u jdbc:ignite:thin://127.0.0.1/
    issuing: !connect jdbc:ignite:thin://127.0.0.1/ '' '' org.apache.ignite.IgniteJdbcThinDriver
    Connecting to jdbc:ignite:thin://127.0.0.1/
    Connected to: Apache Ignite (version 2.3.0#20171028-sha1:8add7fd5)
    Driver: Apache Ignite Thin JDBC Driver (version 2.3.0#20171028-sha1:8add7fd5)
    Autocommit status: true
    Transaction isolation: TRANSACTION_REPEATABLE_READ
    sqlline version 1.3.0
    0: jdbc:ignite:thin://127.0.0.1/> !tables
    +--------------------------------+--------------------------------+--------------------------------+--------------------------------+--------------------------------+---------+
    |           TABLE_CAT            |          TABLE_SCHEM           |           TABLE_NAME           |           TABLE_TYPE           |            REMARKS             |         |
    +--------------------------------+--------------------------------+--------------------------------+--------------------------------+--------------------------------+---------+
    |                                | eventCache                     | EVENTCACHEPOJO                 | TABLE                          |                                |         |
    |                                | eventCache                     | EVENTCACHEPOJO                 | TABLE                          |                                |         |
    +--------------------------------+--------------------------------+--------------------------------+--------------------------------+--------------------------------+---------+
    0: jdbc:ignite:thin://127.0.0.1/> select count(*) from "eventCache"."EVENTCACHEPOJO";
    +--------------------------------+
    |            COUNT(*)            |
    +--------------------------------+
    | 2619705                        |
    +--------------------------------+
    

    【讨论】:

      【解决方案2】:

      以下是连接到 Ignite 中特定架构的几个选项:

      1. jdbc:ignite:thin://172.16.0.5/mySchema - 将连接到“MYSCHEMA”(不区分大小写)
      2. jdbc:ignite:thin://172.16.0.5/"mySchema" - 将连接到“mySchema”(区分大小写)

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2023-01-22
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-01-05
        • 2020-08-16
        相关资源
        最近更新 更多