Skip to content

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

Draft
plusplusjiajia wants to merge 1 commit into
apache:masterfrom
plusplusjiajia:fix/python-format-table-partition-paths
Draft

plusplusjiajia wants to merge 1 commit 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.
  • Reader: unescapes directory names, reads the default partition name as null, and skips non-partition directories.
  • 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.

Compatibility

  • Tables written by earlier PyPaimon versions, which named directories with str() and kept partition columns in the files, need no migration: reads, filters and overwrites still find their files. 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. 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; #11173 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, tables written by earlier versions, 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?

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>
@plusplusjiajia
plusplusjiajia force-pushed the fix/python-format-table-partition-paths branch from 2842b36 to 3fed644 Compare November 27, 2026 11:00
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