100% Free Forever
AI-Powered Learning
Industry Expert Content
Certificates & Badges
Learn At Your Own Pace
Programming

Hive Basics

An introduction to Apache Hive's SQL-on-Hadoop model, covering its architecture, the Metastore, table design, and query execution.

Ecosystem ToolsBeginner9 min readJul 10, 2026
Analogies

What Is Hive?

Apache Hive is a data warehouse layer built on top of Hadoop that lets analysts query data stored in HDFS using HiveQL, a SQL-like language, instead of writing raw MapReduce code. Hive translates each query into a directed acyclic graph of MapReduce, Tez, or Spark jobs depending on the configured execution engine, and it follows a schema-on-read model: the underlying files aren't validated or transformed at load time, structure is imposed only when a query reads them, which makes ingestion fast but shifts data-quality bugs to query time.

🏏

Cricket analogy: Like a commentator translating raw ball-by-ball data into a readable scorecard on demand, rather than the broadcaster reformatting the footage as it's recorded, Hive imposes structure only when a query like a Virat Kohli strike-rate breakdown actually runs.

Hive Architecture and the Metastore

Hive's architecture centers on the Driver, which parses and plans a query, the Compiler and Optimizer, which turn that plan into an execution DAG, and the Metastore, a separate service backed by a relational database like MySQL or PostgreSQL that stores table schemas, partition locations, and column statistics rather than any actual data. Because the Metastore is decoupled from the query engine, multiple tools, Hive itself, Spark SQL, Presto, and Impala, can all share the same catalog of table definitions and read the same underlying HDFS or S3 files consistently.

🏏

Cricket analogy: The Metastore is like the official scorecard archive an entire cricket board maintains centrally, so both the TV broadcaster and the stadium's giant screen pull the same match records rather than each keeping a private, possibly inconsistent copy.

The Metastore stores only metadata -- table schemas, partition locations, column statistics -- never the actual rows. Losing HDFS data is catastrophic, but losing the Metastore is nearly as bad: Hive would no longer know which files belong to which table, so it should be backed up like any production database.

Tables, Partitions, and Buckets

Hive tables come in two flavors: managed (internal) tables, where Hive owns the underlying data files and DROP TABLE deletes them, and external tables, where Hive only stores metadata pointing at files that live independently, so dropping the table leaves the data untouched, the safer default when other tools also read those files. Large tables should be partitioned, typically by a low-cardinality column like a date, so a query with a WHERE clause on that column only scans the relevant subdirectories, and can additionally be bucketed by hashing a high-cardinality column like user_id into a fixed number of files to speed up joins and sampling.

🏏

Cricket analogy: Partitioning a huge ball-by-ball dataset by match_date is like a stadium archive filing scorecards into separate boxes per series, so a request for just the 2023 World Cup only pulls those boxes instead of the entire archive.

sql
CREATE EXTERNAL TABLE web_logs (
  user_id     STRING,
  event_type  STRING,
  event_ts    TIMESTAMP
)
PARTITIONED BY (log_date STRING)
CLUSTERED BY (user_id) INTO 32 BUCKETS
STORED AS ORC
LOCATION 's3://analytics-bucket/web_logs/';

ALTER TABLE web_logs ADD PARTITION (log_date='2026-07-09')
  LOCATION 's3://analytics-bucket/web_logs/log_date=2026-07-09/';

SELECT event_type, COUNT(*)
FROM web_logs
WHERE log_date = '2026-07-09'
GROUP BY event_type;

Query Execution Engines

Hive's default execution engine historically was MapReduce, but production clusters now overwhelmingly configure hive.execution.engine to tez or spark, since Tez collapses a query's MapReduce stages into a single DAG that avoids writing intermediate results back to HDFS between every stage, cutting latency substantially for multi-join queries. Storing tables in a columnar format like ORC or Parquet compounds this benefit, because Hive's vectorized query execution reads and processes data in batches of a few thousand rows per column at once rather than row by row, and predicate pushdown lets it skip entire ORC stripes that a WHERE clause's min/max statistics prove can't match.

🏏

Cricket analogy: Switching from MapReduce to Tez is like a broadcast team building one continuous highlights reel instead of exporting the footage to disk after every over and re-importing it for the next segment, dramatically cutting turnaround time for a Kohli innings recap.

Over-partitioning is a common beginner mistake: partitioning by a high-cardinality column like user_id (instead of bucketing by it) can produce millions of tiny HDFS partitions, overwhelming the Metastore and NameNode with small-file metadata and making planning slower than a full scan would have been.

  • Hive layers a SQL-like language, HiveQL, over Hadoop, translating queries into MapReduce, Tez, or Spark execution DAGs.
  • Hive follows schema-on-read: files aren't validated at load time, structure is applied only when a query reads them.
  • The Metastore is a separate database-backed service storing table and partition metadata, shared by Hive, Spark SQL, Presto, and other engines.
  • External tables leave underlying files untouched on DROP TABLE; managed tables delete the data along with the metadata.
  • Partitioning by a low-cardinality column like date enables partition pruning; bucketing by a high-cardinality column speeds up joins and sampling.
  • Tez and columnar formats like ORC, combined with vectorized execution and predicate pushdown, dramatically outperform classic MapReduce-based Hive.

Practice what you learned

Was this page helpful?

Topics covered

#Programming#HadoopStudyNotes#HiveBasics#Hive#Architecture#Metastore#Tables#StudyNotes#SkillVeris#ExamPrep