dataengref migrate

Home / Teradata

Teradata to Databricks: function mapping

2 of 5 common Teradata functions need a change in Databricks. Mapping table with Databricks syntax and behavior differences.

Other targets: Teradata to Snowflake · Teradata to BigQuery

Needs a rewrite (1)

No Databricks function with the same behavior; use the construct shown.

TeradataDatabricksNotes
SAMPLERewrite TABLESAMPLE (n ROWS) / TABLESAMPLE (percent PERCENT)REPEATABLE (seed) makes the sample repeatable.
Teradata SAMPLE 0.25 means 25 percent. Snowflake SAMPLE (0.25) means 0.25 percent, a hundred times smaller.
Multiple samples with SAMPLEID and stratified sampling (WHEN ... THEN) have no direct equivalent; build them with a window function over RANDOM().

Different name (1)

Same behavior under another name; rename the call and check the notes.

TeradataDatabricksNotes
OREPLACEDifferent name replace(str, search [, replace])The replacement defaults to an empty string.
OREPLACE(s, 'x', NULL) removes 'x' in Teradata; REPLACE(s, 'x', NULL) returns NULL in the targets. Pass '' explicitly.

Works as written (3)

The same call runs, but check the notes for behavior differences.

TeradataDatabricksNotes
NULLIFZEROSame name nullifzero(expr)Databricks Runtime 16.0 and above; the docs do not list it for Databricks SQL warehouses.
NULLIFZERO is mostly used to avoid division by zero. BigQuery also offers SAFE_DIVIDE(x, y), which returns NULL when y is 0.
QUALIFYSame name QUALIFY boolean_expressionEvaluated after window functions.
Teradata accepts legacy ordered-analytic syntax such as QUALIFY RANK(amount DESC) <= 3 and CSUM. Rewrite these as RANK() OVER (ORDER BY amount DESC) and SUM(...) OVER (...).
ZEROIFNULLSame name zeroifnull(expr)Databricks Runtime 16.0 and above; the docs do not list it for Databricks SQL warehouses, where coalesce(expr, 0) works everywhere.
On Databricks SQL warehouses or runtimes before 16.0, write coalesce(expr, 0) instead.

Paste a query into the SQL checker to list the functions it uses that need a change.