JingsongLi commented on code in PR #11346:
URL: https://github.com/apache/paimon/pull/11346#discussion_r4662650687


##########
docs/docs/spark/sql-query.md:
##########
@@ -245,6 +245,31 @@ Scans below expressions using `input_file_name()`, 
`input_file_block_start()`, o
 `input_file_block_length()` are skipped: these functions need the source 
reader's
 task-local file context, which is not carried through a shuffle.
 
+### 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
+PyPaimon writer recorded a finite file maximum for a file containing `NaN`.
+The Paimon scan can skip that file based on its recorded maximum.
+
+For an affected snapshot, repartition the query input before sorting to keep
+TopN in Spark above the shuffle. Replace the table name and snapshot ID in
+this example with the ones you want to read.
+
+```sql
+CREATE OR REPLACE TEMP VIEW scores_for_sort AS
+SELECT /*+ REPARTITION(1) */ score

Review 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.



##########
docs/docs/spark/sql-query.md:
##########
@@ -245,6 +245,31 @@ Scans below expressions using `input_file_name()`, 
`input_file_block_start()`, o
 `input_file_block_length()` are skipped: these functions need the source 
reader's
 task-local file context, which is not carried through a shuffle.
 
+### 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

Review 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.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to