ColumnRef
The ColumnRef class provides a fluent API for building column expressions.
Overview
ColumnRef is returned by the col() function and provides chainable methods for creating expressions.
import { col } from "molniya";
// Create a column reference
const priceCol = col("price");
// Chain methods to build expressions
priceCol.mul(1.1).add(col("tax"));Creating Column References
col()
col(name: string): ColumnRefExample:
import { col } from "molniya";
col("id")
col("customer_name")
col("total_amount")Comparison Methods
eq()
Equal comparison.
eq(other: Expr | number | string | boolean): ComparisonExprExample:
col("status").eq("active")
col("id").eq(123)
col("verified").eq(true)neq()
Not equal comparison.
neq(other: Expr | number | string | boolean): ComparisonExprExample:
col("status").neq("deleted")
col("id").neq(0)gt()
Greater than.
gt(other: Expr | number): ComparisonExprExample:
col("age").gt(18)
col("price").gt(100)gte()
Greater than or equal.
gte(other: Expr | number): ComparisonExprExample:
col("score").gte(60) // Passing grade
col("balance").gte(0) // Non-negativelt()
Less than.
lt(other: Expr | number): ComparisonExprExample:
col("age").lt(65)
col("temperature").lt(100)lte()
Less than or equal.
lte(other: Expr | number): ComparisonExprExample:
col("price").lte(50) // Budget itemsbetween()
Check if value is within a range (inclusive).
between(low: Expr | number, high: Expr | number): BetweenExprExample:
col("age").between(18, 65)
col("score").between(0, 100)Null Check Methods
isNull()
Check if value is null.
isNull(): NullCheckExprExample:
col("email").isNull()isNotNull()
Check if value is not null.
isNotNull(): NullCheckExprExample:
col("email").isNotNull()Arithmetic Methods
add()
Add to another expression.
add(other: Expr | number): ArithmeticExprExample:
col("price").add(col("tax"))
col("score").add(10) // Bonus pointssub()
Subtract another expression.
sub(other: Expr | number): ArithmeticExprExample:
col("total").sub(col("discount"))mul()
Multiply by another expression.
mul(other: Expr | number): ArithmeticExprExample:
col("price").mul(0.9) // 10% discount
col("price").mul(col("quantity"))div()
Divide by another expression.
div(other: Expr | number): ArithmeticExprExample:
col("total").div(col("count")) // Averagemod()
Modulo (remainder) operation.
mod(other: Expr | number): ArithmeticExprExample:
col("n").mod(2) // Check even/oddneg()
Negate the value.
neg(): NegExprExample:
col("debt").neg() // Negative debt = creditString Methods
contains()
Check if string contains a pattern.
contains(pattern: string): StringOpExprExample:
col("email").contains("@gmail.com")
col("description").contains("urgent")startsWith()
Check if string starts with a pattern.
startsWith(pattern: string): StringOpExprExample:
col("name").startsWith("Dr.")
col("phone").startsWith("+1")endsWith()
Check if string ends with a pattern.
endsWith(pattern: string): StringOpExprExample:
col("email").endsWith("@company.com")
col("file").endsWith(".pdf")Utility Methods
alias()
Create an aliased expression (for renaming in aggregations).
alias(name: string): AliasExprExample:
// In aggregation context
df.groupBy("category", [
{ name: "total", expr: col("amount").sum().alias("total_amount") }
])cast()
Cast to a different type.
cast(targetDType: DTypeKind): CastExprExample:
import { DTypeKind } from "molniya";
col("id").cast(DTypeKind.Int64)
col("price").cast(DTypeKind.Float64)toExpr()
Get the underlying expression (rarely needed directly).
toExpr(): ColumnExprExample:
const expr = col("id").toExpr();Chaining Examples
Complex Filter
df.filter(
col("age")
.gte(18)
.and(col("age").lt(65))
.and(col("active").eq(true))
)Calculated Column
df.withColumn(
"discounted_total",
col("price")
.mul(col("quantity"))
.mul(col("discount"))
.add(col("tax"))
)String Matching
df.filter(
col("email")
.contains("@")
.and(col("email").endsWith(".com"))
)Method Equivalents
ColumnRef methods have equivalent standalone functions:
// These are equivalent:
col("a").add(col("b"))
add(col("a"), col("b"))
// These are equivalent:
col("a").gt(5)
gt(col("a"), 5)Use whichever style you prefer. The ColumnRef methods are often more readable for chaining.