SmartQueryTools

Get Top N Rows from Parquet Files Online

Extract the top N rows per group from Parquet files directly in your browser. Get the top 5 products per category, highest scores per team, or any ranked subset — no upload required.

How to get Top N Rows from Parquet files

  1. Drop your file onto the upload area. The first 200 rows are shown and the first numeric column is pre-selected as the ranking column.
  2. Choose Rank by column and a Direction: Highest first for the largest values, Lowest first for the smallest.
  3. Optionally choose a Group by column to get the top rows within each group. Leave it on (none) to rank the whole table.
  4. Set Top N (default 5). Tick Include rank position column if you want a rank_in_group column showing 1, 2, 3 within each group.
  5. Click Get Top N, check the row count and preview, then download the result in the same format.

Your file is processed locally in your browser and is never uploaded. The free limit is 50 MB per file; larger files work if your device has the memory for them.

Worked example

A race organiser has marathon finish times and wants the two fastest runners in each age group for the podium list.

Input (Parquet)

Parquet file (binary, columnar) — shown as a table with its schema

runnerage_groupfinish_minutes
Aroha NgataF40-49212.5
Megan DoyleF40-49198.25
Lena FischerF40-49205
Tom ReidM50-59187.75
Raj PatelM50-59201
Owen ClarkeM50-59179.5

Schema: runner VARCHAR, age_group VARCHAR, finish_minutes DOUBLE

Settings

  • Rank by column: finish_minutes
  • Direction: Lowest first
  • Group by: age_group
  • Top N: 2
  • Include rank position column: on

Result

runnerage_groupfinish_minutesrank_in_group
Megan DoyleF40-49198.251
Lena FischerF40-492052
Owen ClarkeM50-59179.51
Tom ReidM50-59187.752

Lower times are better, so Lowest first is used. Each age group is ranked on its own, and the slowest runner in each group drops out. The output is sorted by age_group and then by finish_minutes. The rank_in_group column is added at the end only because the rank option was ticked. With Group by left on (none), the result would be the two fastest runners overall: Owen Clarke and Tom Reid.

Working with Parquet files

Parquet columns keep their stored types, so a DECIMAL revenue column or an INT64 score ranks numerically without any guessing. Timestamp columns rank correctly at full precision, which makes "latest 3 events per device" a simple setting: rank by the timestamp, Highest first, N = 3. Two events a few microseconds apart are ranked separately even if they look identical in the preview.

The Group by list includes every column, but grouping by a struct or list column is rarely useful. Pick a scalar key such as a customer ID or region code instead. The result is written with COPY to a new Parquet file with the same column types, plus an INT64 rank_in_group column if you asked for it. Row groups are rewritten, so a file that was sorted or partitioned a certain way upstream will be ordered by group and rank afterwards. Because the whole file is ranked in memory, very large files are limited by the memory available to your browser tab.

Frequently Asked Questions

Can I get the latest N records per ID from a Parquet file?

Yes. Set Rank by to the timestamp column, Direction to Highest first, Group by to the ID column, and Top N to the number you need.

Does the Parquet output keep DECIMAL and TIMESTAMP types?

Yes. All original columns keep their types. The optional rank_in_group column is added as an integer.

What happens when two rows tie at the Nth position?

The tool uses ROW_NUMBER, so exactly N rows are returned per group and one of the tied rows is dropped. Which one is not guaranteed. If ties matter, use the Rank tool, which supports RANK and DENSE_RANK, and then filter.

Can I rank by a text or date column?

Yes. Rank by lists every column. Text ranks alphabetically and dates rank chronologically. The first numeric column is only the default.

Where are NULL values placed in the ranking?

After all non-NULL values, whichever direction you choose. They only appear in the result when a group has fewer than N rows with a value.

Related Tools