Skip to main content
Version: 2.0

Functions

A conforming Teckel implementation must support the core functions listed on this page. Functions are called with standard syntax: function_name(arg1, arg2, ...). Calls can be nested to arbitrary depth.

Aggregate Functions

Aggregate functions operate on a set of rows and return a single value. They are used in groupBy transformations and in select with grouping.

FunctionReturn TypeDescription
count(expr)integerCount of non-NULL values.
count(*)integerTotal row count, including NULLs.
count(DISTINCT expr)integerCount of distinct non-NULL values.
sum(expr)same as inputSum of non-NULL values. NULL if all inputs are NULL.
avg(expr)doubleAverage of non-NULL values. NULL if all inputs are NULL.
min(expr)same as inputMinimum non-NULL value. NULL if all inputs are NULL.
max(expr)same as inputMaximum non-NULL value. NULL if all inputs are NULL.

Examples

- asset:
ref: order_stats
source:
groupBy:
from: orders
grouping:
- "customer_id"
columns:
- "customer_id"
- "count(*) as total_orders"
- "count(DISTINCT product_id) as unique_products"
- "sum(amount) as total_spent"
- "avg(amount) as avg_order_value"
- "min(order_date) as first_order"
- "max(order_date) as last_order"

NULL Behavior in Aggregations

FunctionAll values NULLMix of NULL and non-NULL
count(expr)0Count of non-NULL values
count(*)Row countRow count
sum(expr)NULLSum of non-NULL values
avg(expr)NULLAverage of non-NULL values
min(expr)NULLMinimum of non-NULL values
max(expr)NULLMaximum of non-NULL values

String Functions

FunctionReturn TypeDescription
concat(expr, ...)stringConcatenate arguments. NULL if any argument is NULL.
upper(expr)stringConvert to uppercase.
lower(expr)stringConvert to lowercase.
trim(expr)stringRemove leading and trailing whitespace.
ltrim(expr)stringRemove leading whitespace.
rtrim(expr)stringRemove trailing whitespace.
length(expr)integerString length in characters.
substring(expr, start, len)stringExtract substring. Positions are 1-indexed.
replace(expr, search, replacement)stringReplace all occurrences of search with replacement.
coalesce(expr, ...)same as first non-NULLReturn the first non-NULL argument.

Examples

columns:
- "concat(first_name, ' ', last_name) as full_name"
- "upper(country_code) as country"
- "lower(email) as email_normalized"
- "trim(raw_input) as clean_input"
- "length(description) as desc_length"
- "substring(phone, 1, 3) as area_code"
- "replace(name, 'Corp.', 'Corporation') as name_full"
- "coalesce(nickname, first_name, 'Unknown') as display_name"

Nested string functions:

columns:
- "upper(trim(concat(first_name, ' ', last_name))) as full_name_upper"

Numeric Functions

FunctionReturn TypeDescription
abs(expr)same as inputAbsolute value.
round(expr, scale)same as inputRound to scale decimal places.
floor(expr)same as inputRound down to nearest integer.
ceil(expr)same as inputRound up to nearest integer.
power(base, exp)doubleExponentiation.
sqrt(expr)doubleSquare root.
mod(expr, divisor)same as inputModulo (equivalent to the % operator).

Examples

columns:
- "abs(balance) as absolute_balance"
- "round(price * tax_rate, 2) as tax_amount"
- "floor(rating) as rating_floor"
- "ceil(duration / 60.0) as duration_hours"
- "power(growth_rate, years) as compound_factor"
- "sqrt(variance) as std_deviation"
- "mod(row_id, 10) as partition_bucket"

Date/Time Functions

FunctionReturn TypeDescription
current_date()dateCurrent date at pipeline execution time.
current_timestamp()timestampCurrent timestamp at pipeline execution time.
year(expr)integerExtract the year component.
month(expr)integerExtract the month (1–12).
day(expr)integerExtract the day of month (1–31).
hour(expr)integerExtract the hour (0–23).
minute(expr)integerExtract the minute (0–59).
second(expr)integerExtract the second (0–59).
date_add(date, days)dateAdd a number of days to a date.
date_diff(end, start)integerNumber of days between two dates (end - start).
to_date(expr, format)dateParse a string into a date using the given format.
to_timestamp(expr, format)timestampParse a string into a timestamp using the given format.

