Repository navigation
Description
Search before asking
- I searched the existing issues. [Bug] PyPaimon system table filters lose nanoseconds in timestamp literals #11305 reports a loss of precision in timestamp literals on system tables. This report concerns timestamp values read from an append-only data table.
Paimon version
Apache Paimon 2.2-SNAPSHOT
Compute Engine
PyPaimon with the Python planner and reader, Python 3.13.2, PyArrow 22.0.0, pandas 2.3.3, Polars 1.44.2.
Minimal reproduce step
Write two rows whose timestamps differ by one nanosecond. Both rows have name = 'keep', so adding AND name LIKE 'k%p' should preserve the result of each timestamp equality filter.
from tempfile import TemporaryDirectory
import pandas as pd
import pyarrow as pa
from pypaimon import CatalogFactory, Schema
def read_ids(table, predicate):
read = table.new_read_builder().with_filter(predicate).with_projection(["id"])
splits = read.new_scan().plan().splits()
return read.new_read().to_arrow(splits)["id"].to_pylist()
with TemporaryDirectory() as warehouse:
catalog = CatalogFactory.create({"warehouse": warehouse})
catalog.create_database("db", False)
t = pd.Timestamp("2026-01-01").value
data = pa.table({
"id": [1, 2],
"name": ["keep", "keep"],
"ts": pa.array([t, t + 1], type=pa.timestamp("ns")),
})
schema = Schema.from_pyarrow_schema(data.schema, options={
"file.format": "parquet",
"scan.native-plan.enabled": "false",
"read.native.enabled": "false",
})
catalog.create_table("db.events", schema, False)
table = catalog.get_table("db.events")
batch = table.new_batch_write_builder()
writer, commit = batch.new_write(), batch.new_commit()
try:
writer.write_arrow(data)
commit.commit(writer.prepare_commit())
finally:
writer.close()
commit.close()
pb = table.new_read_builder().new_predicate_builder()
for offset in (0, 1):
eq = pb.equal("ts", pd.Timestamp(t + offset, unit="ns"))
with_like = pb.and_predicates([pb.like("name", "k%p"), eq])
print(f"t+{offset}ns equality={read_ids(table, eq)} with_like={read_ids(table, with_like)}")Actual output
t+0ns equality=[1] with_like=[1, 2]
t+1ns equality=[2] with_like=[]
What doesn't meet your expectations?
The query for t should return [1], and the query for t + 1 ns should return [2]. Timestamp equality alone returns both expected results. Adding LIKE makes row 2 match the first timestamp and disappear from the query for its own timestamp.
Anything else?
The Parquet file stores two distinct nanosecond values, 1767225600000000000 and 1767225600000000001. The wildcard LIKE causes the Python reader to evaluate the compound predicate row by row. During that step, Polars iter_rows() converts both column values to the same microsecond-precision Python datetime. The equality check therefore sees the same timestamp for both rows.
Are you willing to submit a PR?
- I'm willing to submit a PR!
Activity