Lesson 3 of 5 ML Data Sources, Storage and Formats

Choosing Data Formats for ML Workloads

This lesson explains how a dataset's file format affects how fast it can be read, how much querying costs and which algorithms and services accept it, and how to match the format to the access pattern.

Learning outcomes

After completing this lesson, you will be able to:

  • Use CSV, JSON and JSON Lines correctly, including label column placement.
  • Explain when columnar formats such as Parquet and ORC are faster and cheaper.
  • Identify ML-specific formats such as RecordIO-protobuf.

Row formats: CSV, JSON and JSON Lines

CSV is the simplest tabular format and is accepted by most SageMaker AI built-in algorithms. For supervised training with built-in algorithms, the target is usually the first column and the file has no header row. CSV has no schema or types, so data types must be inferred and commas inside values must be quoted.

JSON represents nested records, such as an order with line items. JSON Lines (JSONL) places one JSON object on each line, which makes the file easy to split and stream. JSONL is the required format for Amazon Bedrock model customisation datasets and Bedrock batch inference input, and it is common for SageMaker AI batch transform and Ground Truth manifests.

Columnar formats: Parquet and ORC

Apache Parquet and Apache ORC store values column by column with compression and embedded statistics. A query or feature extraction job that needs five columns out of two hundred reads only those five, and readers can skip blocks whose statistics exclude a filter. This makes columnar formats far cheaper and faster for analytics with Athena, Glue and EMR. Parquet is the most widely supported and is accepted by several built-in algorithms and by SageMaker Feature Store offline queries.

The following diagram compares what a feature query reads from clickstream data stored as gzip JSON and as partitioned Parquet.

What a feature query reads before and after the CTAS conversion. From gzip JSON, every query parses all eighty fields of every record. From Snappy Parquet partitioned by event date, it reads only the six selected columns of the dates it needs, typically cutting the bytes read by more than 90%.
The layout is schematic.
Sort into groups

Row or columnar?

Exam skills 1.1.5

Decide whether each workload is better served by a row format or a columnar format.

Log in to try this activity Interactive activities are free with an account.

ML-specific formats

RecordIO-protobuf is the optimised format for many SageMaker AI built-in algorithms such as Linear Learner, Factorization Machines and K-Means, and works well with Pipe mode, which streams data to the algorithm. Deep learning frameworks have their own sharded formats, such as TFRecord for TensorFlow. Images are stored as JPEG or PNG files with a manifest that lists each file and its label, and audio as WAV or FLAC.

The following table summarises when each format fits.

FormatStrengthTypical use
CSVSimple, universalBuilt-in algorithm input, small exports
JSON / JSONLNested records, line-splittableBedrock fine-tuning and batch inference, manifests
Parquet / ORCColumnar, compressed, statisticsLarge analytic datasets, feature extraction
RecordIO-protobufOptimised for built-in algorithmsPipe mode training
TFRecordSharded binary recordsTensorFlow training at scale
JPEG/PNG + manifestImages with labelsComputer vision training
Match the pairs

Formats for ML tools

Exam skills 1.1.5

Match each format with the ML workload that expects it.

Log in to try this activity Interactive activities are free with an account.
Worked example

Converting clickstream data

Raw clickstream events arrive as gzip JSON files totalling 2 TB per month. Data scientists extract six fields out of eighty to build features, and their Athena queries scan the full dataset each time.

-- Athena CTAS: rewrite raw JSON as partitioned Parquet once
CREATE TABLE clicks_parquet
WITH (format = 'PARQUET', parquet_compression = 'SNAPPY',
      partitioned_by = ARRAY['event_date'])
AS SELECT user_id, session_id, page, action, device, event_ts, event_date
FROM clicks_raw_json;

Each query now reads only the selected columns and partitions. Scanning six of eighty columns in compressed Parquet typically cuts the bytes read by more than 90%, which lowers Athena cost and speeds up feature jobs. JSON remains suitable for the raw landing zone, where records are written once and kept for replay.

Check yourself

Which format do Bedrock fine-tuning and batch inference use?

Show answer

JSONL, with one JSON record per line.

Exam Tips

Remember for the exam

  • Reading a few columns of large tables: Parquet or ORC.
  • Bedrock fine-tuning and batch inference: JSONL.
  • Built-in algorithms in Pipe mode: RecordIO-protobuf.
  • Built-in algorithm CSV input: target first, no header.
  • Convert raw JSON to partitioned Parquet once to cut query cost.