Implementation:Lance format Lance Java RewriteOp
| Knowledge Sources | |
|---|---|
| Domains | Java_SDK, Dataset_Management |
| Last Updated | 2026-02-08 19:33 GMT |
Overview
Description
The Rewrite class is an immutable operation for reorganizing data within a Lance dataset without changing its logical content. It implements the Operation interface and is the primary mechanism for data compaction and reordering. Because the operation modifies the physical addresses of existing rows, any vector or scalar indices that cover the rewritten fragments must be remapped.
The operation contains three components: a list of RewriteGroup objects (each mapping old fragments to new fragments), a list of RewrittenIndex objects (tracking index remapping), and an optional Index for fragment reuse optimization. All lists default to empty when not set.
Usage
Use Rewrite for compaction operations that consolidate small fragments into larger ones, remove deleted row tombstones, or physically reorder data for improved scan performance. After a rewrite, affected indices are remapped using the rewrittenIndices list.
Code Reference
Source Location
java/src/main/java/org/lance/operation/Rewrite.java
Signature
public class Rewrite implements Operation {
public static Builder builder();
public List<RewriteGroup> groups();
public List<RewrittenIndex> rewrittenIndices();
public Optional<Index> fragReuseIndex();
public String name(); // returns "Rewrite"
}
Import
import org.lance.operation.Rewrite;
I/O Contract
| Parameter | Type | Required | Description |
|---|---|---|---|
| groups | List<RewriteGroup> |
No | Groups mapping old fragments to new fragments (defaults to empty) |
| rewrittenIndices | List<RewrittenIndex> |
No | Index remapping entries for affected indices (defaults to empty) |
| fragReuseIndex | Index |
No | Optional index for fragment reuse optimization |
| Return | Type | Description |
|---|---|---|
| groups() | List<RewriteGroup> |
The rewrite groups mapping old to new fragments |
| rewrittenIndices() | List<RewrittenIndex> |
Index remapping entries |
| fragReuseIndex() | Optional<Index> |
The fragment reuse index, if present |
| name() | String |
Returns "Rewrite" for JNI dispatch
|
Usage Examples
// Compact fragments: merge old fragments into new, larger fragments
RewriteGroup group = new RewriteGroup(oldFragments, newFragments);
Rewrite rewriteOp = Rewrite.builder()
.groups(List.of(group))
.rewrittenIndices(List.of(remappedIndex))
.build();
String opName = rewriteOp.name(); // "Rewrite"
List<RewriteGroup> groups = rewriteOp.groups();
Related Pages
- Lance_format_Lance_Java_CreateIndexOp -- Creates or replaces indices (may follow a rewrite)
- Lance_format_Lance_Java_AppendOp -- Appends data (may cause fragmentation that rewrite consolidates)
- Lance_format_Lance_Java_DataReplacementOp -- Replaces column data within fragments