Skip to content

SubqueryAlias Unary Logical Operator

SubqueryAlias is a <> that represents an aliased subquery (i.e. the <> logical query plan with the <> in the <>).

SubqueryAlias is <> when:

  • AstBuilder is requested to parse a <> or <> query, <> and <> in a SQL statement

  • <> operator is used

  • SessionCatalog is requested to find a table or view in catalogs

  • RewriteCorrelatedScalarSubquery logical optimization is requested to <> (when <> to <>, Project or Filter logical operators with correlated scalar subqueries)

[[doCanonicalize]] SubqueryAlias simply requests the <> for the <>.

[[output]] When requested for <>, SubqueryAlias requests the <> logical operator for them and adds the <> as a <>.

NOTE: <> logical optimization eliminates (removes) SubqueryAlias operators from a logical query plan.

NOTE: <> logical optimization rewrites correlated scalar subqueries with SubqueryAlias operators.

=== [[catalyst-dsl]][[subquery]][[as]] Catalyst DSL -- subquery And as Operators

[source, scala]

as(alias: String): LogicalPlan subquery(alias: Symbol): LogicalPlan


subquery and as operators in Catalyst DSL create a <> logical operator, e.g. for testing or Spark SQL internals exploration.

[source, scala]

import org.apache.spark.sql.catalyst.dsl.plans._ val t1 = table("t1")

val plan = t1.subquery('a) scala> println(plan.numberedTreeString) 00 'SubqueryAlias a 01 +- 'UnresolvedRelation t1

val plan = t1.as("a") scala> println(plan.numberedTreeString) 00 'SubqueryAlias a 01 +- 'UnresolvedRelation t1


=== [[creating-instance]] Creating SubqueryAlias Instance

SubqueryAlias takes the following when created:

  • [[alias]] Alias
  • [[child]] Child <>