ProductDocsArchitectureBlogGitHubGitHubGet Started
Available

Expression Functions

col, lit, expr, aggregate and scalar functions in krishiv.functions.

Overview

Import from krishiv.functions or krishiv.sql.functions:

from krishiv.functions import col, lit, sum, avg, count, expr
from krishiv.sql.functions import upper, lower, date_trunc, coalesce

Column and Literal

FunctionSignatureDescription
col(name)col(name: str) -> ColumnReference a column by name.
column(name)column(name: str) -> ColumnAlias for col.
lit(value)lit(value: Any) -> ColumnConstant literal value (int, float, str, bool, None).
expr(sql)expr(sql: str) -> ColumnParse a SQL expression string into a Column.
call_function(name, *args)ColumnCall a named SQL function or UDF with Column arguments.
function(name, *args)ColumnAlias for call_function.

Aggregate Functions

FunctionDescription
count(col='*')Count rows or non-null values of a column.
count_all()COUNT(*) — count all rows.
sum(col)Sum of numeric values.
avg(col)Arithmetic mean.
mean(col)Alias for avg.
min(col)Minimum value.
max(col)Maximum value.

Null / Conditional

FunctionDescription
coalesce(*cols)Return the first non-null value.
ifnull(value, replacement)Return replacement if value is null.
nullif(left, right)Return null if left == right, else left.
isnull(col)True if the column is null.
isnotnull(col)True if the column is not null.
isnan(col)True if the value is NaN.

String Functions

FunctionDescription
upper(col)Convert to uppercase.
lower(col)Convert to lowercase.
length(col)String length (character count).
trim(col)Strip leading and trailing whitespace.
ltrim(col)Strip leading whitespace.
rtrim(col)Strip trailing whitespace.
concat(*cols)Concatenate strings.

Math Functions

FunctionDescription
abs(col)Absolute value.
round(col, scale=0)Round to scale decimal places.
floor(col)Floor (round down to integer).
ceil(col)Ceiling (round up to integer).
sqrt(col)Square root.
exp(col)e raised to the power of col.
log(col)Natural logarithm.
sin(col)Sine (radians).
cos(col)Cosine (radians).
tan(col)Tangent (radians).

Date/Time Functions

FunctionDescription
current_date()Current date (evaluates at query planning time).
current_timestamp()Current timestamp.
date_trunc(unit, timestamp)Truncate to a time unit ('year', 'month', 'day', 'hour', 'minute', 'second').

Sort and Cast

FunctionDescription
asc(col)Wrap column in ascending sort order.
desc(col)Wrap column in descending sort order.
cast(col, data_type)Cast column to data_type string (e.g. 'int64', 'utf8').
try_cast(col, data_type)Cast returning null on failure instead of erroring.