Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there sql WITH clause equivalent in hive?

Tags:

sql

hadoop

hive

Failed to find the answer in the specs.

So, I wonder: Can I do something like that in hive?

insert into table my_table
with a as
(
    select *
        from ...
        where ...  
),

b as
(
    select *
        from ...
        where ...  
)
select 
    a.a, 
    a.b, 
    a.c, 
    b.a, 
    b.b, 
    b.c 
from a join b on (a.a=b.a);
like image 833
aviad Avatar asked May 28 '14 10:05

aviad


People also ask

IS WITH clause supported in Hive?

A Hive WITH Clause can be added before a SELECT statement of you query, to define aliases for complex and complicated expressions that are referenced multiple times within the body of the SELECT statements.

What is the use of WITH clause in Hive?

The WITH clause is an optional clause used to contain one or more common table expressions (CTE) where each CTE defines a temporary table that exists for the duration of the query. Each subquery in the WITH clause specifies a table name, an optional list of column names, and a SELECT statement.

What type of SQL does Hive use?

Hive was created to allow non-programmers familiar with SQL to work with petabytes of data, using a SQL-like interface called HiveQL.

Is Hive query same as SQL?

Key differences between Hive and SQL: Architecture: Hive is a data warehouse project for data analysis; SQL is a programming language. (However, Hive performs data analysis via a programming language called HiveQL, similar to SQL.) Set-up: Hive is a data warehouse built on the open-source software program Hadoop.


1 Answers

With is available in Hive as of version 0.13.0. Usage documented here.

like image 90
John McDonnell Avatar answered Sep 22 '22 22:09

John McDonnell