Skip to main content
How you cut a file up before encoding changes what you get back. The same data encoded whole and encoded in pieces is not the same result, and the difference can be large. The rule is short: put similar bytes next to each other. In a table that means one file per column. The rest of this page is what that looks like in practice, and when it is worth doing. Dependencies: pandas and the serva SDK.

Why a column encodes better than a row

Any table stored row major interleaves its types. One row of a table holds an integer, then a date, then a short code, then a float, then a flag, and the next row does the same thing again with different values:
Read as bytes, the pattern turns over every few characters. A compressor works on what is adjacent, and in this layout almost nothing is adjacent to anything like itself. Take one column of the same table and the picture inverts:
Every value has the same shape, drawn from the same small set. That is the repetition an encoder is built to find, and row major storage is what was hiding it. The second reason has nothing to do with size. One file per column means a run reads only the features it uses, and a feature can be added or dropped without encoding the dataset again.

Which columns pay off

The gain is not spread evenly, so it helps to know what to expect before you split anything. What matters is how many distinct values a column holds relative to its number of rows. A column of near unique values has little internal repetition to exploit, so isolating it does not help much. Those columns tend to dominate whatever size is left after a split, which is worth knowing when you are deciding whether the split is worth the effort.

Split the file

Read the frame as text so the column files hold exactly what the source held, then write one file per column.
dtype=str with keep_default_na=False matters. Without it pandas reinterprets your values on the way in and rewrites them on the way out, so the column files would hold something subtly different from the source rather than a rearrangement of it.

Encode each piece

The SDK encodes from a path, so each column is already a file by the time it gets here.
Each piece lands beside its source with a .serva suffix, so the set stays together as one dataset rather than becoming a pile of unrelated files.

Keep the rows aligned

This is the part that goes wrong. Splitting throws away the thing that held the data together: row 5000 of one column file is only meaningful because it is the same record as row 5000 of every other. Nothing in the files themselves enforces that. Write a manifest at split time and treat it as part of the dataset.
Never filter or sort a single column file on its own. Any operation that changes the length or the order of one column has to be applied to all of them, or the rows stop lining up and nothing will tell you.

Load only what you need

A run that uses three features decodes three files, whatever the table’s full width.
That rebuilds a frame identical to those columns of the source, in the same row order.

A measured example

One dataset, to show the shape of the result. A public flights table, 200,000 rows and 35 columns, 35.0 MB of CSV. Splitting produced a result 25% smaller than encoding the same data whole. Per column, sorted by how well each did, and grouped by the kinds described above: Six columns of clock times and elapsed minutes account for most of what is left. Your own tables will differ in the details, but the ordering holds: the fewer distinct values a column carries, the more a split gains you.
The column files together are about 1% larger than the source, since each row ends with a newline instead of sharing a comma with its neighbours, and every file repeats a header. The split starts slightly behind on raw bytes and still finishes well ahead.

Choosing where to cut

Columns are the natural seam in a table, but they are not the only one.
  • By column, when the table is wide and the columns differ in kind. This is the case above.
  • By row block, when the file is long rather than wide. Blocks of a few hundred thousand rows keep the row major layout but give you pieces you can encode in parallel and load selectively.
  • By both, for a large table: split into row blocks first, then columns within each block.
The same reasoning applies to any format with repeating internal structure. Wherever a file interleaves unlike things, separating them before encoding gives the encoder more to work with.

When not to split

Splitting is not free.
  • It costs time. In the example above the 35 columns took 344 seconds to encode against 127 seconds for the same data whole. Each piece is its own job with its own upload and round trip, so a wide table multiplies that fixed cost by its column count.
  • Very wide tables get unwieldy. Four hundred columns means four hundred files, four hundred encode calls, and a manifest that has to be right.
  • Narrow tables are not worth it. With three or four columns there is little interleaving to remove, and the overhead is most of what you pay.
  • Mostly unique data gains little. A table that is nearly all timestamps and measurements has little repetition for a split to expose.