Implementation:Lance format Lance Java ColumnAlteration
| Knowledge Sources | |
|---|---|
| Domains | Java_SDK, Dataset_Management |
| Last Updated | 2026-02-08 19:33 GMT |
Overview
Description
The ColumnAlteration class represents a set of modifications to apply to a specific column in a Lance dataset. It supports three types of alterations: renaming a column, changing its nullability, and casting it to a different Arrow data type. Each alteration is optional and identified by a column path string.
The class uses a builder pattern where the Builder constructor requires the column path. The builder directly modifies the internal ColumnAlteration instance's optional fields, making the build step lightweight. Multiple alterations can be combined on the same column in a single ColumnAlteration instance.
Usage
Use ColumnAlteration to alter existing columns in a Lance dataset schema. Combine multiple alterations (rename, nullable, cast) in one object for atomic application. This is typically submitted as part of a dataset alter-columns operation.
Code Reference
Source Location
java/src/main/java/org/lance/schema/ColumnAlteration.java
Signature
public class ColumnAlteration {
public String getPath();
public Optional<String> getRename();
public Optional<Boolean> getNullable();
public Optional<ArrowType> getDataType();
public static class Builder {
public Builder(String path);
public Builder rename(String rename);
public Builder nullable(boolean nullable);
public Builder castTo(ArrowType dataType);
public ColumnAlteration build();
}
}
Import
import org.lance.schema.ColumnAlteration;
I/O Contract
| Parameter | Type | Required | Description |
|---|---|---|---|
| path | String |
Yes | The column path identifying the column to alter |
| rename | String |
No | New name for the column |
| nullable | boolean |
No | Whether the column should be nullable |
| castTo | ArrowType |
No | Target Arrow data type for type casting |
| Method | Return Type | Description |
|---|---|---|
| getPath() | String |
The column path |
| getRename() | Optional<String> |
The new column name, if set |
| getNullable() | Optional<Boolean> |
The new nullability, if set |
| getDataType() | Optional<ArrowType> |
The target data type for casting, if set |
Usage Examples
// Rename a column
ColumnAlteration rename = new ColumnAlteration.Builder("old_name")
.rename("new_name")
.build();
// Make a column nullable
ColumnAlteration makeNullable = new ColumnAlteration.Builder("required_field")
.nullable(true)
.build();
// Cast a column to a different type
ColumnAlteration castType = new ColumnAlteration.Builder("score")
.castTo(new ArrowType.FloatingPoint(FloatingPointPrecision.DOUBLE))
.build();
// Combine multiple alterations on the same column
ColumnAlteration combined = new ColumnAlteration.Builder("amount")
.rename("total_amount")
.nullable(true)
.castTo(new ArrowType.FloatingPoint(FloatingPointPrecision.DOUBLE))
.build();
Related Pages
- Lance_format_Lance_Java_ProjectOp -- Changes schema without modifying data (column removal, reordering)
- Lance_format_Lance_Java_LanceField -- Lance field representation with type information
- Lance_format_Lance_Java_LanceSchema -- Lance schema containing fields and metadata