描述:
执行sql语句
语法:
hive_execute(con,sql)
备注:
外部库函数,hive_execute,可执行create table, drop table, load data, insert into, insert owerwrite,create view等hive sql语句, Load data local inpath支持本地文件操作,而非hive server上的文件; Load data inpath支持hdfs文件操作,需要hdfsUser有对应的权限。
参数:
con |
数据库连接串 |
sql |
sql语句,可执行create table, drop table, load data, insert into, insert owerwrite,create view等hive sql语句 |
返回值:
boolean值
示例:
|
A |
|
1 |
=hive_client("hdfs://192.168.0.8:9000/","thrift://192.168.0.8:9083","hive","asus") |
连接hive数据库 |
2 |
=hive_execute(A1, "create table stu2( id string, name string,age string)") |
建表 |
3 |
=hive_execute(A1, "drop table stu") |
删除表 |
4 |
=hive_execute(A1, "alter table stu2 add columns (ncol string)") |
表中添加列 |
5 |
=hive_execute(A1, "insert into stu2 values ('2','dfff','21','lll')") |
插入数据 |
6 |
=hive_execute(A1,"load data local inpath 'D:\\haha.txt' overwrite into table ha") |
将本地txt文件上传到hive表中 |
相关概念: