Skip to content

feat: support truncate table api#5604

Merged
wjones127 merged 9 commits intolance-format:mainfrom
zhangyue19921010:support-truncate
Jan 12, 2026
Merged

feat: support truncate table api#5604
wjones127 merged 9 commits intolance-format:mainfrom
zhangyue19921010:support-truncate

Conversation

@zhangyue19921010
Copy link
Copy Markdown
Contributor

@zhangyue19921010 zhangyue19921010 commented Dec 31, 2025

Semantics

  • Introduces truncate table to create a new snapshot version whose manifest has no fragments while preserving the existing schema and table config.
  • Acts as an overwrite-style commit for the latest version; does not physically delete historical data files.
  • After truncation, new data can be appended or the table can be restored to previous versions.

Differences vs Delete Rows

  • Delete Rows:
    • Soft-deletes rows by writing deletion files/vectors; existing fragments remain
  • Truncate Table:
    • Replaces the current version with an “empty fragments” version; no deletion files are produced and current-version fragments are not carried forward.
Rust:
ds.truncate_table().await.unwrap();

Python:
ds.truncate_table()

Java:
ds1.truncateTable()

@github-actions github-actions Bot added enhancement New feature or request python java labels Dec 31, 2025
@codecov
Copy link
Copy Markdown

codecov Bot commented Dec 31, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@wjones127
Copy link
Copy Markdown
Contributor

  • Soft-deletes rows by writing deletion files/vectors; existing fragments remain

This isn't true; if you delete an entire fragment it is removed from the list. If you delete all rows, all fragments are removed. So this is just equivalent to dataset.delete("true"). We even have a fast path for that 1. Is there any other reason to make a special operation for this?

Footnotes

  1. https://github.com/lance-format/lance/blob/0a8d618b5ec6ce6ac978aadced88a0061487f9ec/rust/lance/src/dataset/write/delete.rs#L182-L192

@wjones127 wjones127 self-assigned this Jan 1, 2026
@zhangyue19921010
Copy link
Copy Markdown
Contributor Author

Hi, thanks a lot for your attention @wjones127 ! The addition of support for Truncate table here is mainly intended to supplement the TRUNCATE TABLE related to standard SQL (SQL:2008) at the syntax level, making it more user-friendly for those analysts accustomed to using TRUNCATE TABLE command.

Of course, As u mentioned, Lance users can also use delete("true") and complete it quickly based on the fast path in the code.

@wjones127
Copy link
Copy Markdown
Contributor

Okay, I get that it's a more familiar API. Could you change the implementation to just be a simple wrapper around delete("true") then?

@zhangyue19921010
Copy link
Copy Markdown
Contributor Author

Okay, I get that it's a more familiar API. Could you change the implementation to just be a simple wrapper around delete("true") then?

Sure thing. Changed. PTAL ~

@zhangyue19921010
Copy link
Copy Markdown
Contributor Author

Hi @wjones127 would u mind to take another look? Thanks :) I have finished that a simple wrapper around delete("true")

Copy link
Copy Markdown
Contributor

@wjones127 wjones127 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

@wjones127 wjones127 merged commit af48840 into lance-format:main Jan 12, 2026
26 of 27 checks passed
jackye1995 pushed a commit to jackye1995/lance that referenced this pull request Jan 21, 2026
Semantics
- Introduces **truncate table** to create a new snapshot version whose
manifest has no fragments while preserving the existing schema and table
config.
- Acts as an overwrite-style commit for the latest version; does not
physically delete historical data files.
- After truncation, new data can be appended or the table can be
restored to previous versions.


Differences vs Delete Rows

- Delete Rows:
- Soft-deletes rows by writing deletion files/vectors; existing
fragments remain
- Truncate Table:
- Replaces the current version with an “empty fragments” version; no
deletion files are produced and current-version fragments are not
carried forward.

```
Rust:
ds.truncate_table().await.unwrap();

Python:
ds.truncate_table()

Java:
ds1.truncateTable()

```

---------

Co-authored-by: Will Jones <willjones127@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request java python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants