In some cases, the expressions in a logical plan will be modified to new ones during analysis, e.g. the handling for self-join cases. If some expressions are resolved based on the analyzed plan, they are referring to changed expression ids, not original ids.
But the transformation of DataFrame will use logical plan to construct new DataFrame, e.g. groupBy and aggregation. So in such cases, the expressions in these DataFrames will be inconsistent.
The problems are specified as following:
- Expression ids in logical plan are possibly inconsistent if expression ids are changed during analysis and some expressions are resolved after that
When we try to run the following codes:
Because groupBy and min will perform resolving based on the analyzed logical plan, their expression ids refer to analyzed plan, instead of logical plan.
So the logical plan of df2 looks like:
As you see, the expression ids in Aggregate are different to the expression ids in Subquery y. This is the first problem.
- The df2 can't be performed
The showing logical plan of df2 can't be performed. Because the expression ids of Subquery y will be modified for self-join handling during analysis, the analyzed plan of df2 becomes:
The expressions referred in Aggregate are not matching to these in Subquery y. This is the second problem.
We try to add a PreAnalyzer. When a logical plan rawPlan is given to SQLContext, it uses PreAnalyzer to modify the logical plan before assigning to QueryExecution.logical. Then later operations will based on the pre-analyzed logical plan, instead of the original rawPlan.