Description:
Execute Hive’s SQL-like queries.
Syntax:
hive_execute(con,sql)
Note:
This external library function supports executing Hive’s SQL-like statements, including create table, drop table, load data, insert into, insert owerwrite, and create view. The statement Load data local inpath supports only operations on local files, rather than those on a Hive server; the statement Load data inpath supports operations on HDFS files, over which the user needs to have the corresponding privilege.
Parameter:
con |
Database connection string |
sql |
A SQL query statement |
Return value:
A boolean value
Example:
|
A |
|
1 |
=hive_client("hdfs://192.168.0.8:9000/","thrift://192.168.0.8:9083","hive","asus") |
Connect to the hive database |
2 |
=hive_execute(A1, "create table stu2( id string, name string,age string)") |
Create a table |
3 |
=hive_execute(A1, "drop table stu") |
Drop a table |
4 |
=hive_execute(A1, "alter table stu2 add columns (ncol string)") |
Add a column to the table |
5 |
=hive_execute(A1, "insert into stu2 values ('2','dfff','21','lll')") |
Insert data into the table |
6 |
=hive_execute(A1,"load data local inpath 'D:\\haha.txt' overwrite into table ha") |
Upload a local txt file to overwrite a Hive table |
Related function: