4.7. 基本查询

4.7.1 数据查询

1. 数据预览

select * from common_example001 where partition like 'teststream' limit 10;

图 4.7.1.1数据预览

注:因f1字段在建表时只索引未存储,故该字段预览结果为null。

select s1,s2,i1,l1 from common_example001 where partition like 'teststream' limit 10;

图 4.7.1.2数据预览

2. 过滤

select * from common_example001 where partition like 'teststream' and s1='zs' limit 10;

图 4.7.1.3过滤

select s1,i1,l1 from common_example001 where partition like 'teststream' and s1='ls    ' and i1='61' limit 10;

图 4.7.1.4过滤

3. 条件嵌套

select s1,i1,l1 from common_example001 where partition like 'teststream' and s1='ww' and i1='62' and (ti1>'61' and ti1<='63') limit 10;

图 4.7.1.5条件嵌套

4. between and(闭区间)

select s1,i1,l1,ti1 from common_example001 where partition like 'teststream' and ti1 between 61 and 63 limit 10;

图 4.7.1.6闭区间

5. 字符前缀匹配

select s1,i1,l1 from common_example001 where partition like 'teststream' and s1='z*'  limit 10;

图 4.7.1.7前缀匹配

select s1,i1,l1 from common_example001 where partition like 'teststream' and s1 like 'z%'  limit 10;

图 4.7.1.8前缀匹配

6. 分页

由于hive sql本身并不支持分页功能,但在特定场景下分页又是非常有必要的。所以lsql在简单查询场景,添加了分页功能,目前默认只支持30000条以内的分页。

具体用法,大家请参考下图SQL的 limit offset,rows的用法,跟mysql有些类似。

切记,必须是简单SQL的查询,不能使用HIVE SQL (如函数,嵌套,关联等),offset+rows不能超过3万条。

select s1,i1,l1 from common_example001 where partition like 'teststream' and ( i1>'60' and i1<='67') order by s1 desc limit 3,3;

图 4.7.1.9分页

7. 排序

基本排序:
select s1,i1,ti1 from common_example001 where partition like 'teststream' and ( i1>'60' and i1<='67') order by i1 desc limit 10;

图 4.7.1.10排序

排序的性能跟命中的记录条数有直接关系:

  • 如果说排序的性能,最快的仍属于tree类型的排序,可以利用索引,其他排序均属于暴力排序。所以对于时间类型的排序,尽量转换成tree类型的,再借助磁盘存储在SSD上,会有意想不到的性能提升。

  • 在范围筛选上,i1>'60' and i1<='67'的性能不如 i1 like '[60 TO 67]'的性能,i1 like '[60 TO 67]'与i1 between 60 and 67(闭区间)的性能相同,而i1的性能不如ti1这种是tree类型的性能。但tree的性能提升是以额外的存储而换来的。

    select ti1,s1,i1 from common_example001 where partition like 'teststream' and (ti1>'60' and ti1<='67')order by ti1 desc limit 10;
    

图 4.7.1.11排序

8. wildcard类型的模糊匹配

模糊匹配(顺序可能错乱,但节省空间):
select wc4_1 from common_example001 where partition like 'teststream' and wc4_1='82' limit 10;

图 4.7.1.12 模糊匹配

9. wildcard含有p位置的精确匹配

  • 包含某一字符串

    select wc4_2 from common_example001 where partition like 'teststream' and wc4_2 like '39' limit 10;
    

    图 4.7.1.13包含匹配

  • 前缀后缀匹配

    --前缀匹配
    select wc4_2 from common_example001 where partition like 'teststream' and wc4_2 like '^156' limit 10;
    

    图 4.7.1.14前缀匹配

    --后缀匹配
    select wc4_2 from common_example001 where partition like 'teststream' and wc4_2 like '49^' limit 10;
    

图 4.7.1.15后缀匹配

Copyright © lucene.xin 2020 all right reserved修改时间: 2021-07-05 17:55:43

results matching ""

    No results matching ""