Implementation:Lance format Lance Java SqlExpressions
| Knowledge Sources | |
|---|---|
| Domains | Java_SDK, Dataset_Management |
| Last Updated | 2026-02-08 19:33 GMT |
Overview
Description
The SqlExpressions class represents a list of named SQL expressions for computed column generation. Each expression consists of a name (the target column name) and an expression (a SQL expression string that can reference existing columns in the dataset). The evaluated expression becomes the value of the new column.
The class uses an immutable outer container with an inner SqlExpression class that follows the JavaBean pattern (getter/setter). The Builder provides a fluent withExpression(name, expr) method that creates and appends SqlExpression entries incrementally.
Usage
Use SqlExpressions to define computed columns when adding new columns to a Lance dataset. Each expression is evaluated against existing dataset columns to produce new column values. This is commonly used with update or add-column operations.
Code Reference
Source Location
java/src/main/java/org/lance/schema/SqlExpressions.java
Signature
public class SqlExpressions {
public List<SqlExpression> getSqlExpressions();
public static class SqlExpression {
public String getName();
public void setName(String name);
public String getExpression();
public void setExpression(String expression);
}
public static class Builder {
public Builder();
public Builder withExpression(String name, String expr);
public SqlExpressions build();
}
}
Import
import org.lance.schema.SqlExpressions;
import org.lance.schema.SqlExpressions.SqlExpression;
I/O Contract
| Parameter | Type | Required | Description |
|---|---|---|---|
| name | String |
Yes | The name for the new computed column |
| expr | String |
Yes | SQL expression string referencing existing dataset columns |
| Method | Return Type | Description |
|---|---|---|
| getSqlExpressions() | List<SqlExpression> |
The list of named SQL expressions |
| Property | Type | Description |
|---|---|---|
| name | String |
Column name for the computed result |
| expression | String |
SQL expression evaluated against existing columns |
Usage Examples
// Define computed columns using SQL expressions
SqlExpressions expressions = new SqlExpressions.Builder()
.withExpression("full_name", "first_name || ' ' || last_name")
.withExpression("age_group", "CASE WHEN age < 18 THEN 'minor' ELSE 'adult' END")
.withExpression("score_normalized", "score / 100.0")
.build();
// Access individual expressions
for (SqlExpression expr : expressions.getSqlExpressions()) {
System.out.println(expr.getName() + " = " + expr.getExpression());
}
Related Pages
- Lance_format_Lance_Java_UpdateOp -- Update operation that may use SQL expressions for column values
- Lance_format_Lance_Java_MergeOp -- Merge operation for adding new columns to datasets
- Lance_format_Lance_Java_ColumnAlteration -- Alters column properties rather than computing new values