Skip to content

[python] Encode format table partition paths like Java - #11018

Open
plusplusjiajia wants to merge 3 commits into
apache:masterfrom
plusplusjiajia:fix/python-format-table-partition-paths
Open

plusplusjiajia wants to merge 3 commits into
apache:masterfrom
plusplusjiajia:fix/python-format-table-partition-paths

Conversation

@plusplusjiajia

@plusplusjiajia plusplusjiajia commented Nov 6, 2026 •

Copy link
Copy Markdown
Member

Purpose

PyPaimon's format table did not name partition directories as Java does: values were not escaped (x/y became two levels), null cut the path short instead of using __DEFAULT_PARTITION__, some values were formatted with str(), and escaped directories were read without unescaping.

As in Java PartitionPathUtils, FormatTableFileWriter and FormatTableWrite:

  • Writer: formats and escapes keys and values like Java, writes null as the default partition name, and leaves partition columns out of the files. It refuses values whose directory names would read back as another value, such as non-UTF-8 BINARY or an LTZ time in a DST overlap. A table of only partition columns keeps them in CSV and JSON files; other formats refuse it. Files hold the table's columns in its order: a nullable column that the input leaves out is written as null, and input without a NOT NULL column or with duplicate columns is refused before any file is written.
  • Reader: unescapes directory names, reads the default partition name as null, and skips non-partition directories. Every file reads every partition column: a file that keeps its partition columns reads them wherever it is, such as a=x/y of ('x/y', None), and an earlier version's file above the partition depth reads null for the keys where its path stopped. A partition filter matches an earlier version's directory, such as pt=a=b, by the values that a read of the whole table takes from it.
  • Overwrite: replaces the files of the partition's directory. It finds and checks them before it writes anything, and deletes them after the new files are written. A file that fails to write, and the new files written before it, are deleted, so a failure leaves the old files.
  • Filters and static overwrite: compare typed values, so overwrite({'pt': 'true'}) clears the partition of True, and 0.0 does not clear -0.0. A value that does not convert to the partition type is refused instead of selecting the null partition. A Python value converts only to the same value of the partition type, and a float also to the FLOAT that it spells, so overwrite({'pt': 1.5}) of an INT is refused instead of clearing the partition of 1, and a filter of 0.1 selects 0.1f.

