问题陈述 假设有一个日志文本文件。下面是文件中的字段。
日志文件
userID
productID
action
其中“动作”将是其中之一–
Browse, Click, AddToCart, Purchase, LogOut
选择执行AddToCart操作但未执行购买操作的用户。
('1001','101','201','Browse'),
('1002','102','202','Click'),
('1001','101','201','AddToCart'),
('1001','101','201','Purchase'),
('1002','102','202','AddToCart')
任何人都可以建议使用性能优化的蜂巢或猪获得此信息
答案 0 :(得分:1)
根据单个表扫描中的确切要求,可以使用sum()或分析sum()进行此操作。如果用户将两种产品添加到购物车但只购买了一种产品,该怎么办?
对于用户+产品:
select userID, productID
from
(
select
userID,
productID,
sum(case when action='AddToCart' then 1 else 0 end) addToCart_cnt,
sum(case when action='Purchase' then 1 else 0 end) Purchase_cnt
from table
group by userID, productID
)s
where addToCart_cnt>0 and Purchase_cnt=0
答案 1 :(得分:0)
配置单元:使用not in
select * from table
where action='AddtoCart' and
userID not in (select distinct userID from table where action='Purchase')
猪:使用操作过滤ID,并进行左联接并检查ID为空
A = LOAD '\path\file.txt' USING PigStorage(',') AS (userID:int,b:int,c:int,action:chararray) -- Note I am assuming the first 3 columns are int.You will have to figure out the loading without the quotes.
B = FILTER A BY (action='AddToCart');
C = FILTER A BY (action='Purchase');
D = JOIN B BY userID LEFT OUTER,C BY userID;
E = FILTER D BY C.userID is null;
DUMP E;