Skip to content

Commit

Permalink
0622blog
Browse files Browse the repository at this point in the history
0622blog;
目录调整
  • Loading branch information
xxzuo committed Jun 22, 2022
1 parent 892aae7 commit 22c1866
Show file tree
Hide file tree
Showing 6 changed files with 194 additions and 3 deletions.
3 changes: 2 additions & 1 deletion source/_posts/es-on-hive.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ title: es on hive
date: 2022-06-16 21:50:59
tags:
- hive
- ElasticSearch
categories:
- 配置相关
- 大数据
---


Expand Down
2 changes: 2 additions & 0 deletions source/_posts/hive-ip地理信息查询.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ title: hive-ip地理信息查询
date: 2022-06-20 23:04:06
tags:
- hive
categories:
- 大数据
---

# HIVE UDF IP查询
Expand Down
2 changes: 1 addition & 1 deletion source/_posts/hive-中文乱码.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ date: 2022-06-16 21:51:19
tags:
- hive
categories:
- 配置相关
- 大数据
---


Expand Down
112 changes: 112 additions & 0 deletions source/_posts/hive权限相关命令.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
---
title: hive权限相关命令
author: xxzuo
date: 2022-06-22 23:27:58
tags:
- hive
categories:
- 大数据
---



```sql
-- 查看当前用户
select current_user();


-- 查看当前角色
show current roles;


-- 切换 admin 角色
set role admin;

-- 查看所有角色
show roles;



-- 查看用户的角色
show role grant user {userName};




-- 把角色授权给某个用户
grant role {roleName} to user {userName};




-- 撤销某个用户的角色授权
revoke role {roleName} from user {userName};






-- 创建角色
create role {roleName};




-- 删除角色
drop role {roleName};


-- 授予某个库的权限给某个用户
grant select on database {dbName} to user {userName};
grant insert on database {dbName} to user {userName};
grant update on database {dbName} to user {userName};
grant delete on database {dbName} to user {userName};

-- 回收某个库的权限给某个用户
revoke select on database {dbName} from user {userName};
revoke insert on database {dbName} from user {userName};
revoke update on database {dbName} from user {userName};
revoke delete on database {dbName} from user {userName};

-- 查看指定用户在所有库下面的权限
show grant user {userName};
-- 查看指定用户在某个库的权限
show grant user {userName} on database {dbName};






-- 授予表的权限给某个用户
grant select on table {dbName}.tableName to user {userName};
grant insert on table {dbName}.tableName to user {userName};
grant update on table {dbName}.tableName to user {userName};
grant delete on table {dbName}.tableName to user {userName};


-- 回收某个用户的表的权限
revoke create on table {dbName}.tableName from user {userName};
revoke select on table {dbName}.tableName from user {userName};
revoke insert on table {dbName}.tableName from user {userName};
revoke update on table {dbName}.tableName from user {userName};
revoke delete on table {dbName}.tableName from user {userName};

-- 查看指定用户在指定表的权限
show grant user {userName} on table {dbName}.{tableName};





-- 权限类别
-- ALTER 更改表结构,创建分区
-- CREATE 创建表
-- DROP 删除表,或分区
-- INDEX 创建和删除索引
-- LOCK 锁定表,保证并发
-- SELECT 查询表权限
-- SHOW_DATABASE 查看数据库权限
-- UPDATE 为表加载本地数据的权限
```
2 changes: 1 addition & 1 deletion source/_posts/yarn配置.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ date: 2022-06-21 22:54:37
tags:
- yarn
categories:
- 配置相关
- 大数据
---


Expand Down
76 changes: 76 additions & 0 deletions source/_posts/创建hive-udf.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
---
title: 创建hive-udf
author: xxzuo
date: 2022-06-22 23:28:20
tags:
- hive
categories:
- 大数据
---



### 1.自定义 UDF 函数
pom 中添加下面依赖
```xml
<dependencies>
<dependency>
<groupId>org.apache.hive</groupId>
<artifactId>hive-exec</artifactId>
<version>2.3.4</version>
<!-- 不需要打入jar包 -->
<scope>provided</scope>
</dependency>
</dependencies>
```
> 由于 hive 环境中已经有了 hive-exec jar包 所以打包时,不需要将hive-exec 打入
新建一个类 继承 UDF 即可
```java
// 继承UDF类
public class MyUDF extends UDF {
// 实现evaluate方法
public int evaluate(String str) {
// 自定义逻辑
return 0;
}
}
```

在这个类中,方法名一定要为 **evaluate**

### 2.打包上传
在 maven 中打包
找到刚才的 jar 包
上传到 hive 所在服务器

将jar包移动到 hive目录下的auxlib目录

然后重启hiveserver2


### 3.注册函数
将jar包注册到hive中后,就可以注册刚才自己编写的udf函数了

一般需要先注册临时函数,因为UDF开发完成后,需要进过一些测试才能确认代码是否没有问题。在测试UDF代码时,务必使用临时函数进行测试。这样即使代码出现了问题,也不会把函数真正的注册到Hive。代码测试完毕并且确认无误后,再将函数注册为永久函数


HIVE 函数相关
```sql
# 创建临时函数
CREATE TEMPORARY FUNCTION <函数名> AS <class全路径>;
# 删除临时函数
DROP TEMPORARY FUNCTION [IF EXISTS] <函数名>;


# 创建永久函数
CREATE FUNCTION [db_name.]function_name AS class_name
[USING JAR|FILE|ARCHIVE 'file_uri' [, JAR|FILE|ARCHIVE 'file_uri'] ];
# 删除永久函数
DROP FUNCTION [IF EXISTS] function_name;


# 查看函数
show functions;

```

0 comments on commit 22c1866

Please sign in to comment.