Compatibility

  • Tables written by earlier PyPaimon versions, which named directories with str(), stopped the path at the first null value and kept partition columns in the files, still read, filter and take new rows. An overwrite refuses such a table before it writes or deletes anything, as it cannot always tell which partition an earlier file belongs to: it could delete another partition's rows or leave the old rows next to the new ones. It lists the table's directories and refuses a file above the partition depth or in a directory that this version would not name so, such as pt=True, which earlier versions wrote, and a directory such as pt=a%3Ab, which is also the earlier name of 'a%3Ab', that holds another value's rows. Such a table is rewritten with this version before it is overwritten.
  • Earlier TEXT files keep no partition columns, so an earlier TEXT directory with an escape, such as pt=a%3Ab, reads as 'a:b', as in Java.
  • Java before and since 19 name some FLOAT values differently, such as 2.68873286E11 and 2.6887329E11 ([Bug] [python] FLOAT and DOUBLE partition names differ between PyPaimon and Java on JDK 8/11/17 #11164), and Java 11 rejects the Java 19+ name. PyPaimon reads both as one partition and, as before, writes the exact value, which every Java reads. An overwrite refuses a table with a FLOAT directory that Java named otherwise than the exact value, such as pt=0.1 for 0.1f, or a DOUBLE directory that Java before 19 named otherwise. A Java filter on 0.1 does not find pt=0.10000000149011612.

#11007 (CSV nulls) depends on this PR and is merged after it. #11008 also changes file_store_path_factory.py and writes an overwrite's new files before it deletes the old ones in the same way. #11173, now merged, fixes the Java side of value-only default partition names.

Tests

  • format_write_execution_test.py: escaped, null and value-only paths, typed filters and overwrites, refused values, CSV and TEXT files, reads of tables written by earlier versions and overwrites that refuse them, failed overwrites that keep the old files, and FLOAT names of both JDKs.
  • Spark with Paimon 2.1.0, PyPaimon and pypaimon-rust 0.4.0 wrote Parquet and ORC tables with a b, x/y and null partitions against a DLF catalog, and every client read every table back with the same rows.
  • JavaPyE2ETest#testReadPythonFloatFormatTable reads FLOAT partitions written by PyPaimon with Java.
  • rest_format_table_test.py, cli_table_test.py, filesystem_catalog_test.py and native_commit_partition_spec_test.py pass. flake8 is clean.

@plusplusjiajia
plusplusjiajia force-pushed the fix/python-format-table-partition-paths branch 3 times, most recently from 921404e to 03a0223 Compare November 8, 2026 14:16
@plusplusjiajia
plusplusjiajia force-pushed the fix/python-format-table-partition-paths branch 6 times, most recently from 25b8f03 to 3cbe56f Compare November 15, 2026 12:50
@plusplusjiajia
plusplusjiajia force-pushed the fix/python-format-table-partition-paths branch 2 times, most recently from 2eb8da5 to fd97991 Compare November 15, 2026 13:54
@plusplusjiajia
plusplusjiajia force-pushed the fix/python-format-table-partition-paths branch 2 times, most recently from f89466a to 5c9e1ae Compare November 16, 2026 01:39
@skyyyy955

Copy link
Copy Markdown
Contributor

Thanks for looking into #11164. I tested a three-row Parquet format table using the JDK 11 and JDK 21 directory names for the same FLOAT value. A full scan reads all three rows on master. On 5c9e1ae, it fails on pt=2.68873286E11 with Partition value cannot be cast to FLOAT due to precision loss. Filtering for that value returns only the row in the JDK 21 directory. Would it help if I added this case to the PR tests?

@plusplusjiajia
plusplusjiajia force-pushed the fix/python-format-table-partition-paths branch 11 times, most recently from ed165c8 to 2842b36 Compare November 24, 2026 09:26
@plusplusjiajia
plusplusjiajia force-pushed the fix/python-format-table-partition-paths branch from 2842b36 to 3fed644 Compare November 27, 2026 11:00
@plusplusjiajia
plusplusjiajia force-pushed the fix/python-format-table-partition-paths branch from 3fed644 to 2a47771 Compare November 30, 2026 03:50
@plusplusjiajia

Copy link
Copy Markdown
Member Author

@skyyyy955 Thanks for testing. This is fixed now: a read takes both JDKs' names of a FLOAT value as one partition, and a filter on the value returns the rows of both directories. test_format_reads_float_partition_names_of_either_jdk covers this case, so there is no need to add it.

@plusplusjiajia
plusplusjiajia force-pushed the fix/python-format-table-partition-paths branch 10 times, most recently from 66a07c3 to 17308bf Compare November 30, 2026 09:39
plusplusjiajia and others added 3 commits November 30, 2026 01:40
PyPaimon's format table writer stopped the partition path at the first
null value, did not escape keys or values, and formatted some values
with Python's str(), so for example a value 'a/b' created two directory
levels and a null value put the file at a shorter path. Java readers
read such files with wrong partition values, and PyPaimon read Java
paths without unescaping them.

As in Java FormatTableFileWriter and PartitionPathUtils, the writer now
formats values like Java's partition computer, escapes keys and values,
writes null values as the default partition name, and rejects values
that a value-only layout would hide. As in Java FormatTableWrite,
partition columns are left out of the data files. CSV and JSON files
of a table whose columns are all partition columns keep them, since a
file without columns loses its rows, and the other formats refuse such
a table. Those files store null for a blank value, which names the
default partition, so a read returns what a partition filter finds.
The reader unescapes keys and values, reads the default partition name as null and skips
directories that are not partition directories, as Java does; older
files that contain partition columns still read their own values.

Equality partition filters now compare typed values, so they match the
new directory names, and partition columns read with the table's types
whether or not a file contains them. A static overwrite compares
directory names, so a spec such as 'true', '1.0' or the default
partition name clears the partition written for True, 1.00 or a null or
blank value, NaN clears the NaN partition, and 0.0 does not clear -0.0.
A static overwrite or partition filter whose value does not convert to
the partition type, such as a DECIMAL overflow, is refused instead of
selecting the null partition.
The value formatting is shared with the path factory of normal tables.

Since the files leave the partition columns out, a read takes the
partition values from the directory names, as filters and overwrites
do for every table. The writer refuses a value whose name reads back
as another value, such as non-UTF-8 BINARY, a local time in a DST
overlap, or a value equal to the default partition name, which names
the null partition; a static overwrite value is checked the same way,
since it would select the other value's directory, and a typed static
value takes the partition type's form, as rows do, so Decimal('1.0')
selects the directory 1.00 of a DECIMAL(4, 2) partition. The writer checks
every partition of the input before an overwrite deletes any file, so
a rejected value does not clear the partitions that precede it.

A row whose only column in a CSV file is null is an empty line, so CSV
reads keep empty lines unless csv.skip-empty-lines is set, as Java
does. CSV null handling is otherwise unchanged; a null STRING still
reads back as an empty string, as before, until the CSV writer and
reader share Java's null representation. CSV and JSON files infer
their column types, so a column of only nulls infers the null type;
their data columns are read with the declared types, which lets such
files be read together with the others.

Tables written by earlier PyPaimon versions keep working. Those
versions named directories with str() of the values, without escaping,
stopped the path at the first null value and kept the partition
columns in the files, so a file that has partition columns carries its
own values. Reads take those values; a directory that only an earlier
version writes, such as pt=a=b for 'a=b', is read, though Java skips
it. A partition filter matches a directory by its escaped or its
earlier unescaped name, keeps the rows of files with partition columns
by their own values, and also reads the files that earlier versions
left above the partition depth for null values. An overwrite deletes
only the partition's files: in the partition's directory, files
without partition columns and, when the name was escaped and so may be
an earlier name of another value, such as pt=a%3Ab for 'a%3Ab', files
whose partition columns hold only the partition's values; and at the
earlier version's path of the partition, such as pt=True, files whose
partition columns hold only its values. Subdirectories, such as the
earlier pt=x/y, are left alone.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…lter earlier TEXT directories by their values

- An overwrite deleted a partition's files before it wrote the new ones,
  and read an earlier version's file only after it had deleted the files
  of the partition's own directory. A file that it could not read, or a
  write that failed, left the partition without its old rows and without
  the new ones. The overwrite now finds and checks the files it replaces
  before it writes anything, and deletes them after the new files are
  written. A file that fails to write, and the new files written before
  it, are deleted, so a failure leaves the old files.
- A partition filter read no rows of an earlier version's TEXT
  directory, such as pt=a=b or pt=, which a read of the whole table
  takes as 'a=b' and ''. Such a directory now matches by those values.
- An overwrite of FLOAT or DOUBLE partitions listed and parsed the
  parent directory once per partition to find the other JDK's names,
  which took quadratic time: about 66 seconds for 1000 partitions. The
  directories are now indexed by value once per write; the files of
  other names are still read to check that they are the partition's.
- _partition_from_row and _delete_data_files_in_path have no callers.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ions

An overwrite looked for a partition's earlier files where earlier
versions could have written them: directories named with str() of the
values, paths stopped at a null value, directories of blank values, and
the other JDK's names of FLOAT and DOUBLE values. Each of these layouts
had cases that left the old rows next to the new ones or read the same
files once per partition.

An overwrite now replaces the files of the partition's directory, and
refuses a table that holds files of earlier versions before it writes
or deletes anything. It lists the table's directories once a write and
refuses a file above the partition depth or in a directory that this
version would not name so, taking the names as the scan found them. A
directory that is also an earlier name of another value, such as
pt=a%3Ab of 'a:b' and of 'a%3Ab', must hold only its partition's rows,
and the earlier directory of the partition no rows of it; these are
checked for every partition of the input before any is written. Java's
names of FLOAT values, where they are not the exact value that this
version writes, are refused the same way. Reads, filters and appends of
such tables are unchanged. The check reads the footers of Parquet and ORC
files, and only the partition columns of a file that keeps them. It
takes the table's files as the scan lists them, without holding them.

Every file now reads every partition column, so that an earlier file
above the partition depth, which has no value for the keys where its
path stopped, reads null for them and concatenates with the others. A
CSV file that keeps its partition columns reads an unquoted empty field,
or one that is csv.null-literal, as null, as Java's reader takes the
literal, and a quoted field as its text.

Static partitions and partition filters convert a Python value in one
way: only to the same value of the partition type, and a float also to
the FLOAT that it spells, as Python has no single-precision literal. A
static partition such as 1.5 of an INT no longer selects the partition
of 1, and a filter of 0.1 selects that of 0.1f, as '0.1' does. A NumPy
scalar, such as an element of a pandas Series, converts as the Python
value it holds.

A file's partition values come from its partition columns where it
keeps them, wherever it is, such as ('x/y', None) that earlier versions
wrote to a=x/y; else from its directories, with null for the keys past
its depth, where earlier versions stopped the path at a null value. A
file without them below a directory that names no key, inside a
partition directory, belongs to no partition that a read can tell, and
Java skips it. A filter selects the rows by the values that the read
takes: those of a file that keeps its partition columns by matching
each distinct value once, floats by their bits so that 0.0 and -0.0
stay apart.

Files leave the partition columns out, so a batch of only partition
columns would write files without columns, which lose their rows. A
nullable column that a batch leaves out is written as null, and a batch
without a NOT NULL column, or with duplicate columns, is refused before
any file is written. The columns take the table's order, which Java's
CSV reader takes by position; other columns follow, as before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@plusplusjiajia
plusplusjiajia force-pushed the fix/python-format-table-partition-paths branch from 17308bf to 55bc8ee Compare November 30, 2026 09:46
@plusplusjiajia
plusplusjiajia marked this pull request as ready for review November 30, 2026 09:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants