5.1.4. 映射表汇聚

1. 汇聚优势

汇聚存储可以解决搜索的内容不知道在表的哪个字段中,可以做到全表匹配。再结合分词数据类型即可做到全文检索的特性。

2. 汇聚原理

将表中已有的字段中的数据汇聚到一个新的字段中进行存储的机制,用以解决数据搜索过程中不知道位置的问题的方法叫做汇聚存储。

自定义汇聚表示用户可以自行定义汇聚列,包括汇聚列名字、需要汇聚的字段和是否汇聚字段的字段名。

3. 汇聚使用

(1) 创建带有汇聚功能的映射表

汇聚例子如下:

create mapping macpf1(
cs1 y_string_id,
sc1 y_string_id,
cwc4_1 y_wildcard4_ism,
copy_string1 y_string_idm physical@copy_string1_y_string_idm,
copy_string2 y_string_idm physical@copy_string2_y_string_idm,
copy_range y_string_idm physical@copy_range_y_string_idm,
copy_txt y_wildcard4_ism physical@copy_txt_y_wildcard4_ism,
copy_all y_wildcard4_ism  physical@copy_all_y_wildcard4_ism
)
tableproperties  
(
mapping_physical_table='mp_ph',/*映射到哪张表里去*/
/*汇聚1:汇聚字段名称包含cs的数据(***\*cs1\****),withfield@true表示含有原始字段的名称*/
copyfield='indexof@cs dest@copy_string1 withfield@true',
/*汇聚2:汇聚字段名称包含cs的字段的数据(***\*cs1\****),不含原始字段的名称*/
copyfield='indexof@cs dest@copy_string2',
/*汇聚3:汇聚字段’sc1’中的数据(***\*copy_string1在汇聚1中已做汇聚,可以继续对其添加汇聚数据,不会对之前的内容造成覆盖\****),withfield@true表示含有原始字段的名称*/
copyfield='equals@sc1 dest@copy_string1 withfield@true',
/*汇聚4:汇聚’cwc4_1’中的数据,不含原始字段的名称*/
copyfield='equals@cwc4_1 dest@copy_txt',
/*汇聚5:汇聚***\*所有字段\****中的数据,withfield@true表示含有原始字段的名称*/
copyfield='indexof@all  dest@copy_all  withfield@true',
/*汇聚6:汇聚第2~3个字段中的数据(***\*sc1、cwc4_1\****),withfield@true表示含有原始字段的名称*/
copyfield='rangeof@1~2 dest@copy_range withfield@true'
);

注:

  • cs*、sc*、cwc4*:代表原始字段。
  • copy_*:代表要发往目标汇聚字段。
  • copyfield:代表字段数据汇聚关键字。
  • withfield@:true代表汇聚字段含有原始的字段名称,该关键字不声明则代表汇聚字段不含原始字段名称。
  • indexof@:可以使用all关键字匹配所有字段,也可以用字段模糊匹配,比如:cs,匹配含有cs字符的字段。
  • dest@:代表汇聚的数据发往哪个目标字段中的关键字。
  • equals@:代表需要进行汇聚的明确的字段名称的关键字。

图5.1.4.1 创建带有汇聚功能的映射表详情

(2) 导入数据

1) 原始数据(路径:/wyh/mpcpf.log):

图11 原始数据图

2) 向映射表中导入数据的方法与物理表中导入数据的方法完全一样。示例如下:

./load.sh -t mpcpf1 -tp txt -local -f /wyh/mpcpf.log -sp , -fl cs1,sc1,cwc4_1

3) 导入数据后对映射表、物理表做全表查询:

图12 映射表全表查询

注:创建表时进行汇聚时未声明withfield@true的汇聚内容,在查询时只展示字段值,如["zs"]的形式,若声明withfield@true关键字,展示形式为原始字段名称@字段值,如["cs1@zs"]的形式。

图13 物理表查询

(3) 查询方法

1) 查看每张表的数据量(对物理表做查询):

 select count(*) from mp_ph;

 select mapping_name,count(*) from mp_ph group by mapping_name;

图14 查询数据量用法图

2) 指定字段查询(显示指定及系统自动指定):

select cs1,sc1,cwc4_1 from mpcpf1;

select v_2_y_string_id,v_1_y_string_id,v_1_y_wildcard4_ism from mp_ph where mapping_name=’mpcpf1’;

图15 指定字段查询(普通字段)

select copy_string1,copy_string2,copy_range,copy_txt,copy_all from mpcpf1;

select copy_string1 y_string_idm,
copy_string2 y_string_idm,
copy_range y_string_idm,
copy_txt y_wildcard4_ism,
copy_all y_wildcard4_ism
from mp_ph where mapping_name=’mpcpf1’;

图16 指定字段查询(汇聚字段)

3) 汇聚字段查询(对映射表做查询,解决待查询的数据不知道属于哪个字段的问题):

select * from mpcpf1;
select * from mpcpf1 where copy_all = ‘早餐’;

图17 汇聚字段映射表模糊查询

select * from mpcpf1;

select * from v_2_y_string_id,
v_1_y_string_id,
v_1_y_swildcard4_ism,
copy_string1_y_string_idm,
copy_string2_y_string_idm,
copy_range_y_string_idm,
copy_txt_y_swildcard4_ism,
copy_all_y_swildcard4_ism 
from mp_ph where mapping_name=’mpcpf1’ 
and copy_all_y_swildcard4_ism=’早餐’;

图18 汇聚字段物理表模糊查询

Copyright © lucene.xin 2020 all right reserved修改时间: 2021-07-06 15:11:31

results matching ""

    No results matching ""