Skip to content

RuntimeReplaceable -- Replaceable SQL Expressions

RuntimeReplaceable is the <> for <> that are replaced by Logical Optimizer with their child expression (that can then be evaluated).

NOTE: Catalyst Optimizer uses ReplaceExpressions.md[ReplaceExpressions] logical optimization to replace RuntimeReplaceable expressions.

RuntimeReplaceable contract allows for expression aliases, i.e. expressions that are fairly complex in the inside than on the outside, and is used to provide compatibility with other SQL databases by supporting SQL functions with their more complex Catalyst expressions (that are already supported by Spark SQL).

NOTE: <> are tied up to their SQL functions in FunctionRegistry.md#expressions[FunctionRegistry].

[[Unevaluable]] RuntimeReplaceable expressions are unevaluable

[[contract]] [source, scala]


package org.apache.spark.sql.catalyst.expressions

trait RuntimeReplaceable extends UnaryExpression with Unevaluable { // as a marker contract it only marks a class // no methods are required }


NOTE: To make sure the explain plan and expression SQL works correctly, a RuntimeReplaceable implementation should override Expression.md#flatArguments[flatArguments] and Expression.md#sql[sql] methods.

[[implementations]] .RuntimeReplaceables [cols="1,1,1",options="header",width="100%"] |=== | RuntimeReplaceable | Standard Function | SQL Function

[[IfNull]] IfNull
FunctionRegistry.md#ifnull[ifnull]
[[Left]] Left
FunctionRegistry.md#left[left]
[[NullIf]] NullIf
FunctionRegistry.md#nullif[nullif]
[[Nvl]] Nvl
FunctionRegistry.md#nvl[nvl]
[[Nvl2]] Nvl2
FunctionRegistry.md#nvl2[nvl2]

| [[ParseToDate]] spark-sql-Expression-ParseToDate.md[ParseToDate] | spark-sql-functions-datetime.md#to_date[to_date] | FunctionRegistry.md#to_date[to_date]

| [[ParseToTimestamp]] expressions/ParseToTimestamp.md[ParseToTimestamp] | spark-sql-functions-datetime.md#to_timestamp[to_timestamp] | FunctionRegistry.md#to_timestamp[to_timestamp]

[[Right]] Right
FunctionRegistry.md#right[right]
===
Back to top