问题陈述假设有一个日志文本文件。下面是文件中的字段。
日志文件
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')
有人建议用Hive或Pig来获得这些信息吗
2条答案
按热度按时间5jdjgkvh1#
这可以使用sum()或analytic sum()实现,具体取决于单个表扫描中的确切要求。如果用户向购物车添加了两个产品,但只购买了一个呢?
对于用户+产品:
olhwl3o22#
配置单元:使用
not in
```select * from table
where action='AddtoCart' and
userID not in (select distinct userID from table where action='Purchase')
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;