Support Questions

Find answers, ask questions, and share your expertise
Announcements
Celebrating as our community reaches 100,000 members! Thank you!

How to run all of hive queries in a file in one go

avatar
Expert Contributor

I have around 15 queries saved in a saved file in hive editor that is integrated in hue. The queries include CREATE TABLE/DROP TABLE and SELECT statement at the end of the file.

It seems like I can not execute all of these in one go.

 

How do I syntactically format or write hive queries so that hive can understand that we have the next query starting after end of one query .It should then finally give results of the select query.

1 ACCEPTED SOLUTION

avatar
Rising Star

If this is from HUE, hue can execute multiple command in a sequence until it reaches the first query that returns results (like a select query). For example, the following should be executed entirely in a single go.

 

drop table if exists foo;
create table if not exists foo (code string, description string, salary int);
insert into foo select code, description, salary from sample s where s.salary > 50000 and s.salary < 100000;
select * from foo where salary < 75000;

 

The following will stop after the select query, so the drop table will not be executed.

drop table if exists foo;
create table if not exists foo (code string, description string, salary int);
insert into foo select code, description, salary from sample_07 s where s.salary > 50000 and s.salary < 100000;
select * from foo where salary < 75000;

drop table foo;

 

But if you use beeline to execute a file containing multiple select queries, this should work without pausing.

View solution in original post

2 REPLIES 2

avatar
Super Guru

Hi sim6,

 

Do you mean that you want to run all the qureries in the file through Hue's Hive Editor interface, rather than running through beeline or Hive CLI?

 

Can you please copy and paste the content of the script here for me to have a look?

 

What was the result you get when you tried to run this file in Hue? You mentioned you can't execute all of them, do you know which ones were executed? And how did you run this file through Hue?

avatar
Rising Star

If this is from HUE, hue can execute multiple command in a sequence until it reaches the first query that returns results (like a select query). For example, the following should be executed entirely in a single go.

 

drop table if exists foo;
create table if not exists foo (code string, description string, salary int);
insert into foo select code, description, salary from sample s where s.salary > 50000 and s.salary < 100000;
select * from foo where salary < 75000;

 

The following will stop after the select query, so the drop table will not be executed.

drop table if exists foo;
create table if not exists foo (code string, description string, salary int);
insert into foo select code, description, salary from sample_07 s where s.salary > 50000 and s.salary < 100000;
select * from foo where salary < 75000;

drop table foo;

 

But if you use beeline to execute a file containing multiple select queries, this should work without pausing.