-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: YANGDB <[email protected]>
- Loading branch information
Showing
5 changed files
with
206 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
integ-test/src/test/scala/org/opensearch/flint/spark/LogicalPlanTestUtils.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package org.opensearch.flint.spark | ||
|
||
import org.apache.spark.sql.catalyst.expressions.{Alias, ExprId} | ||
import org.apache.spark.sql.catalyst.plans.logical.{Aggregate, LogicalPlan, Project} | ||
|
||
/** | ||
* general utility functions for ppl to spark transformation test | ||
*/ | ||
trait LogicalPlanTestUtils { | ||
/** | ||
* utility function to compare two logical plans while ignoring the auto-generated expressionId associated with the alias | ||
* which is used for projection or aggregation | ||
* @param plan | ||
* @return | ||
*/ | ||
def compareByString(plan: LogicalPlan): String = { | ||
// Create a rule to replace Alias's ExprId with a dummy id | ||
val rule: PartialFunction[LogicalPlan, LogicalPlan] = { | ||
case p: Project => | ||
val newProjections = p.projectList.map { | ||
case alias: Alias => Alias(alias.child, alias.name)(exprId = ExprId(0), qualifier = alias.qualifier) | ||
case other => other | ||
} | ||
p.copy(projectList = newProjections) | ||
|
||
case agg: Aggregate => | ||
val newGrouping = agg.groupingExpressions.map { | ||
case alias: Alias => Alias(alias.child, alias.name)(exprId = ExprId(0), qualifier = alias.qualifier) | ||
case other => other | ||
} | ||
val newAggregations = agg.aggregateExpressions.map { | ||
case alias: Alias => Alias(alias.child, alias.name)(exprId = ExprId(0), qualifier = alias.qualifier) | ||
case other => other | ||
} | ||
agg.copy(groupingExpressions = newGrouping, aggregateExpressions = newAggregations) | ||
|
||
case other => other | ||
} | ||
|
||
// Apply the rule using transform | ||
val transformedPlan = plan.transform(rule) | ||
|
||
// Return the string representation of the transformed plan | ||
transformedPlan.toString | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.