ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

【TcaplusDB知识库】RESTfulAPI. for Generic表-[PB] IndexQuery.介绍

2022-02-16 10:31:08  阅读:164  来源: 互联网

标签:IndexQuery RESTfulAPI Generic tcaplus 查询 table where id select


【TcaplusDB知识库】RESTfulAPI2.0 for Generic表-[PB] IndexQuery2.0介绍

简介

通过全局索引查询记录,支持SQL语法如附录。使用此接口需要提前在腾讯云控制台或本地Docker版的Web平台针对表添加全局索引字段。

POST http://{Tcaplus_REST_URL}

请求语法

Http请求

#腾讯云控制台 RESTful Endpoint, ip:80, 端口默认80
http://172.17.0.22
#TcaplusDB本地docker版 RESTful Endpoint, ip:31001, 端口默认31001
http://9.135.8.93:31001

Http头

名称是否必填限制条件说明
x-tcaplus-target Tcaplus.IndexQuery
x-tcaplus-version Tcaplus3.50.0
x-tcaplus-app-id 对应业务id编号(aka,集群接入id)
x-tcaplus-zone-id 对应zone编号(aka,表格组id)
x-tcaplus-protocol-version 对应protocol版本号,默认2.0
x-tcaplus-table-name 对应表名
x-tcaplus-pwd-md5 业务密码(aka,集群访问密码),传入计算后的md5值
x-tcaplus-idl-type protobuf
x-tcaplus-result-flag 0:操作成功后不返回数据1:操作成功后返回和请求一致的数据2:操作成功后返回本次update操作后的数据3:操作成功后返回tcapsvr端操作前的数据
x-tcaplus-data-version-check   1:检测记录版本号,只有当该版本号与服务器端的版本号相同时,该版本号才会自增2:不检测记录版本号,强制把客户端的记录版本号写入到服务器中3:不检测记录版本号,将服务器端的版本号自增
x-tcaplus-data-version   具体的version值

 

示例:

x-tcaplus-target:Tcaplus.IndexQuery
x-tcaplus-app-id:3
x-tcaplus-zone-id:1
x-tcaplus-protocol-version:2.0
x-tcaplus-table-name:game_players
x-tcaplus-pwd-md5:4e81984efccfb4982333aeb1ff7968d5
x-tcaplus-result-flag:2
x-tcaplus-version:Tcaplus3.50.0
x-tcaplus-data-version-check: 3
x-tcaplus-idl-type:protobuf

Data

使用json格式表示记录相关信息。参数信息:

  • Query: 必须,指定查询的SQL语句。

示例:以game_server_id索引字段作为 查询条件

#示例1,
{
  "Query": "select player_id, player_name,player_email, game_server_id, pay.amount from game_players where game_server_id>0 limit 1 offset 0"
}

完整请求示例

curl -i -XPOST -H 'x-tcaplus-target: Tcaplus.IndexQuery' -H 'x-tcaplus-app-id: 70' -H 'x-tcaplus-zone-id: 1' -H 'x-tcaplus-protocol-version: 2.0' -H 'x-tcaplus-table-name: game_players' -H 'x-tcaplus-pwd-md5: 0972ad76decf4d11a69e2e0d9af335da' -H 'x-tcaplus-result-flag: 2' -H 'x-tcaplus-version: Tcaplus3.50.0' -H 'x-tcaplus-data-version-check: 1' -H 'x-tcaplus-idl-type: protobuf' http://172.17.32.17 -d '{
  "Query": "select player_id, player_name,player_email, game_server_id, pay.amount from game_players where game_server_id>0 limit 1 offset 0"
}'

返回语法

返回参数说明

参数名说明
ErrorCode 返回码
ErrorMsg 返回信息
MultiRecords 返回的记录集合
Record 返回的记录数据,根据SQL中查询的字段返回
TotalNum 返回匹配的记录条数

 

返回示例

成功返回示例

{
  "ErrorCode": 0,
  "ErrorMsg": "Succeed",
  "MultiRecords": [{
      "RecordVersion": 1,
      "Record": {
          "game_server_id": 55,
          "pay": {
              "amount": 55
          },
          "player_email": "55",
          "player_id": 5,
          "player_name": "5"
      }
  }],
  "TotalNum": 1
}

失败返回示例

{"ErrorCode":-13841,"ErrorMsg":"proxy_err_query_index_field_not_exist"}

错误码

参考 [PB]常见错误码

支持的SQL语法

条件查询

支持 =, >, >=, <, <=, !=, between, in, not in, like, not like, and, or , 比如:

select * from table where a > 100 and b < 1000;

select * from table where a between 1 and 100 and b < 1000;

select * from table where str like "test";

select * from table where a > 100 or b < 1000;

注意:between 查询时,between a and b,对应的查询范围为[a, b],比如 between 1 and 100, 是会包含 1 和 100 这两个值的,即查询范围为[1,100]。

注意:like 查询是支持模糊匹配,其中"%"通配符,匹配 0 个或者多个字符; “_”通配符,匹配 1 个字符。

分页查询

支持 limit offset 分页查询。 比如:

select * from table whre a > 100 limit 100 offset 0;

注意:当前 limit 必须与 offset 搭配使用,即不支持 limit 1 或者 limit 0,1 这种。

聚合查询

当前支持的聚合查询包括:sum, count, max, min, avg,比如:

select sum(a), count(*), max(a), min(a), avg(a) from table where a > 1000;

注意:聚合查询不支持 limit offset,即 limit offset 不生效;

注意:目前只有 count 支持 distinct,即 select count(distinct(a)) from table where a > 1000; 其他情况均不支持 distinct。

部分字段查询

select a, b from table where a > 1000;

对于 pb 表,还支持查询嵌套字段的值,用点分方式,类似:

select field1.field2.field3, a, b from table where a > 1000;

不支持的 SQL语法

不支持聚合查询与非聚合查询混用

select *, a, b from table where a > 1000;

select sum(a), a, b from table where a > 1000;

select count(*), * from table where a > 1000;

有限支持Order by查询

select * from table where a > 1000 order by a;

不支持group by查询

select * from table where a > 1000 group by a;

不支持having查询

select sum(a) from table where  a > 1000 group by a having sum(a) > 10000;

不支持多表联合查询

select * from table1 where table1.a > 1000 and table1.a = table2.b;

不支持嵌套的SELECT查询

select * from table where a > 1000 and b in (select b from table where b < 5000);

不支持别名

select sum(a) as sum_a from table where a > 1000;

其它不支持的查询

  • 不支持 join 查询;

  • 不支持 union 查询;

  • 不支持类似 select a+b from table where a > 1000 的查询;

  • 不支持类似 select * from table where a+b > 1000 的查询;

  • 不支持类似 select * from table where a >= b 的查询;

  • 不支持其他未提到的查询。


 

img

TcaplusDB是腾讯出品的分布式NoSQL数据库,存储和调度的代码完全自研。具备缓存+落地融合架构、PB级存储、毫秒级时延、无损水平扩展和复杂数据结构等特性。同时具备丰富的生态、便捷的迁移、极低的运维成本和五个九高可用等特点。客户覆盖游戏、互联网、政务、金融、制造和物联网等领域。

标签:IndexQuery,RESTfulAPI,Generic,tcaplus,查询,table,where,id,select
来源: https://www.cnblogs.com/TcaplusDBers/p/15899348.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有