What are the clauses a Hive query could start with

Viewed 93

For retrieving data from Hive SQL, what all clauses a query could start with ? I only know of SELECT and WITH. Is there anything else ?

I'm not looking anything like CREATE, DELETE, ALTER etc..

This is basically for deciding whether a given query is for reading data from table or not (using query.startsWith()).

Thanks in advance !

1 Answers

SQL query can start with WITH, FROM, SELECT.

Multi-insert looks like this:

[WITH...]
[FROM...]
INSERT OVERWRITE TABLE1 SELECT...
INSERT OVERWRITE TABLE2 SELECT...

WITH can be omitted, it can start with FROM, it can be SELECT or INSERT...SELECT.

This query works. It starts with FROM and does not read data from table

from (select current_timestamp ts) s
select ts

The same inserting into multiple tables, of course the example is oversimplified but quite working

with mydata as (select current_timestamp ts)

from (select ts from mydata) s

insert into table1 
select ts

insert into table2
select ts
where ts = current_timestamp
Related