WindowsSubstitution Logical Evaluation Rule¶
WindowsSubstitution is a logical evaluation rule (
Rule[LogicalPlan]) that the Logical Analyzer uses to resolve (aka substitute) WithWindowDefinition unary logical operators with <
WindowsSubstitution is part of Substitution fixed-point batch of rules.
NOTE: It appears that
WindowsSubstitution is exclusively used for pure SQL queries because WithWindowDefinition.md[WithWindowDefinition] unary logical operator is created exclusively when
AstBuilder WithWindowDefinition.md#creating-instance[parses window definitions].
If a window specification is not found,
WindowsSubstitution fails analysis with the following error:
Window specification [windowName] is not defined in the WINDOW clause.
NOTE: The analysis failure is unlikely to happen given
AstBuilder sql/AstBuilder.md#withWindows[builds a lookup table of all the named window specifications] defined in a SQL text and reports a
ParseException when a
WindowSpecReference is not available earlier.
WindowsSubstitution takes the
child logical plan and transforms its <
WINDOW clause (see spark-sql-Expression-WindowExpression.md#WithWindowDefinition-example[WithWindowDefinition Example]).