CodeBlanks Logo Icon CodeBlanks

SQL on Hadoop

Run SQL over big data.

SQL on Hadoop

SQL on Hadoop reaches big data on HDFS with SQL. Hive compiles SQL into MapReduce; Presto runs an in-memory distributed query instead.

SELECT customer_id, COUNT(*)
FROM hive.orders
GROUP BY customer_id;

Hive turns SQL into MapReduce.

customer_id, COUNT(*) is selected from hive.orders. Rows are grouped by customer_id; aggregate functions are computed per group.

SQL on Hadoop — details

Hive is slow but handles very large data; Presto is fast but bound by memory. They pair up: Hive for ETL, Presto for interactive analysis.

Practice SQL on Hadoop

Select 10 rows from the hive.orders table: SELECT * FROM hive.orders LIMIT 10.

Starter code

query.sql
-- Hadoop query
SELECT * FROM

Sample solution

query.sql
SELECT * FROM hive.orders LIMIT 10;

Expected output

10 rows

Questions and answers

Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.

1 What does Hive turn SQL into?

  • JSON
  • XML
  • MapReduce Correct answer
  • HTML

Explanation: Hive turns SQL into MapReduce.

2 Hive catalog

Question
SELECT * FROM ____.orders LIMIT 10
Answer
SELECT * FROM hive.orders LIMIT 10

Explanation: hive.orders refers to the orders table in the Hive catalog (catalog.table).

3 SQL on Hadoop: match the terms

Term Meaning
Hive compiler
Presto in-memory
HDFS file system
MapReduce parallel

All lessons in Expert