hive_execute ()

阅读(2601) 标签: 执行, sql, 外部库函数,

描述:

执行sql语句。

语法:

hive_execute(con,sql)

备注:

外部库函数,外部库的使用请参考《外部库使用指南》。

可执行create table drop table load data insert into insert owerwritecreate viewhive sql语句,Load data local inpath支持本地文件操作,不支持hive server上的文件;Load data inpath支持hdfs文件操作,需要hdfsUser有对应的权限。

参数:

con

数据库连接串。

sql

sql语句。

返回值:

Boolean

示例:

 

A

 

1

=hive_open("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表中。

相关概念:

hive_open()