Skip to content

ResolveOrdinalInOrderByAndGroupBy Logical Resolution Rule

ResolveOrdinalInOrderByAndGroupBy is a logical resolution rule that <> in a logical query plan.

ResolveOrdinalInOrderByAndGroupBy is part of the Resolution fixed-point batch in the standard batches of the Analyzer.

ResolveOrdinalInOrderByAndGroupBy is a Catalyst rule for transforming logical plans, i.e. Rule[LogicalPlan].

[[creating-instance]] ResolveOrdinalInOrderByAndGroupBy takes no arguments when created.

[source, scala]

// FIXME: DEMO val rule = spark.sessionState.analyzer.ResolveOrdinalInOrderByAndGroupBy

val plan = ??? val planResolved = rule(plan) scala> println(planResolved.numberedTreeString) 00 'UnresolvedRelation t1


=== [[apply]] Executing Rule -- apply Method

[source, scala]

apply(plan: LogicalPlan): LogicalPlan

apply walks the logical plan from children up the tree and looks for <> and <> logical operators with <> leaf expressions (in <> and <> expressions, respectively).

For a <> logical operator with <> expressions, apply replaces all the <> expressions (with <> child expressions) with SortOrder expressions and the expression at the index - 1 position in the output schema of the <> logical operator.

For a <> logical operator with <> expressions, apply replaces all the expressions (with <> child expressions) with the expression at the index - 1 position in the <> of the current Aggregate logical operator.

apply throws a AnalysisException (and hence fails an analysis) if the ordinal is outside the range:

ORDER BY position [index] is not in select list (valid range is [1, [output.size]])
GROUP BY position [index] is not in select list (valid range is [1, [aggs.size]])

apply is part of the Rule abstraction.

Back to top