内容纲要
概要描述
Morphling模式下MapJoin后在做group by没有结果
详细说明
具体测试SQL如下:
drop stream s2;
CREATE STREAM s2(
hits int,
url string,
dtime TIMESTAMP
) ROW FORMAT DELIMITED FIELDS TERMINATED BY ","
TBLPROPERTIES(
"topic"="testjoin",
"timefield"="dtime",
"timeformat"="yyyy-MM-dd HH:mm:ss",
"use.lowlevel.consumer"="true",
"kafka.zookeeper"="stream371:2188",
"kafka.broker.list"="stream371:9098"
);
--建立结果表
drop table s2_out;
CREATE table s2_out(
key string,
hits int,
url string,
realtime string,
mintime string,
maxtime string
);
--建立窗口
drop stream wstream;
CREATE stream wstream AS
SELECT *
FROM s2 STREAMWINDOW w1 AS (SEPARATED BY dtime INTERVAL '5' SECOND); – 窗口时间为5
SET streamsql.use.eventtime=true;
set streamsql.use.eventmode=true; --可选,使用eventmode延时会更低
set morphling.result.auto.flush=true;
--流表进行Join – 无结果 s2_out为结果表
stop streamjobs;
drop stream s_result;
create stream s_result as select/+MAPJOIN(dict_table)/ wstream.url
from wstream join dict_table on wstream.url = dict_table.url group by wstream.url;
insert into s2_out(hits,url,realtime,mintime,maxtime) select '-',url,'','-','end' from s_result;
问题原因:
在5.1之前的版本,由于使用/ + MAPJOIN / hint, 如果hive.ignore.mapjoin.hint设置成false的话,hive会生成MapJoinOperator,但是在构建mapjoindesc的时候,没有设置streamwindow配置,所以导致没有结果;
如果hive.ignore.mapjoin.hint设置成true,hive生成的JoinOperator,inceptor会在后续自动convert成MapJoinOperator,在这个过程中是设置过StreamWindowDesc的,因此会产生正确结果。
解决方法:
有两种解决方法:
set hive.ignore.mapjoin.hint = true; 强行在inceptor去做优化
先做MapJoin,在构建窗口,并进行group by操作; 这样的好处可以避免滑动窗口中同一条数据要join多次。