handlersocket使用 第四章 Getting data

四.Getting data

英文原文如下

Getting data

 

The'find' request has the following syntax.

 

    <indexid> <op> <vlen><v1> ... <vn> [LIM] [IN] [FILTER ...]

 

LIMis a sequence of the following parameters.

 

    <limit> <offset>

 

INis a sequence of the following parameters.

   

    @ <icol> <ivlen> <iv1>... <ivn>

 

FILETERis a sequence of the following parameters.

 

    <ftyp> <fop> <fcol><fval>

 

-<indexid> is a number. This number must be an <indexid> specifiedby a

  'open_index' request executed previously onthe same connection.

-<op> specifies the comparison operation to use. The current version of

  HandlerSocket supports '=', '>', '>=','<', and '<='.

-<vlen> indicates the length of the trailing parameters <v1> ... <vn>. This

  must be smaller than or equal to the numberof index columns specified by

  the <indexname> parameter of thecorresponding 'open_index' request.

-<v1> ... <vn> specify the index column values to fetch.

-LIM is optional. <limit> and <offset> are numbers. When omitted, itworks

  as if 1 and 0 are specified. These parameterworks like LIMIT of SQL.

  These values don't include the number ofrecords skipped by a filter.

-IN is optional. It works like WHERE ... IN syntax ofSQL. <icol> must be

  smaller than the number of index columnsspecified by the <indexname>

  parameter of the corresponding 'open_index'request. If IN is specified in

  a find request, the <icol>-th parametervalue of <v1> ...  <vn> is ignored.

-FILTERs are optional. A FILTER specifies a filter. <ftyp> is either 'F'

  (filter) or 'W' (while). <fop>specifies the comparison operation to use.

  <fcol> must be smaller than the numberof columns specified by the

  <fcolumns> parameter of thecorresponding 'open_index' request. Multiple

  filters can be specified, and work as thelogical AND of them. The

  difference of 'F' and 'W' is that, when arecord does not meet the

  specified condition, 'F' simply skips therecord, and 'W' stops the loop.

 

‘find’请求有以下参数:

     <indexid> <op> <vlen><v1> ... <vn> [LIM] [IN] [FILTER ...]

 

‘LIM’是以下参数的一个序列

      <limit> <offset>

 

‘IN’是一项参数的一个序列

      @ <icol> <ivlen> <iv1>... <ivn>

 

‘FILETER’是以下参数的一个序列

      <ftyp> <fop> <fcol><fval>

 

-<indexid>是一个数字。这个数字必须是在同一个连接中先前执行的‘open_index’请求中的indexid是同一个数字。

 

-<op>表示要使用的操作符。在目前的handlersocket版本中支持‘=’,‘>’,‘>=’,‘<’,‘<=’。

 

-<vlen>说明了连续参数<v1> ... <vn>的个数。这个数字必须不大于那个在其相对于的‘open_index’请求中指定的参数<indexname>的索引的列数。

-<v1>... <vn> 是索引的列的取值。

 

-<LIM>是可选参数。<limit>和<offset>都是数字。如果两个参数被忽略,将按其值指定为1和0(即1和0是这两个参数的默认值)。这两个参数的作用和SQL中的LIMIT是相似的。//这些值不包括被filter忽略的记录的个数。

 

-IN是可选的。它的作用和SQL语句中的WHERE....IN相似。<icol>必须小于那个在其相对于的‘open_index’中的索引的列的数量。如果在一个find请求中使用了IN参数,那么在<v1> ...  <vn>中第<icol>个参数将被忽略。

 

-FILTERs是可选参数。一个FILTER指定了一个过滤条件。<ftyp>只能是‘F’(filter)或‘W’(while)。<fop>指定了所使用的比较操作符。<fcol>必须小于其所对应的‘open_index’请求中参数<fcolumns>的列的数量。可以指定多个过滤条件,它们以and的逻辑进行工作。‘F’和‘W’的不同在于,如果一条记录没有符合指定的条件,‘F’就跳过这个记录,但是‘W’将终止这个循环。

 

 