Examples

columns:
- "current_date() as run_date"
- "current_timestamp() as run_timestamp"
- "year(order_date) as order_year"
- "month(order_date) as order_month"
- "day(order_date) as order_day"
- "hour(event_time) as event_hour"
- "date_add(start_date, 30) as due_date"
- "date_diff(end_date, start_date) as duration_days"
- "to_date(date_string, 'yyyy-MM-dd') as parsed_date"
- "to_timestamp(ts_string, 'yyyy-MM-dd HH:mm:ss') as parsed_ts"

Date extraction is commonly paired with grouping:

- asset:
ref: monthly_revenue
source:
groupBy:
from: orders
grouping:
- "year(order_date)"
- "month(order_date)"
columns:
- "year(order_date) as year"
- "month(order_date) as month"
- "sum(amount) as revenue"

Window Functions

Window functions compute values across a set of rows related to the current row without collapsing the result. They are used in window transformations with partitionBy and orderBy clauses.

FunctionReturn TypeDescription
row_number()integerSequential row number within the partition (1-based).
rank()integerRank within the partition. Rows with equal values receive the same rank; the next rank has a gap.
dense_rank()integerRank within the partition. No gaps between ranks for ties.
lag(expr, offset)same as inputValue from offset rows before the current row. NULL if out of range.
lead(expr, offset)same as inputValue from offset rows after the current row. NULL if out of range.
first_value(expr)same as inputFirst value in the window frame.
last_value(expr)same as inputLast value in the window frame.
ntile(n)integerDistributes rows into n approximately equal-sized buckets, numbered 1 through n.

Examples

- asset:
ref: ranked_employees
source:
window:
from: employees
columns:
- column: "row_number() as rn"
partitionBy:
- "department"
orderBy:
- column: "salary"
direction: desc
- asset:
ref: sales_with_context
source:
window:
from: daily_sales
columns:
- column: "lag(revenue, 1) as prev_day_revenue"
partitionBy:
- "store_id"
orderBy:
- column: "sale_date"
direction: asc
- column: "lead(revenue, 1) as next_day_revenue"
partitionBy:
- "store_id"
orderBy:
- column: "sale_date"
direction: asc
- asset:
ref: ranked_products
source:
window:
from: product_sales
columns:
- column: "rank() as sales_rank"
partitionBy:
- "category"
orderBy:
- column: "total_sold"
direction: desc
- column: "dense_rank() as dense_sales_rank"
partitionBy:
- "category"
orderBy:
- column: "total_sold"
direction: desc
- column: "ntile(4) as quartile"
partitionBy:
- "category"
orderBy:
- column: "total_sold"
direction: desc

Accessing boundary values in a partition:

columns:
- column: "first_value(price) as opening_price"
partitionBy:
- "symbol"
orderBy:
- column: "trade_date"
direction: asc
- column: "last_value(price) as closing_price"
partitionBy:
- "symbol"
orderBy:
- column: "trade_date"
direction: asc

Conditional Functions

Conditional functions handle NULL values and provide inline branching logic.

FunctionReturn TypeDescription
coalesce(expr, ...)variesReturn the first non-NULL argument.
nullif(expr1, expr2)same as expr1Return NULL if expr1 = expr2, otherwise return expr1.
ifnull(expr, default)variesReturn default if expr is NULL, otherwise return expr. Equivalent to coalesce(expr, default).

Examples

columns:
# Use first available contact method
- "coalesce(mobile_phone, home_phone, office_phone, 'no phone') as contact_phone"

# Avoid division by zero: nullif returns NULL when divisor is 0,
# which makes the division produce NULL instead of an error
- "total / nullif(count, 0) as safe_average"

# Provide a default for missing values
- "ifnull(middle_name, '') as middle_name"

Note that coalesce also appears in the String Functions section because it is commonly used with string values, but it works with any data type.

For more advanced conditional logic, use the CASE expression:

columns:
- "CASE WHEN score >= 90 THEN 'A' WHEN score >= 80 THEN 'B' WHEN score >= 70 THEN 'C' ELSE 'F' END as grade"