Hive 建议使用蜂箱或猪的最佳方式

Hive 建议使用蜂箱或猪的最佳方式,hive,apache-pig,Hive,Apache Pig,问题陈述 假设有一个日志文本文件。下面是文件中的字段 日志文件 userID productID action 其中一项行动是—— Browse, Click, AddToCart, Purchase, LogOut 选择执行AddToCart操作但未执行购买操作的用户 ('1001','101','201','Browse'), ('1002','102','202','Click'), ('1001','101','201','AddToCart'), ('1001','101','20

问题陈述 假设有一个日志文本文件。下面是文件中的字段

日志文件

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获取此信息

Pig:使用操作过滤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;

这可以使用求和或分析求和,具体取决于单表扫描中的确切要求。若用户向购物车添加了两个产品,但只购买了一个,那个么会怎么样

对于用户+产品:

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

示例数据中有4列,但您提到日志文件有3列。缺少很多信息。例如,您的数据实际上是否在配置单元表中?最重要的是,你到底试过什么?
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