栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

临时加入Hive查询(时间紧迫的事件)

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

临时加入Hive查询(时间紧迫的事件)

这将是一个幼稚的解决方案:

select  *from         messages c        cross join      messages mwhere   m.time  between c.time - interval '0.001' second     and     c.time + interval '0.001' second    and c.word1 = '2B3B'    and m.word2 = 'ABAA';

+----------------------------+--------+-------+-------+----------------------------+--------+-------+-------+| time | source | word1 | word2 | time | source | word1 | word2 |+----------------------------+--------+-------+-------+----------------------------+--------+-------+-------+| 2012-02-01 23:43:16.998824 |   0001 | 2B3B  | FAF0  | 2012-02-01 23:43:16.999356 |   0002 |  2326 | ABAA  |+----------------------------+--------+-------+-------+----------------------------+--------+-------+-------+

这是具有良好性能的解决方案

select  *from         messages c        join messages m        on   floor (cast(c.time as decimal(37,7)) / (2 * 0.001))   =  floor (cast(m.time as decimal(37,7)) / (2 * 0.001))where   m.time  between c.time - interval '0.001' second     and     c.time + interval '0.001' second    and c.word1 = '2B3B'    and m.word2 = 'ABAA'union allselect  *from         messages c        join messages m        on   floor ((cast(c.time as decimal(37,7)) + 0.001) / (2 * 0.001))   =  floor ((cast(m.time as decimal(37,7)) + 0.001) / (2 * 0.001))where   floor (cast(c.time as decimal(37,7)) / (2 * 0.001))     <>        floor (cast(m.time as decimal(37,7)) / (2 * 0.001))    and m.time  between c.time - interval '0.001' second     and     c.time + interval '0.001' second    and c.word1 = '2B3B'    and m.word2 = 'ABAA'

+----------------------------+--------+-------+-------+----------------------------+-------+-------+-------+| time | source | word1 | word2 |_col4 | _col5 | _col6 | _col7 |+----------------------------+--------+-------+-------+----------------------------+-------+-------+-------+| 2012-02-01 23:43:16.998824 |   0001 | 2B3B  | FAF0  | 2012-02-01 23:43:16.999356 |  0002 |  2326 | ABAA  |+----------------------------+--------+-------+-------+----------------------------+-------+-------+-------+

插图

事件A和B将被UNIOn ALL的上部捕获。
事件B和C将被UNIOn ALL的下部捕获。

    0        0.002    0.004    0.006    0.008    0.01          |        |        |        |        |        |-------------------------------------------------------|        ||        |    A  B  C     |        |     |        |-------------------------------------------------------         |        |        |        |        |   0.001    0.003    0.005    0.007    0.009


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/670231.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号