Skip to main content

How to Use Snappy Compression with Hive and Hadoop (Updated)

Struggling with delivery, architecture alignment, or platform stability?

I help teams fix systemic engineering issues: processes, architecture, and clarity.
→ See how I work with teams.


Snappy is a fast compression codec widely used in Hadoop ecosystems. This updated guide shows how to generate data, upload it to HDFS, process it with Hive using Snappy compression, verify the output files, and load Snappy-compressed data back into Hive using modern Hadoop commands.

Snappy is a high-performance compression and decompression library originally developed at Google. It is optimized for speed rather than maximum compression ratio, making it a preferred codec in many Hadoop and Hive pipelines.

Snappy is integrated in all modern Hadoop distributions (Hadoop 2.x and 3.x) and works with Hive, MapReduce, and increasingly Tez or Spark-based Hive deployments.

1. Create sample input data

Generate a small test file:

$ seq 1 1000 | awk '{OFS="\001";print $1, $1 % 10}' > test_input.hive
$ head -5 test_input.hive
1^A1
2^A2
3^A3
4^A4
5^A5

2. Upload the data into HDFS

Updated command: Hadoop now uses hdfs dfs instead of hadoop dfs.

$ hdfs dfs -mkdir -p /tmp/hivetest
$ hdfs dfs -put test_input.hive /tmp/hivetest

$ hdfs dfs -ls /tmp/hivetest
Found 1 items
-rw-r--r--   3 hdfs supergroup   5893 ... /tmp/hivetest/test_input.hive

3. Create an external Hive table

External tables in Hive reference a directory:

hive> CREATE EXTERNAL TABLE hivetest1 (a INT, b INT)
      ROW FORMAT DELIMITED FIELDS TERMINATED BY '\001'
      LOCATION '/tmp/hivetest';

hive> SELECT * FROM hivetest1 LIMIT 1;
1     1

4. Enable Snappy in Hive

Before writing compressed output, enable Snappy via session settings:

hive> SET hive.exec.compress.output=true;
hive> SET mapreduce.output.fileoutputformat.compress.codec=org.apache.hadoop.io.compress.SnappyCodec;
hive> SET mapreduce.output.fileoutputformat.compress.type=BLOCK;

Note: In Hadoop 2.x and 3.x, the modern property names start with mapreduce.output. instead of mapred.output.

Now create a managed table for compressed output:

hive> CREATE TABLE hivetest2 (a INT, b INT);

5. Insert data into the Snappy-compressed table

Hive will launch a MapReduce (or Tez) job that produces Snappy-compressed output blocks:

hive> INSERT OVERWRITE TABLE hivetest2
      SELECT * FROM hivetest1;

Total jobs = 1
... job output omitted ...
1000 Rows loaded to hivetest2

6. Validate the compressed data file

Verify that Hive created a Snappy file:

$ hdfs dfs -ls /user/hive/warehouse/hivetest2
Found 1 items
-rw-r--r--   3 hdfs supergroup  4021 ... /user/hive/warehouse/hivetest2/000000_0.snappy

Read the Snappy file (it will appear as binary with readable records):

$ hdfs dfs -cat /user/hive/warehouse/hivetest2/000000_0.snappy | head -5
...binary header...
1^A1
2^A2
3^A3
4^A4
5^A5

7. Load Snappy data into another Hive table

You can also load existing Snappy files using LOAD DATA:

hive> CREATE TABLE hivetest3 (a INT, b INT);

hive> LOAD DATA INPATH '/user/hive/warehouse/hivetest2/000000_0.snappy'
      INTO TABLE hivetest3;

hive> SELECT * FROM hivetest3 LIMIT 5;
1     1
2     2
3     3
4     4
5     5

Notes for Modern Hadoop Versions

  • Snappy is enabled by default in Hadoop 2.x+ as long as native libraries are installed.
  • On Hive-on-Tez or Spark, compression is still controlled via SET statements or table properties.
  • Modern Hive uses ORC or Parquet, which internally use Snappy by default.
  • This example remains valid for teaching raw file-based compression workflows.

Snappy remains a preferred codec due to its balance between speed and reasonable compression ratio. Always ensure that your Hadoop installation has native Snappy libraries available; otherwise, Hadoop will silently fall back to slow pure-Java implementations.

If you need help with distributed systems, backend engineering, or data platforms, check my Services.

Most read articles

Building a Model-Agnostic Multi-Agent System with OpenClaw

Over one week we rebuilt our AI stack around OpenClaw’s multi-agent architecture to avoid provider lock-in and stop wasting premium tokens. By aligning models to tasks, diversifying fallbacks across providers, enforcing minimal tool access, and switching to memory-first workflows with ephemeral sessions, we reduced token usage per task by about 70% and cut our monthly bill by 77% while improving operational resilience. How We Achieved 77% Cost Reduction and Provider Independence Over the past week, we rebuilt our AI infrastructure around OpenClaw’s multi-agent architecture. The result was a 77% cost reduction , provider independence , and a delegation system that routes work to the most cost-effective model for each job. Below is the technical journey of optimizing a 7-agent squad with OpenClaw. The Challenge: Model Provider Lock-In We started with a simple problem: our entire squad defaulted to a single model provider. This created three issues: Cost inefficiency beca...

BacNet => MQTT in Production: The Real Cost of Bridging BACnet to MQTT at Scale

bacnet2mqtt looks simple in a README and expensive in production. Once BACnet polling, reconnection behavior, stale state, and MQTT publishing collide, teams discover they are not deploying a lightweight adapter but operating infrastructure. This article breaks down where bacnet2mqtt works, where it becomes a bottleneck, and which production patterns reduce the operational damage before incidents, backlogs, and silent data loss turn a building integration into a long-running engineering problem. I inherited a building controls integration problem 18 months ago. Three office floors. 217 BACnet sensors covering temperature, occupancy, and HVAC actuators. The data was trapped inside the building automation network while the business wanted analytics, reporting, and compliance visibility in the data platform. The obvious answer looked easy enough: deploy bacnet2mqtt, bridge BACnet into MQTT, and push the stream into the lakehouse stack. The repository made it sound like a w...

Get Apache Flume 1.3.x running on Windows

Since we found an increasing interest in the flume community to get Apache Flume running on Windows systems again, I spent some time to figure out how we can reach that. Finally, the good news - Apache Flume runs on Windows. You need some tweaks to get them running. Prerequisites Build system: maven 3x, git, jdk1.6.x, WinRAR (or similar program) Apache Flume agent: jdk1.6.x, WinRAR (or similar program), Ultraedit++ or similar texteditor Tweak the Windows build box 1. Download and install JDK 1.6x from Oracle 2. Set the environment variables    => Start - type " env " into the search box, select " E dit system environment variables ", click Environment Variables, Select " New " from the " Systems variables " box, type " JAVA_HOME " into " variable name " and the path to your JDK installation into "Variable value" (Example:  C:\Program Files (x86)\Java\jdk1.6.0_33 ) 3. Download maven from Apache 4. Set...