helix_ir.transform

helix_ir.transform — lazy transformation DSL.

class helix_ir.transform.Table(source_name: str, schema: Schema | None = None)[source]

Bases: object

A lazy relational table backed by a LogicalPlan.

Operations return new Table instances without executing queries. Call .to_sql() to compile or .to_arrow() to execute via DuckDB.

filter(predicate: Expression) Table[source]

Filter rows by a predicate expression.

where(predicate: Expression) Table[source]

Alias for filter().

select(*exprs: Expression) Table[source]

Select specific columns.

with_column(name: str, expr: Expression) Table[source]

Add or replace a column.

drop(*columns: str) Table[source]

Drop columns by name.

rename(**mapping: str) Table[source]

Rename columns: rename(old_name=’new_name’).

sort(*exprs: Expression | SortExpr) Table[source]

Sort by expressions.

order_by(*exprs: Expression | SortExpr) Table[source]

Alias for sort().

limit(n: int, offset: int = 0) Table[source]

Limit to n rows, with optional offset.

head(n: int = 5) Table[source]

Return first n rows.

group_by(*exprs: Expression) operators.GroupedTable[source]

Group by expressions — returns a GroupedTable for .agg().

join(other: Table, on: Expression, how: str = 'inner') Table[source]

Join with another table.

union(other: Table, all: bool = True) Table[source]

Union with another table.

distinct() Table[source]

Return distinct rows (wraps in a SELECT DISTINCT).

to_sql(dialect: str = 'duckdb') str[source]

Compile this table to a SQL SELECT statement.

to_arrow() Table[source]

Execute this query via DuckDB and return a PyArrow Table.

helix_ir.transform.col(name: str, table: str | None = None) Column[source]

Create a Column reference.

helix_ir.transform.lit(value: Any) Literal[source]

Create a Literal value.

helix_ir.transform.star() StarExpr[source]

Create a SELECT * expression.

helix_ir.transform.sum_(expr: Expression | str) FunctionExpr[source]

SUM aggregate.

helix_ir.transform.avg_(expr: Expression | str) FunctionExpr[source]

AVG aggregate.

helix_ir.transform.min_(expr: Expression | str) FunctionExpr[source]

MIN aggregate.

helix_ir.transform.max_(expr: Expression | str) FunctionExpr[source]

MAX aggregate.

helix_ir.transform.count_(expr: Expression | str = '*') FunctionExpr[source]

COUNT aggregate.

helix_ir.transform.count_distinct_(expr: Expression | str) FunctionExpr[source]

COUNT(DISTINCT …) aggregate.

helix_ir.transform.coalesce(*exprs: Expression | str) FunctionExpr[source]

COALESCE function.

helix_ir.transform.concat(*exprs: Expression | str) FunctionExpr[source]

CONCAT function.

helix_ir.transform.date_trunc(unit: str, expr: Expression | str) FunctionExpr[source]

DATE_TRUNC function.

helix_ir.transform.length(expr: Expression | str) FunctionExpr[source]

LENGTH/LEN string function.