Hadoop 类蜂巢算子
我不知道该如何处理这个问题: 这是我的数据:Hadoop 类蜂巢算子,hadoop,hive,hiveql,sql-like,Hadoop,Hive,Hiveql,Sql Like,我不知道该如何处理这个问题: 这是我的数据: Table1: Table2: BRAND PRODUCT SOLD Sony Sony ABCD 1233 Apple Sony adv 1233 Google Sony aaaa 1233 IBM Apple 123 1233 etc.
Table1: Table2:
BRAND PRODUCT SOLD
Sony Sony ABCD 1233
Apple Sony adv 1233
Google Sony aaaa 1233
IBM Apple 123 1233
etc. Apple 345 1233
IBM 13123 1233
是否可以过滤查询,即我有一个代表品牌和总sold的表?
我的想法是:
Select table1.brand, sum(table2.sold) from table1
join table2
on (table1.brand LIKE '%table2.product%')
group by table.1.brand
这是我的主意,但我总是出错
最大的问题是Like操作符,或者还有其他解决方案吗?我看到两个问题:首先,在hive中的连接只在相等条件下工作,Like在那里不起作用 配置单元中仅支持相等联接、外部联接和左半联接。配置单元不支持非相等条件的联接条件,因为很难将此类条件表示为映射/减少作业 相反,这需要加入where条款 其次,我还发现like语句本身存在问题:'%table2.product%'被解释为字符串'%table2.product%'。此外,即使这样做是为了达到预期目的,它也会尝试在品牌内部寻找table2.product,而您似乎想从另一个角度来寻找它。要获得您想要的评估,您需要在table1.brand的内容中添加通配符;要实现这一点,需要将通配符连接到表达式中
table2.product LIKE concat('%',table1.brand,'%'))
通过这样做,您的like将计算字符串“%Sony%”、“%Apple%”等,而不是“%table2.product%”
你想要的是Brandon Bell的问题,我把它合并到这个答案中:
SELECT table1.brand, SUM(table2.sold)
FROM table1, table2
WHERE table2.product LIKE concat('%', table1.brand, '%')
GROUP BY table1.brand;
您应该能够在没有连接的情况下完成此任务。请参见以下查询:
SELECT table1.brand, sum(table2.sold)
FROM table1, table2
WHERE table2.product LIKE concat('%', table1.brand, '%')
GROUP BY table1.brand;
这是回报
Apple 2466
IBM 1233
Sony 3699
其中,我的输入文件如下所示:
Sony
Apple
Google
IBM
及
只是为了澄清隐式连接就是连接。就性能而言,它们应该是相同的。“FROM a,b其中a.ID=b.ID”是“FROM a JOIN b ON a.ID=b.ID:”的语法糖谢谢你的澄清。请检查并建议上述类似问题。非常感谢。
Sony ABCD 1233
Sony adv 1233
Sony aaaa 1233
Apple 123 1233
Apple 345 1233
IBM 13123 1233