sundapeng opened a new issue, #862:
URL: https://github.com/apache/paimon-rust/issues/862

   ### Search before asking
   
   - [x] I searched in the 
[issues](https://github.com/apache/paimon-rust/issues) and found nothing 
similar.
   
   ### Please describe the bug 🐞
   
   `TRUNCATE TABLE` on a Format Table returns success, but no file is deleted 
and every row is still there. The same happens with `TRUNCATE TABLE ... 
PARTITION (...)`, for tables with and without catalog-managed partitions.
   
   ```sql
   CREATE TABLE paimon.db.t (id BIGINT, dt STRING) PARTITIONED BY (dt)
   WITH ('type' = 'format-table', 'file.format' = 'parquet', 
'metastore.partitioned-table' = 'true');
   -- another engine writes rows into dt=a and dt=b
   TRUNCATE TABLE paimon.db.t;          -- OK
   SELECT COUNT(*) FROM paimon.db.t;    -- still returns every row
   ```
   
   `SQLContext::handle_truncate_table` does not look at the table type. It 
opens a `TableCommit` and calls `truncate_table` / `truncate_partitions`, which 
is an OVERWRITE snapshot commit. A Format Table has no snapshot, so the commit 
resolves no entries and returns `Ok` without doing anything. 
`TableCommit::truncate_table` in the C and Go bindings has the same silent 
success.
   
   Java supports TRUNCATE on format tables since apache/paimon#9330 
(`FormatTableCommit#truncateTable` and `#truncatePartitions`), so a table 
written by Spark can be truncated from Spark but not from the Rust client.
   
   ### Solution
   
   Follow the Java semantics:
   
   - delete data files only; partition directories and catalog registrations 
stay;
   - with catalog-managed partitions, empty the registered partitions and 
report zero statistics with `replaceStatistics=true`; a directory nobody 
registered is not touched;
   - without them, empty the partition directories found under the table;
   - keep staging entries such as `_temporary`, and delete other files whatever 
their extension, like Java;
   - make `TableCommit::truncate_*` refuse a Format Table instead of reporting 
success.
   
   ### Are you willing to submit a PR?
   
   - [x] I'm willing to submit a PR!
   


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