Skip to content

Commit

Permalink
Make append alias distinct
Browse files Browse the repository at this point in the history
Signed-off-by: Andy Kwok <[email protected]>
  • Loading branch information
andy-k-improving committed Dec 20, 2024
1 parent b219097 commit 6b3aeec
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -263,9 +263,8 @@ public LogicalPlan visitTrendline(Trendline node, CatalystPlanContext context) {
public LogicalPlan visitAppendCol(AppendCol node, CatalystPlanContext context) {

final String APPENDCOL_ID = WindowSpecTransformer.ROW_NUMBER_COLUMN_NAME;
// todo: Add table prefix
final String TABLE_LHS = "T1";
final String TABLE_RHS = "T2";
final String TABLE_LHS = "APPENDCOL_T1";
final String TABLE_RHS = "APPENDCOL_T2";
final UnresolvedAttribute t1Attr = new UnresolvedAttribute(seq(TABLE_LHS, APPENDCOL_ID));
final UnresolvedAttribute t2Attr = new UnresolvedAttribute(seq(TABLE_RHS, APPENDCOL_ID));
final List<Expression> fieldsToRemove = new ArrayList<>(List.of(t1Attr, t2Attr));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ class PPLLogicalPlanAppendColCommandTranslatorTestSuite
private val RELATION_EMPLOYEES = UnresolvedRelation(Seq("employees"))

private val T12_JOIN_CONDITION =
EqualTo(UnresolvedAttribute("T1._row_number_"), UnresolvedAttribute("T2._row_number_"))
EqualTo(UnresolvedAttribute("APPENDCOL_T1._row_number_"), UnresolvedAttribute("APPENDCOL_T2._row_number_"))

private val T12_COLUMNS_SEQ =
Seq(UnresolvedAttribute("T1._row_number_"), UnresolvedAttribute("T2._row_number_"))
Seq(UnresolvedAttribute("APPENDCOL_T1._row_number_"), UnresolvedAttribute("APPENDCOL_T2._row_number_"))

// @formatter:off
/**
Expand Down Expand Up @@ -75,7 +75,7 @@ class PPLLogicalPlanAppendColCommandTranslatorTestSuite
: +- 'UnresolvedRelation [relation], [], false
*/
val t1 = SubqueryAlias(
"T1",
"APPENDCOL_T1",
Project(Seq(ROW_NUMBER_AGGREGATION, UnresolvedStar(None)), RELATION_EMPLOYEES))

/*
Expand All @@ -86,7 +86,7 @@ class PPLLogicalPlanAppendColCommandTranslatorTestSuite
+- 'UnresolvedRelation [relation], [], false
*/
val t2 = SubqueryAlias(
"T2",
"APPENDCOL_T2",
Project(
Seq(ROW_NUMBER_AGGREGATION, UnresolvedStar(None)),
Aggregate(AGE_ALIAS :: Nil, Seq(COUNT_STAR, AGE_ALIAS), RELATION_EMPLOYEES)))
Expand Down Expand Up @@ -131,7 +131,7 @@ class PPLLogicalPlanAppendColCommandTranslatorTestSuite
: +- 'UnresolvedRelation [relation], [], false
*/
val t1 = SubqueryAlias(
"T1",
"APPENDCOL_T1",
Project(
Seq(ROW_NUMBER_AGGREGATION, UnresolvedStar(None)),
Project(
Expand All @@ -149,7 +149,7 @@ class PPLLogicalPlanAppendColCommandTranslatorTestSuite
+- 'UnresolvedRelation [relation], [], false
*/
val t2 = SubqueryAlias(
"T2",
"APPENDCOL_T2",
Project(
Seq(ROW_NUMBER_AGGREGATION, UnresolvedStar(None)),
Aggregate(AGE_ALIAS :: Nil, Seq(COUNT_STAR, AGE_ALIAS), RELATION_EMPLOYEES)))
Expand Down Expand Up @@ -196,7 +196,7 @@ class PPLLogicalPlanAppendColCommandTranslatorTestSuite
: +- 'UnresolvedRelation [relation], [], false
*/
val t1 = SubqueryAlias(
"T1",
"APPENDCOL_T1",
Project(
Seq(ROW_NUMBER_AGGREGATION, UnresolvedStar(None)),
Project(
Expand All @@ -215,7 +215,7 @@ class PPLLogicalPlanAppendColCommandTranslatorTestSuite
+- 'UnresolvedRelation [employees], [], false
*/
val t2 = SubqueryAlias(
"T2",
"APPENDCOL_T2",
Project(
Seq(ROW_NUMBER_AGGREGATION, UnresolvedStar(None)),
DataFrameDropColumns(
Expand Down Expand Up @@ -274,7 +274,7 @@ class PPLLogicalPlanAppendColCommandTranslatorTestSuite
: +- 'UnresolvedRelation [employees], [], false
*/
val mainSearch = SubqueryAlias(
"T1",
"APPENDCOL_T1",
Project(
Seq(ROW_NUMBER_AGGREGATION, UnresolvedStar(None)),
Project(
Expand All @@ -290,7 +290,7 @@ class PPLLogicalPlanAppendColCommandTranslatorTestSuite
+- 'UnresolvedRelation [employees], [], false
*/
val firstAppenCol = SubqueryAlias(
"T2",
"APPENDCOL_T2",
Project(
Seq(ROW_NUMBER_AGGREGATION, UnresolvedStar(None)),
DataFrameDropColumns(
Expand All @@ -300,7 +300,7 @@ class PPLLogicalPlanAppendColCommandTranslatorTestSuite
Aggregate(AGE_ALIAS :: Nil, Seq(COUNT_STAR, AGE_ALIAS), RELATION_EMPLOYEES)))))

val joinWithFirstAppendCol = SubqueryAlias(
"T1",
"APPENDCOL_T1",
Project(
Seq(ROW_NUMBER_AGGREGATION, UnresolvedStar(None)),
DataFrameDropColumns(
Expand All @@ -314,7 +314,7 @@ class PPLLogicalPlanAppendColCommandTranslatorTestSuite
+- 'UnresolvedRelation [employees], [], false
*/
val secondAppendCol = SubqueryAlias(
"T2",
"APPENDCOL_T2",
Project(
Seq(ROW_NUMBER_AGGREGATION, UnresolvedStar(None)),
Project(Seq(UnresolvedAttribute("dept")), RELATION_EMPLOYEES)))
Expand Down Expand Up @@ -369,7 +369,7 @@ class PPLLogicalPlanAppendColCommandTranslatorTestSuite
: +- 'UnresolvedRelation [relation], [], false
*/
val t1 = SubqueryAlias(
"T1",
"APPENDCOL_T1",
Project(Seq(ROW_NUMBER_AGGREGATION, UnresolvedStar(None)), RELATION_EMPLOYEES))

/*
Expand All @@ -380,7 +380,7 @@ class PPLLogicalPlanAppendColCommandTranslatorTestSuite
+- 'UnresolvedRelation [relation], [], false
*/
val t2 = SubqueryAlias(
"T2",
"APPENDCOL_T2",
Project(
Seq(ROW_NUMBER_AGGREGATION, UnresolvedStar(None)),
Aggregate(Nil, Seq(
Expand All @@ -391,7 +391,7 @@ class PPLLogicalPlanAppendColCommandTranslatorTestSuite
val expectedPlan = Project(
Seq(UnresolvedStar(None)),
DataFrameDropColumns(
T12_COLUMNS_SEQ :+ UnresolvedAttribute("T1.age"),
T12_COLUMNS_SEQ :+ UnresolvedAttribute("APPENDCOL_T1.age"),
Join(t1, t2, LeftOuter, Some(T12_JOIN_CONDITION), JoinHint.NONE)))

comparePlans(logicalPlan, expectedPlan, checkAnalysis = false)
Expand Down

0 comments on commit 6b3aeec

Please sign in to comment.