Repository navigation
[doc] Document Spark TopN with NaN file statistics - #11346
Conversation
JingsongLi
left a comment
There was a problem hiding this comment.
The guide addresses a real wrong-result case. I built the documentation and reproduced 10.0 with pushed TopN and NaN with the documented hint on an old snapshot. Two separate checks found a current writer configuration that is still affected and a workaround without a single-partition exchange.
| ### TopN on Older PyPaimon Snapshots | ||
|
|
||
| Spark sorts `NaN` above all numeric values. In Spark 3.5.9, a descending | ||
| `ORDER BY ... LIMIT` on a floating-point column can miss `NaN` if an older |
There was a problem hiding this comment.
[P2] Describe the affected file bounds independently of snapshot age. On current master ae135d59c9, the default NativeBatchTableWrite path with supported pypaimon-rust==0.5.0 still stored a finite maximum of 1.0 for a new Parquet file containing [NaN, 1.0]. With that file and a [10.0] file in separate splits, Spark 3.5.9 returned 10.0 with TopN pushed down. The same current checkout with Python writing and committing forced returned NaN. Please mention the affected native writer configuration as well as historical files.
|
|
||
| ```sql | ||
| CREATE OR REPLACE TEMP VIEW scores_for_sort AS | ||
| SELECT /*+ REPARTITION(1) */ score |
There was a problem hiding this comment.
[P2] Keep the workaround distributed on large snapshots. The documented hint returned NaN in my replay and the physical plan showed Exchange SinglePartition, which sends every candidate row to one task before sorting. I also verified ORDER BY isnan(score) DESC, score DESC LIMIT 1 on the same Spark 3.5.9 table. It returned NaN with TakeOrderedAndProject, no pushed TopN and no single-partition exchange. This ordering preserves Spark's NaN-first descending behavior and gives operators a way to avoid gathering the entire input.
There was a problem hiding this comment.
Thanks for checking the physical plan. I replaced the repartition hint with ORDER BY isnan(score) DESC, score DESC LIMIT 1 and added an EXPLAIN EXTENDED check for TakeOrderedAndProject and the absence of TopN: on the Paimon scan. Documentation CI passed.
Purpose
Document why descending TopN can miss
NaNwhen a file has a finite recorded maximum. This can affect historical PyPaimon files and new files created by the native batch writer withpypaimon-rust0.5.0. The guide now addsisnan(score)to the sort order so Spark can choose candidates per partition. Reproduction and discussionTests
10.0with TopN pushed down andNaNwhen Spark sorted both files.NaNwithTakeOrderedAndProject. The plan had no Paimon TopN pushdown or single-partition exchange gathering all input. Writer check · Plan check