利用hive API假设你是用户部门员工,现需一张表用于存放用户粉丝数据表: userfollower 存: follower 粉丝有谁 followed 关注谁 l.建表 usertollower 2用户 Mary 有一个粉丝 Alice 3用户Jack 有两个粉丝 Bob 和Ben 4.Jack 还关注了 Mary 5.查看 Jack 被那些人关注,关注了谁 6.Bob 取关了 Jack 7。扫描全表数据
时间: 2024-02-27 18:59:26 浏览: 118
对于这个问题,我们可以使用 HiveQL 语句来完成。
1. 创建表 usertollower:
```
CREATE TABLE usertollower (
follower STRING,
followed STRING
);
```
2. 插入数据:
```
INSERT INTO usertollower VALUES ('Alice', 'Mary');
INSERT INTO usertollower VALUES ('Bob', 'Jack');
INSERT INTO usertollower VALUES ('Ben', 'Jack');
INSERT INTO usertollower VALUES ('Mary', 'Jack');
```
3. 查看 Jack 被那些人关注,关注了谁:
```
SELECT follower, followed
FROM usertollower
WHERE followed = 'Jack'
OR follower = 'Jack';
```
输出结果:
```
follower | followed
---------+---------
Bob | Jack
Ben | Jack
Mary | Jack
Jack | Mary
```
4. Bob 取关了 Jack:
```
DELETE FROM usertollower
WHERE follower = 'Bob'
AND followed = 'Jack';
```
5. 扫描全表数据:
```
SELECT * FROM usertollower;
```
输出结果:
```
follower | followed
---------+---------
Alice | Mary
Ben | Jack
Mary | Jack
Jack | Mary
```
阅读全文