QFSQL Reference
QFSQL (QuantFlow SQL) is an engine-agnostic expression language used in DataInfra field mappings. Each function is translated to engine-native SQL by adapter-specific translators — the same transformation string produces correct SQL across BigQuery, DuckDB, Snowflake, and Trino.
Cast / Convert
cast_safe(expr, type)
Safe type cast — returns NULL on failure instead of raising an error.
| Engine | Translation |
|---|---|
| BigQuery | safe_cast(expr AS type) |
| DuckDB | CAST(expr AS type) (no safe cast) |
| Snowflake | TRY_CAST(expr AS type) |
| Trino | CAST(expr AS type) (no safe cast, fallback) |
cast(expr, type)
Standard type cast — may error on invalid input.
| Engine | Translation |
|---|---|
| All | CAST(expr AS type) |
try_cast(expr, type)
Explicit try-cast (alias for cast_safe on engines that support it).
| Engine | Translation |
|---|---|
| BigQuery | safe_cast(expr AS type) |
| DuckDB | TRY_CAST(expr AS type) |
| Snowflake | TRY_CAST(expr AS type) |
| Trino | CAST(expr AS type) (fallback) |
to_string(expr) / to_integer(expr) / to_decimal(expr) / to_boolean(expr)
Type-specific cast shorthands.
| Function | BigQuery | DuckDB | Snowflake | Trino |
|---|---|---|---|---|
to_string(x) | CAST(x AS STRING) | CAST(x AS VARCHAR) | CAST(x AS VARCHAR) | CAST(x AS TEXT) |
to_integer(x) | CAST(x AS INT64) | CAST(x AS INTEGER) | CAST(x AS INTEGER) | CAST(x AS INTEGER) |
to_decimal(x) | CAST(x AS NUMERIC) | CAST(x AS DECIMAL) | CAST(x AS NUMBER) | CAST(x AS NUMERIC) |
to_boolean(x) | CAST(x AS BOOL) | CAST(x AS BOOLEAN) | CAST(x AS BOOLEAN) | CAST(x AS BOOLEAN) |
Date / Time
timestamp_ms(expr) / timestamp_us(expr) / timestamp_ns(expr)
Convert Unix milliseconds / microseconds / nanoseconds to a timestamp.
| Function | BigQuery | DuckDB | Snowflake | Trino |
|---|---|---|---|---|
timestamp_ms(x) | safe.timestamp_millis(x) | TO_TIMESTAMP(x / 1000.0) | TO_TIMESTAMP_LTZ(x / 1000) | TO_TIMESTAMP(x / 1000.0) |
timestamp_us(x) | safe.timestamp_micros(x) | TO_TIMESTAMP(x / 1000000.0) | TO_TIMESTAMP_LTZ(x / 1000000) | TO_TIMESTAMP(x / 1000000.0) |
timestamp_ns(x) | safe.timestamp_nanos(x) | TO_TIMESTAMP(x / 1000000000.0) | TO_TIMESTAMP_NTZ(x / 1000000000) | TO_TIMESTAMP(x / 1000000000.0) |
timestamp_seconds(expr)
Convert Unix seconds to a timestamp.
| Engine | Translation |
|---|---|
| BigQuery | timestamp_seconds(expr) |
| DuckDB | TO_TIMESTAMP(expr) |
| Snowflake | TO_TIMESTAMP_LTZ(expr) |
| Trino | TO_TIMESTAMP(expr) |
transformation: "timestamp_ms(cast_safe(trade_time, bigint))"
date_trunc(expr, unit)
Truncate a timestamp to the specified unit.
| Engine | Translation |
|---|---|
| BigQuery | date_trunc(expr, unit) |
| DuckDB | DATE_TRUNC(unit, expr) |
| Snowflake | DATE_TRUNC(unit, expr) |
| Trino | DATE_TRUNC(unit, expr) |
date_add(expr, interval, unit)
Add an interval to a date or timestamp.
| Engine | Translation |
|---|---|
| BigQuery | date_add(expr, INTERVAL interval unit) |
| DuckDB | expr + INTERVAL interval unit |
| Snowflake | DATEADD(unit, interval, expr) |
| Trino | expr + INTERVAL 'interval unit' |
Units: day, hour, minute, second, month, year
date_diff(date1, date2, unit)
Compute the difference between two dates.
| Engine | Translation |
|---|---|
| BigQuery | date_diff(date1, date2, unit) |
| DuckDB | DATE_DIFF(unit, date2, date1) |
| Snowflake | DATEDIFF(unit, date2, date1) |
| Trino | EXTRACT(EPOCH FROM (date1 - date2)) |
extract(part, expr)
Extract a date part from a timestamp.
| Engine | Translation |
|---|---|
| All | EXTRACT(part FROM expr) |
Parts: year, month, day, hour, minute, second
format_timestamp(expr, format)
Format a timestamp as a string.
| Engine | Translation |
|---|---|
| BigQuery | format_timestamp(format, expr) |
| DuckDB | STRFTIME(expr, format) |
| Snowflake | TO_CHAR(expr, format) |
| Trino | TO_CHAR(expr, format) |
current_timestamp() / current_date()
Return the current timestamp or date.
| Function | BigQuery | DuckDB | Snowflake | Trino |
|---|---|---|---|---|
current_timestamp() | CURRENT_TIMESTAMP() | CURRENT_TIMESTAMP | CURRENT_TIMESTAMP() | CURRENT_TIMESTAMP |
current_date() | CURRENT_DATE() | CURRENT_DATE | CURRENT_DATE() | CURRENT_DATE |
String
str_concat(expr1, expr2, ...)
Concatenate two or more strings. Null-safe.
| Engine | Translation |
|---|---|
| BigQuery | CONCAT(expr1, expr2, ...) |
| DuckDB | CONCAT(expr1, expr2, ...) |
| Snowflake | CONCAT(expr1, expr2, ...) |
| Trino | (expr1 || expr2 || ...) |
transformation: "str_concat('binance_', cast_safe(trade_id, string))"
str_length(expr)
Return the character length of a string.
| Function | BigQuery | DuckDB | Snowflake | Trino |
|---|---|---|---|---|
str_length(x) | LENGTH(x) | LENGTH(x) | LENGTH(x) | LENGTH(x) |
str_lower(expr) / str_upper(expr)
Lowercase or uppercase a string.
| Engine | Translation |
|---|---|
| All | LOWER(expr) / UPPER(expr) |
str_trim(expr)
Trim whitespace from both ends of a string.
| Engine | Translation |
|---|---|
| All | TRIM(expr) |
str_replace(source, from, to)
Replace occurrences of from with to in source.
| Engine | Translation |
|---|---|
| All | REPLACE(source, from, to) |
str_substring(expr, start, length?)
Extract a substring. start is 1-indexed. If length is omitted, extracts to end.
| Engine | Translation |
|---|---|
| BigQuery | SUBSTR(expr, start, length) |
| DuckDB | SUBSTRING(expr, start, length) |
| Snowflake | SUBSTRING(expr, start, length) |
| Trino | SUBSTRING(expr FROM start FOR length) |
str_contains(source, search)
Check if source contains search. Returns boolean.
| Engine | Translation |
|---|---|
| BigQuery | STRPOS(source, search) > 0 |
| DuckDB | STRPOS(source, search) > 0 |
| Snowflake | CONTAINS(source, search) |
| Trino | STRPOS(source, search) > 0 |
str_starts_with(source, prefix) / str_ends_with(source, suffix)
Check if source starts/ends with a given string.
| Function | BigQuery | DuckDB | Snowflake | Trino |
|---|---|---|---|---|
str_starts_with(s, p) | STARTS_WITH(s, p) | STARTS_WITH(s, p) | STARTSWITH(s, p) | s LIKE p || '%' |
str_ends_with(s, p) | ENDS_WITH(s, p) | ENDS_WITH(s, p) | ENDSWITH(s, p) | s LIKE '%' || p |
regexp_extract(source, pattern)
Extract the first regex match.
| Engine | Translation |
|---|---|
| BigQuery | REGEXP_EXTRACT(source, pattern) |
| DuckDB | REGEXP_EXTRACT(source, pattern) |
| Snowflake | REGEXP_SUBSTR(source, pattern) |
| Trino | (SELECT (regexp_matches(source, pattern))[1]) |
regexp_replace(source, pattern, replacement)
Replace text matching a regex pattern.
| Engine | Translation |
|---|---|
| BigQuery | REGEXP_REPLACE(source, pattern, replacement) |
| DuckDB | REGEXP_REPLACE(source, pattern, replacement) |
| Snowflake | REGEXP_REPLACE(source, pattern, replacement) |
| Trino | REGEXP_REPLACE(source, pattern, replacement) |
regexp_contains(source, pattern)
Check if source matches a regex pattern.
| Engine | Translation |
|---|---|
| BigQuery | REGEXP_CONTAINS(source, pattern) |
| DuckDB | REGEXP_MATCHES(source, pattern) |
| Snowflake | REGEXP_LIKE(source, pattern) |
| Trino | source ~ pattern |
str_split(str, delimiter)
Split a string into an array by delimiter.
| Engine | Translation |
|---|---|
| BigQuery | SPLIT(str, delimiter) |
| DuckDB | string_split(str, delimiter) |
| Snowflake | SPLIT(str, delimiter) |
| Trino | STRING_TO_ARRAY(str, delimiter) |
str_join(array, delimiter)
Join an array into a string with delimiter.
| Engine | Translation |
|---|---|
| BigQuery | ARRAY_TO_STRING(array, delimiter) |
| DuckDB | ARRAY_TO_STRING(array, delimiter) |
| Snowflake | ARRAY_TO_STRING(array, delimiter) |
| Trino | ARRAY_TO_STRING(array, delimiter) |
Numeric / Aggregate
coalesce(expr1, expr2, ...)
Return the first non-NULL value.
| Engine | Translation |
|---|---|
| All | COALESCE(expr1, expr2, ...) |
transformation: "coalesce(price, 0)"
null_if(expr1, expr2)
Return NULL if expr1 == expr2, otherwise return expr1.
| Engine | Translation |
|---|---|
| All | NULLIF(expr1, expr2) |
if_null(expr, fallback)
Return fallback if expr is NULL.
| Engine | Translation |
|---|---|
| BigQuery | IFNULL(expr, fallback) |
| DuckDB | COALESCE(expr, fallback) |
| Snowflake | IFNULL(expr, fallback) |
| Trino | COALESCE(expr, fallback) |
round(expr, decimals?)
Round to decimals places (default 0).
| Engine | Translation |
|---|---|
| All | ROUND(expr, decimals) |
floor(expr) / ceiling(expr)
Floor or ceiling to nearest integer.
| Engine | Translation |
|---|---|
| All | FLOOR(expr) / CEIL(expr) (BigQuery: CEIL, others: CEIL) |
abs(expr)
Absolute value. Identical across all engines: ABS(expr).
greatest(v1, v2, ...) / least(v1, v2, ...)
Return the largest or smallest value among arguments.
| Engine | Translation |
|---|---|
| All | GREATEST(v1, v2, ...) / LEAST(v1, v2, ...) |
sum(expr) / avg(expr) / count(expr) / min(expr) / max(expr)
Standard aggregate functions. Identical across all engines.
count_distinct(expr)
Count distinct values. Translates to COUNT(DISTINCT expr) on all engines.
str_agg(expr, delimiter?)
Aggregate strings with a delimiter.
| Engine | Translation |
|---|---|
| BigQuery | STRING_AGG(expr, delimiter) |
| DuckDB | STRING_AGG(expr, delimiter) |
| Snowflake | LISTAGG(expr, delimiter) |
| Trino | STRING_AGG(expr, delimiter) |
Conditional
if(condition, true_val, false_val)
IF-THEN-ELSE expression.
| Engine | Translation |
|---|---|
| BigQuery | IF(condition, true_val, false_val) |
| DuckDB | IF(condition, true_val, false_val) |
| Snowflake | IFF(condition, true_val, false_val) |
| Trino | CASE WHEN condition THEN true_val ELSE false_val END |
case_when(when_clause)
Multi-branch CASE expression. The argument is the body of a CASE ... END block — conditions and results supplied inline.
transformation: "case_when(WHEN price > 100 THEN 'high' WHEN price > 50 THEN 'mid' ELSE 'low')"
| Engine | Translation |
|---|---|
| All | CASE when_clause END |
Array / JSON
array(elem1, elem2, ...)
Create an array from elements.
| Engine | Translation |
|---|---|
| BigQuery | [elem1, elem2, ...] |
| DuckDB | LIST[elem1, elem2, ...] |
| Snowflake | ARRAY_CONSTRUCT(elem1, elem2, ...) |
| Trino | ARRAY[elem1, elem2, ...] |
array_length(arr)
Return the length of an array.
| Engine | Translation |
|---|---|
| BigQuery | ARRAY_LENGTH(arr) |
| DuckDB | LEN(arr) |
| Snowflake | ARRAY_SIZE(arr) |
| Trino | CARDINALITY(arr) |
array_contains(arr, elem)
Check if an array contains an element.
| Engine | Translation |
|---|---|
| BigQuery | elem IN UNNEST(arr) |
| DuckDB | LIST_CONTAINS(arr, elem) |
| Snowflake | ARRAY_CONTAINS(elem, arr) |
| Trino | elem = ANY(arr) |
struct(field1, field2, ...)
Create a struct/object from fields.
| Engine | Translation |
|---|---|
| BigQuery | STRUCT(field1, field2, ...) |
| DuckDB | STRUCT(field1, field2, ...) |
| Snowflake | OBJECT_CONSTRUCT(field1, field2, ...) |
| Trino | ROW(field1, field2, ...) |
json_extract(json_str, path)
Extract a value from a JSON string by path.
| Engine | Translation |
|---|---|
| BigQuery | JSON_EXTRACT(json_str, path) |
| DuckDB | json_extract_string(json_str, path) |
| Snowflake | JSON_EXTRACT_PATH_TEXT(json_str, path) |
| Trino | json_str -> path |
json_serialize(expr)
Serialize an expression to a JSON string.
| Engine | Translation |
|---|---|
| BigQuery | TO_JSON_STRING(expr) |
| DuckDB | TO_JSON(expr) |
| Snowflake | TO_JSON(expr) |
| Trino | expr :: TEXT |
Hash
md5(expr) / sha256(expr)
Compute the MD5 or SHA-256 hash of a string.
| Function | BigQuery | DuckDB | Snowflake | Trino |
|---|---|---|---|---|
md5(x) | MD5(x) | MD5(x) | MD5(x) | MD5(x) |
sha256(x) | SHA256(x) | SHA256(x) | SHA2(x, 256) | ENCODE(DIGEST(x, 'sha256'), 'hex') |
uuid()
Generate a random UUID. Takes no arguments.
| Engine | Translation |
|---|---|
| BigQuery | GENERATE_UUID() |
| DuckDB | UUID() |
| Snowflake | UUID_STRING() |
| Trino | GEN_RANDOM_UUID()::TEXT |
DolphinDB-Specific Functions
Available only when the target engine is DolphinDB. These are defined in the streaming expression mapper and use native DolphinDB timeseries functions.
| Function | Description |
|---|---|
cast_safe(expr, type) | Safe type cast |
timestamp_ms(expr) | Unix ms → DolphinDB timestamp |
timestamp_us(expr) | Unix µs → DolphinDB timestamp |
current_timestamp() | Current DolphinDB timestamp |
str_concat(...) | String concatenation |
array_element(arr, index) | Array element by index |
array_sum(arr) | Sum of array elements |
raw_expr(dolphindb_expr) | Passthrough raw DolphinDB expression |
# Example: raw DolphinDB expression passthrough
transformation: "raw_expr(ofi(price, size, 0.95))"
Literal Values
QFSQL supports inline literal values directly in transformation strings:
# String literal
transformation: "'binance'"
# Numeric literal
transformation: "0.95"
# Boolean literal
transformation: "true"
# Current timestamp
transformation: "current_timestamp()"
Literals pass through unchanged to engine-native SQL.