Responsefor 'find'

 

If'find' is succeeded, HandlerSocket returns a line of the following

syntax.

 

   0 <numcolumns> <r1> ...<rn>

 

-<numcolumns> always equals to the length of <columns> of thecorresponding

  'open_index' request.

-<r1> ... <rn> is the result set. If N rows are found, the length of<r1>

  ... <rn> becomes ( <numcolumns> *N ).

 

'find'请求的返回:

如果'find'请求成功发送,HandlerSocket 将会返回以下形式:

  0 <numcolumns> <r1> ...<rn>

 

-<numcolumns>总是等于那个在其相对于的‘open_index’请求中指定的参数<columns>的列数。

 

-<r1> ... <rn> 是返回的结果。如果有N行被找到,这个返回的的长度将变为<numcolumns> * N

 

 

主要所使用的成员函数的原型:

virtual void request_buf_exec_generic(size_t pst_id, conststring_ref& op,

    const string_ref *kvs,size_t kvslen, uint32_t limit, uint32_t skip,

    const string_ref&mod_op, const string_ref *mvs, size_t mvslen,

    const hstcpcli_filter*fils = 0, size_t filslen = 0,

    int invalues_keypart = -1,const string_ref *invalues = 0,

size_t invalueslen =0) = 0;

 

下面举几个例子详细说明:

 

1.找到索引等于某一组特定值的查找

  vector<string_ref>vec;

   ......

  const stringkTestEqualOp("=");

  const string_refkTestEqualOpRef(kTestEqualOp.data(), kTestEqualOp.size());

  cli->request_buf_exec_generic(indexid,kTestEqualOpRef, &vec[0], vec_length, limit, offset, 0, 0, 0);

 

a.如果索引的列为(col2,col3),vec只为赋了一个值,则第二个值将被忽略,结果为(col2,?)的limit行,并且按第二个值排序(升序)。

若索引为多列,则根据上述类推即可,即为(col2,col3....,,?,?,?)。

 

2. Where.......in的用法

 cli->request_buf_exec_generic(indexid, kTestEqualOpRef, &vec[0],vec_length, limit ,offset, 0, 0, 0, 0, 0, icol, &vec_in[0], vec_in_length);

其中vec[icol]的值将被忽略,其所取值在vec_in中

注意:使用这个用法是,对于vec_in中的每个值,只能找到第一个结果。

 

3可选参数FILTERs 的用法

首先在’open_index’请求中要指定<fcolumns>的参数,如:

cli->request_buf_open_index(indexid,"test","test1", "index1", "col1,col2,col3,col4","col5,col6");

中的"col5,col6"

在根据索引寻找行的时候,可以另外根据col5和col6指定额外的匹配条件。

 

FILETER的结构

struct hstcpcli_filter {

  string_ref filter_type;        ///<ftyp>

  string_ref op;               ///<fop>

  size_t ff_offset;             /<fcol>

  string_ref val;              //<fval>

  hstcpcli_filter() :ff_offset(0) { }

};

op可以为比较操作符

 

举个例子说明:

vector<hstcpcli_filter>vec_filter;

 hstcpcli_filter filter;

     stringkey_F("F");

     filter.filter_type =string_ref(key_F.data(), key_F.size());

     string key_op("<=");

     filter.op =string_ref(key_op.data(), key_op.size());

     uid = 600;

     snprintf(key_buf, 32,"%u", uid);

     string key_val(key_buf);

     filter.val =string_ref(key_val.data(), key_val.size());

     filter.ff_offset = 0;

vec_filter.push_back(filter);

.....

cli->request_buf_exec_generic(indexid, kTestEqualOpRef,&vec[0], vec_length, limit, offset, 0, 0, 0, &vec_filter[0],vec_filter_length, -1, 0, 0);

 

注意情况看前文中的翻译。

 

 

注意:

astring_ref的值是string的引用,若在string_ref构造后修改string,仍然会再次修改string_ref

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值