AvailableExpression 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
| Function | Signature | Description |
col(name) | col(name: str) -> Column | Reference a column by name. |
column(name) | column(name: str) -> Column | Alias for col. |
lit(value) | lit(value: Any) -> Column | Constant literal value (int, float, str, bool, None). |
expr(sql) | expr(sql: str) -> Column | Parse a SQL expression string into a Column. |
call_function(name, *args) | Column | Call a named SQL function or UDF with Column arguments. |
function(name, *args) | Column | Alias for call_function. |
Aggregate Functions
| Function | Description |
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
| Function | Description |
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
| Function | Description |
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
| Function | Description |
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
| Function | Description |
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
| Function | Description |
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. |