全部产品
云市场

快速开始

更新时间:2019-11-15 15:19:02

1. 开通 Search Index

Search index 功能只被支持在云 HBase 2.x, 依赖全文检索服务和 SQL 服务。开通此功能,主要包括以下三大步骤:

  1. 开通全文检索服务,如已开通请升级至最新版本(界面没有提示小版本升级,当前版本为最新版本)
  2. 开通SQL服务,如已开通请升级至最新版本(界面没有提示小版本升级,当前版本为最新版本)
  3. 在控制台参数配置中,配置参数phoenix.search.index.enabletrue, 并重启 SQL 服务。

以上升级皆为 server 端操作,客户端不需要升级。

可以按照以下流程图进行检查:

drawing

后续版本升级只需单独升级SQL服务和全文检索服务即可,但需要特别注意:在升级SQL服务前要先检查全文检索服务是否是最新版本,也就是要先升级全文检索服务,否则可能会带来兼容性问题

2. sqlline

开启交互式命令行,bin/sqlline-thin.py

  1. -- 创建数据表
  2. create table test (id varchar not null primary key,C1 varchar,C2 varchar, C3 integer)SALT_BUCKETS=2;
  3. -- 写入数据
  4. upsert into test values('a','word','Learn the definition of a phrase as a grammatical unit', 38000);
  5. upsert into test values('b', 'say hello', 'I confused what truth is', 3000);
  6. -- 创建同步索引
  7. create search index on test (C1, C2 {ANALYZER=standard});
  8. -- 索引查询 & 数据表条件过滤
  9. select id from test where search_query='C2:truth OR C2:phrase' and C3 = 3000;

3. JDBC API DEMO

  1. Connection conn = DriverManager.getConnection(url);
  2. String tableName = "test";
  3. Statement stmt = conn.createStatement();
  4. stmt.execute("create table " + tableName
  5. + "(id varchar not null primary key,"
  6. + "C1 varchar,"
  7. + "C2 varchar, "
  8. + "C3 integer )");
  9. for (int i = 0; i < 15; i++) {
  10. stmt.executeUpdate("upsert into " + tableName
  11. + String.format(" values('id_%d', 'c1_%d', 'c2_%d', %d)", i, i % 3, i % 3, i % 2));
  12. }
  13. conn.commit();
  14. //create search index async
  15. stmt.execute("CREATE SEARCH INDEX ON " + tableName + " (C1, C2) ASYNC SHARD_NUM=1,REPLICATION_NUM=1");
  16. stmt.execute("ALTER SEARCH INDEX ON " + tableName + " REBUILD");
  17. stmt.execute("ALTER SEARCH INDEX ON " + tableName + " COMMIT");
  18. ResultSet rs = stmt.executeQuery(
  19. "select * from " + tableName + " where SEARCH_QUERY='C2:c2_2' and c3 = 1");
  20. while (rs.next()) {
  21. // fetch data
  22. }
  23. rs.close();
  24. stmt.execute("DROP SEARCH INDEX ON " + tableName);
  25. stmt.execute("DROP TABLE " + tableName);
  26. stmt.close();
  27. conn.close();