Skip to content
ParquetKitGitHub
On this page

Guides

Parquet DECIMAL Column Shows as Bytes? Decode and Export It

The symptom

You open a Parquet file and a money column looks wrong. Depending on the tool, amount shows up as AAAAAAAE0g==, as b'\x00\x00\x04\xd2', or as 1234 when you expected 12.34. The data is fine. The reader is showing the storage format instead of the value.

How Parquet stores DECIMAL

DECIMAL(precision, scale) is a logical type. On disk it is an unscaled integer, and the scale lives only in the schema:

Physical typeWho writes itStored value for 12.34 at scale 2
INT32precision 1–9, e.g. Spark, DuckDB1234
INT64precision 10–18, e.g. Spark, DuckDB1234
FIXED_LEN_BYTE_ARRAYpyarrow by default; Spark above 18 digitsbig-endian two's-complement bytes of 1234

The writer picks the physical type. DuckDB stores DECIMAL(16,2) as INT64, and pyarrow stores the same column as a 7-byte FIXED_LEN_BYTE_ARRAY. Spark uses byte arrays for every decimal when spark.sql.parquet.writeLegacyFormat=true, which many Hive-era pipelines set. Old readers and some quick-look tools only see the physical type, so you get bytes or a scaled-up integer.

Confirm what you have

DuckDB reports both layers:

SELECT name, type, type_length, converted_type, precision, scale, logical_type
FROM parquet_schema('orders.parquet');

A row like amount | FIXED_LEN_BYTE_ARRAY | 7 | DECIMAL | 16 | 2 tells you everything: 7-byte values, scale 2. If you would rather not install anything, drop the file into the Parquet Viewer. It reads the footer and shows the column as DECIMAL(16,2) with proper values.

Read it with a reader that understands it

Most of the time the fix is to switch readers. DuckDB, pyarrow and Spark all apply the logical type:

SELECT order_id, amount FROM 'orders.parquet' LIMIT 5;
-- amount is DECIMAL(16,2): 12.34, 0.50, ...
import pyarrow.parquet as pq
t = pq.read_table("orders.parquet")
print(t.schema.field("amount").type)   # decimal128(16, 2)

pandas turns these into decimal.Decimal objects in an object column. That is exact but slow. If you read with dtype_backend="pyarrow", the column stays an Arrow decimal type.

Decoding raw bytes by hand

If you are stuck with a tool that gives you the raw bytes, for example a log, a JSON dump, or a legacy reader, the conversion is one line:

from decimal import Decimal
import base64

raw = base64.b64decode("AAAAAAAE0g==")          # or the bytes object itself
unscaled = int.from_bytes(raw, "big", signed=True)
value = Decimal(unscaled).scaleb(-2)            # scale from the schema
print(value)                                    # 12.34

For INT32/INT64 storage, skip the byte step: Decimal(1234).scaleb(-2). The signed=True matters, because negative amounts use two's complement.

Exporting decimals exactly

When converting to CSV, keep the decimal in DuckDB and let it print the fixed scale:

COPY (SELECT order_id, amount FROM 'orders.parquet')
TO 'orders.csv' (HEADER);
-- 12.34, 0.50, 100.00: trailing zeros kept

Three things to avoid:

  • Casting to DOUBLE. amount::DOUBLE is fine for charts but rounds anything beyond about 15 significant digits. That is a problem for DECIMAL(38, x) IDs and crypto amounts.
  • Excel as the destination. Excel stores numbers as doubles, so the same limit applies. Cast to VARCHAR if the exact digits matter.
  • JSON numbers. Most JSON parsers read 12.50 as a float. See fixing "not JSON serializable" for the string-versus-number trade-off.

For a quick conversion without a terminal, Parquet to CSV runs the same DuckDB engine in your browser. The file never leaves your machine, and decimals are written with their declared scale. To spot-check values first, run the parquet_schema query above in the SQL Workbench.

Frequently asked questions

Why does my Parquet decimal column look like base64 or binary?
DECIMAL is a logical type layered on a physical one. Large decimals are stored as FIXED_LEN_BYTE_ARRAY, and a reader that ignores the logical type annotation shows those raw bytes instead of the number.
Why do I see 1250 instead of 12.50?
Small decimals are stored as INT32 or INT64 holding the unscaled value. A reader that drops the scale shows 1250; dividing by 10 to the power of the scale (here 2) gives the real value.
How do I keep decimals exact when converting Parquet to CSV?
Use a reader that understands DECIMAL, such as DuckDB, and write the column as-is or cast it to VARCHAR. Avoid casting to DOUBLE, which rounds values beyond about 15 significant digits.

Related guides