ORC
Optimized Row Columnar
A columnar file format for Hive. Optimized for compression and indexing.
Optimized Row Columnar
A columnar file format for Hive. Optimized for compression and indexing.
ORC (Optimized Row Columnar) is a columnar file format developed in 2013 by Hortonworks for Apache Hive. Created by Facebook as an improvement on RC File, it was designed to optimize analytic query performance in the Hadoop ecosystem.
Its key features are columnar storage, lightweight compression, and built-in indexing. Data is stored in units of Stripes (250MB by default), and each Stripe includes min/max and bloom filter indexes, so unnecessary data scans are skipped. With Predicate Pushdown, Stripes that do not match the WHERE condition are skipped entirely.
It has excellent compression efficiency, supporting Zlib, Snappy, and LZ4, and because values of the same data type are stored contiguously in each column, the effects of dictionary encoding and RLE (Run-Length Encoding) are maximized. Data is stored in 5-10 times less space than text files.
It is natively supported in Hive, Spark, Presto, and Trino, and in particular, Hive ACID transactions work only with the ORC format. Parquet is stronger in general-purpose use, while ORC is stronger in optimization for the Hive ecosystem, so one is chosen depending on the environment.
-- Hive์์ ORC ํ
์ด๋ธ ์์ฑ
CREATE TABLE sales_orc (
sale_id BIGINT,
product_name STRING,
category STRING,
amount DECIMAL(10, 2),
quantity INT,
sale_date DATE
)
STORED AS ORC
TBLPROPERTIES (
'orc.compress' = 'ZLIB', -- ์์ถ ๋ฐฉ์
'orc.compress.size' = '262144', -- ์์ถ ๋ฒํผ ํฌ๊ธฐ
'orc.stripe.size' = '268435456', -- Stripe ํฌ๊ธฐ (256MB)
'orc.row.index.stride' = '10000', -- ์ธ๋ฑ์ค ๊ฐ๊ฒฉ
'orc.bloom.filter.columns' = 'product_name,category' -- ๋ธ๋ฃธ ํํฐ
);
-- ๊ธฐ์กด ํ
์ด๋ธ์์ ORC๋ก ๋ณํ
INSERT INTO TABLE sales_orc
SELECT * FROM sales_csv;
-- ORC ํ
์ด๋ธ ๋ถ์ (ํต๊ณ ์์ง)
ANALYZE TABLE sales_orc COMPUTE STATISTICS FOR COLUMNS;
-- Predicate Pushdown ํ์ฉ ์ฟผ๋ฆฌ
-- category ์ธ๋ฑ์ค๋ก ๋ถํ์ํ Stripe ์คํต
SELECT product_name, SUM(amount) as total_sales
FROM sales_orc
WHERE category = 'Electronics'
AND sale_date BETWEEN '2024-01-01' AND '2024-12-31'
GROUP BY product_name
ORDER BY total_sales DESC
LIMIT 10;
-- Spark์์ ORC ์ฝ๊ธฐ/์ฐ๊ธฐ
-- spark-shell ๋๋ PySpark
-- val df = spark.read.orc("hdfs:///data/sales_orc")
-- Python (PyORC ๋ผ์ด๋ธ๋ฌ๋ฆฌ)
import pyorc
# ORC ํ์ผ ์ฐ๊ธฐ
with open("data.orc", "wb") as f:
with pyorc.Writer(
f,
"struct",
compression=pyorc.CompressionKind.ZLIB
) as writer:
writer.write((1, "product_a", 100.5))
writer.write((2, "product_b", 200.3))
# ORC ํ์ผ ์ฝ๊ธฐ
with open("data.orc", "rb") as f:
reader = pyorc.Reader(f)
for row in reader:
print(row)
Senior: "After switching the Hive tables to ORC, queries got 5 times faster and storage dropped by 70%."
Junior: "How is it different from Parquet?"
Senior: "To use Hive ACID transactions, only ORC works, and for general-purpose analytics, Parquet has better compatibility. We're Hive-centric, so we use ORC."
Interviewer: "Please tell us about your experience with large-scale data storage formats."
Candidate: "I operated a pipeline that stored 1 billion log records per day in ORC. I optimized it by configuring bloom filter columns so that 95% of Stripes are skipped when searching for a specific user_id, and I refreshed statistics with ANALYZE TABLE so that the Hive query planner would build accurate execution plans."
Take a mock interview on this topic โ WIA SOOM AI Interview ยท Start for free
Reviewer: "Please add a bloom filter to the ORC table. There are many searches on the user_id column, so it should be effective."
Developer: "Can I just add the bloom.filter.columns property with ALTER TABLE?"
Reviewer: "Yes, but it doesn't apply to existing data, so you need to recreate the table or run INSERT OVERWRITE."