Skip to main content
Version: Next

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. Named arguments (name => value) are also supported in v3.0.

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"

Collection Functions (v3.0)

Collection functions operate on arrays and maps. These are new in Teckel 3.0.

FunctionReturn TypeDescription
size(expr)integerNumber of elements in array or entries in map.
array_contains(array, value)booleanTrue if array contains the value.
element_at(array_or_map, key)variesElement at index (array, 0-based) or key (map).
explode(expr)rowsExpands array/map into multiple rows.
explode_outer(expr)rowsLike explode, but preserves NULL/empty as a single row.
posexplode(expr)rowsLike explode, but also produces a position column.
flatten(array)arrayFlattens a nested array by one level.
array_distinct(array)arrayRemoves duplicates from an array.
array_sort(array)arraySorts array elements in ascending order.
array_union(a1, a2)arrayUnion of two arrays (no duplicates).
array_intersect(a1, a2)arrayElements common to both arrays.
array_except(a1, a2)arrayElements in a1 but not a2.
array_join(array, delim)stringConcatenates array elements with a delimiter.
array_position(array, elem)integer1-based position of element (0 if not found).
array_remove(array, elem)arrayRemoves all occurrences of element.
array_repeat(elem, count)arrayCreates an array repeating element count times.
arrays_zip(a1, a2, ...)arrayMerges arrays into an array of structs.
array_compact(array)arrayRemoves NULL elements from an array.
map_keys(map)arrayReturns the map's keys as an array.
map_values(map)arrayReturns the map's values as an array.
map_concat(m1, m2, ...)mapMerges multiple maps. Later keys overwrite.
map_from_arrays(keys, values)mapCreates a map from key and value arrays.
map_from_entries(array)mapCreates a map from key-value struct entries.
map_entries(map)arrayReturns key-value struct entries as an array.

Examples

columns:
- "size(tags) as tag_count"
- "array_contains(roles, 'admin') as is_admin"
- "array_join(tags, ', ') as tags_string"
- "map_keys(attributes) as attr_names"

Higher-Order Functions (v3.0)

Higher-order functions accept lambda expressions as arguments. See Lambda Expressions.

FunctionReturn TypeDescription
transform(array, func)arrayApply function to each element.
filter(array, func)arrayKeep elements matching predicate.
aggregate(array, zero, merge)variesReduce array to single value.
exists(array, func)booleanTrue if any element matches predicate.
forall(array, func)booleanTrue if all elements match predicate.
transform_keys(map, func)mapApply function to each key.
transform_values(map, func)mapApply function to each value.
map_filter(map, func)mapKeep entries matching predicate.
zip_with(a1, a2, func)arrayMerge two arrays element-wise using function.

Examples

columns:
- "transform(prices, x -> x * 1.1) as prices_with_tax"
- "filter(scores, x -> x >= 60) as passing_scores"
- "aggregate(amounts, 0, (acc, x) -> acc + x) as total"
- "exists(tags, t -> t = 'urgent') as has_urgent"
- "transform_values(metrics, (k, v) -> round(v, 2)) as rounded_metrics"

Struct Functions (v3.0)

Functions for creating and manipulating struct values.

FunctionReturn TypeDescription
struct(expr, ...)structCreates a struct from positional values.
named_struct(name, val, ...)structCreates a struct with named fields.
with_field(struct, name, value)structAdds or replaces a field in a struct.
drop_fields(struct, name, ...)structRemoves fields from a struct.

Examples

columns:
- "named_struct('name', full_name, 'age', age) as person"
- "with_field(address, 'country', 'US') as updated_address"
- "drop_fields(record, 'internal_id', 'debug_info') as clean_record"

JSON Functions (v3.0)

Functions for parsing, generating, and querying JSON data.

FunctionReturn TypeDescription
from_json(string, schema)structParse JSON string into a struct.
to_json(expr)stringConvert struct/array/map to JSON string.
get_json_object(string, path)stringExtract value by JSONPath.
json_tuple(string, key, ...)tupleExtract multiple values from JSON string.
schema_of_json(string)stringInfer schema of a JSON string as DDL.
parse_json(string)variantParse JSON string to variant type.

Examples

columns:
- "get_json_object(payload, '$.user.name') as user_name"
- "to_json(named_struct('id', id, 'name', name)) as json_output"
- "from_json(raw_json, 'struct<name: string, age: int>') as parsed"

Interval and Temporal Functions (v3.0)

Extended temporal functions including interval construction and additional date/time operations.

FunctionReturn TypeDescription
make_interval(years, months, weeks, days, hours, mins, secs)intervalConstruct a calendar interval.
make_ym_interval(years, months)intervalConstruct a year-month interval.
make_dt_interval(days, hours, mins, secs)intervalConstruct a day-time interval.
extract(field FROM expr)integerExtract field from date/timestamp/interval.
date_trunc(unit, expr)timestampTruncate timestamp to specified unit.
months_between(end, start)doubleNumber of months between two dates.
add_months(date, n)dateAdd N months to a date.
last_day(date)dateLast day of the month.
next_day(date, dayOfWeek)dateNext occurrence of the given day of week.
current_timestamp_ntz()timestamp_ntzCurrent local timestamp without timezone.
to_timestamp_ntz(expr, format)timestamp_ntzParse string to timestamp without timezone.
current_time()timeCurrent time of day.
make_time(hour, min, sec)timeConstruct time from components.

Examples

columns:
- "extract(QUARTER FROM order_date) as quarter"
- "date_trunc('month', event_timestamp) as month_start"
- "months_between(end_date, start_date) as duration_months"
- "last_day(report_date) as month_end"
- "current_timestamp_ntz() as local_now"

Statistical Aggregate Functions (v3.0)

Statistical functions for advanced analytics.

FunctionReturn TypeDescription
stddev(expr)doubleSample standard deviation.
stddev_samp(expr)doubleSample standard deviation.
stddev_pop(expr)doublePopulation standard deviation.
variance(expr)doubleSample variance.
var_samp(expr)doubleSample variance.
var_pop(expr)doublePopulation variance.
corr(expr1, expr2)doublePearson correlation coefficient.
covar_samp(expr1, expr2)doubleSample covariance.
covar_pop(expr1, expr2)doublePopulation covariance.
skewness(expr)doubleSkewness.
kurtosis(expr)doubleExcess kurtosis.
percentile(expr, p)doubleExact percentile (p in [0, 1]).
percentile_approx(expr, p, accuracy)doubleApproximate percentile.
grouping(expr)integer1 if column is aggregated in a grouping set, 0 otherwise.
grouping_id(expr, ...)integerBitmask of grouping columns.

Examples

# In a groupBy transformation
agg:
- "stddev(salary) as salary_stddev"
- "corr(hours_worked, output) as productivity_correlation"
- "percentile_approx(response_time, 0.95) as p95_latency"
- "skewness(order_amount) as amount_skew"

Variant Functions (v3.0)

Functions for working with the semi-structured variant data type.

FunctionReturn TypeDescription
parse_json(string)variantParse JSON string to variant.
to_json(variant)stringConvert variant to JSON string.
variant_get(variant, path, type)typedExtract and cast value from variant by JSONPath.
try_variant_get(variant, path, type)typedLike variant_get, returns NULL on failure.
is_variant_null(variant)booleanTrue if variant value is JSON null.
schema_of_variant(variant)stringInfer schema of variant as DDL string.

Examples

columns:
- "parse_json(raw_payload) as data"
- "variant_get(data, '$.user.name', 'string') as user_name"
- "try_variant_get(data, '$.count', 'integer') as count"
- "is_variant_null(data) as is_empty"