可以使用自定义类来为我从KV商店中输入/获取数据。
也可以使用jdbc创建表中的INSERTING / SELECTING数据。这样我就可以获得名为SQL_PUBLIC_TABLENAME的缓存。
但是我找不到使用SQL查询从KV-store INSERT / SELECT数据的方法。我已经使用@QuerySqlField注释创建了自定义值类和定义的字段,如下所示:
@QuerySqlField(index = true)
public Integer id;
@QuerySqlField(index = true)
public String records_offset;
@QuerySqlField(index = true)
public Integer session_id;
然后我用这种方式使用xml-config定义了缓存:
<property name="cacheConfiguration">
<bean class="org.apache.ignite.configuration.CacheConfiguration">
<!-- Set a cache name. -->
<property name="name" value="test"/>
<property name="queryEntities">
<list>
<bean class="org.apache.ignite.cache.QueryEntity">
<property name="keyType" value="java.lang.Integer"/>
<property name="valueType" value="CDR"/>
<property name="tableName" value="CDR"/>
<property name="fields">
<map>
<entry key="id" value="java.lang.Long"/>
<entry key="records_offset" value="java.lang.String"/>
<entry key="session_id" value="java.lang.Integer"/>
</map>
</property>
</bean>
</list>
</property>
<!-- Set cache mode. -->
<property name="cacheMode" value="PARTITIONED"/>
</bean>
</property>
我有可以放入/获取数据的缓存,我也可以使用sqlline工具连接到Ignite,在那里我可以看到带有test
模式的CDR表(以及其他创建通过jdbc) :
0: jdbc:ignite:thin://127.0.0.1/> !tables
+--------------------------------+--------------------------------+--------------------------------+
| TABLE_CAT | TABLE_SCHEM | TABLE_NAME |
+--------------------------------+--------------------------------+--------------------------------+
| | PUBLIC | CITY |
| | test | CDR |
| | PUBLIC | PERSON |
| | PUBLIC | TEST2 |
| | PUBLIC | LOL |
| | PUBLIC | TEST |
+--------------------------------+--------------------------------+--------------------------------+
但我既不能读取数据也不能将数据放入CDR表中:
0: jdbc:ignite:thin://127.0.0.1/> DROP table CDR;
Error: Table doesn't exist: CDR (state=42000,code=0)
java.sql.SQLException: Table doesn't exist: CDR
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 * from CDR;
Error: Failed to parse query: select * from CDR (state=42000,code=0)
java.sql.SQLException: Failed to parse query: select * from CDR
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/> insert into CDR(ID, RECORDS_OFFSET, SESSION_ID) values (23, '12', 123);
Error: Failed to parse query: insert into CDR(ID, RECORDS_OFFSET, SESSION_ID) values (23, '12', 123) (state=42000,code=0)
java.sql.SQLException: Failed to parse query: insert into CDR(ID, RECORDS_OFFSET, SESSION_ID) values (23, '12', 123)
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/>
答案 0 :(得分:2)
您需要使用架构名称来访问此表:
select * from "test".CDR;
或
从&#34; test.CDR&#34;;
中选择*此外,如果这不会有帮助,请尝试使用大写设置CacheConfiguration.setSqlSchema,例如&#34; PUBLIC&#34;并使用此架构名称