Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
04959c2
refactor analyzer adding a new object
anchovYu Nov 23, 2022
6f44c85
lca code
anchovYu Nov 23, 2022
725e5ac
add tests, refine logic
anchovYu Nov 28, 2022
660e1d2
move lca rule to a new file
anchovYu Nov 28, 2022
fd06094
rename conf
anchovYu Nov 28, 2022
7d4f80f
test failure
anchovYu Nov 29, 2022
b9704d5
small fix
anchovYu Nov 29, 2022
777f13a
temp commit, still in implementation
anchovYu Nov 29, 2022
09480ea
a temporary solution, but still fail certain cases
anchovYu Nov 30, 2022
c972738
working solution, needs some refinement
anchovYu Dec 1, 2022
97ee293
Merge remote-tracking branch 'apache/master' into SPARK-27561-refactor
anchovYu Dec 1, 2022
5785943
make changes to accomodate the recent refactor
anchovYu Dec 2, 2022
757cffb
introduce leaf exp in Project as well
anchovYu Dec 5, 2022
29de892
handle a corner case
anchovYu Dec 5, 2022
72991c6
add more tests; add check rule
anchovYu Dec 6, 2022
d45fe31
uplift the necessity to resolve expression in second phase; add more …
anchovYu Dec 8, 2022
1f55f73
address comments to add tests for LCA off
anchovYu Dec 8, 2022
f753529
revert the refactor, split LCA into two rules
anchovYu Dec 9, 2022
b9f706f
better refactor
anchovYu Dec 9, 2022
94d5c9e
address comments
anchovYu Dec 9, 2022
d2e75fd
Merge branch 'SPARK-27561-refactor' into SPARK-27561-agg
anchovYu Dec 9, 2022
edde37c
basic version passing all tests
anchovYu Dec 9, 2022
fb7b18c
update the logic, add and refactor tests
anchovYu Dec 12, 2022
3698cff
update comments
anchovYu Dec 13, 2022
e700d6a
add a corner case comment
anchovYu Dec 13, 2022
8d20986
address comments
anchovYu Dec 13, 2022
d952aa7
Merge branch 'SPARK-27561-refactor' into SPARK-27561-agg
anchovYu Dec 13, 2022
44d5a3d
Merge remote-tracking branch 'apache/master' into SPARK-27561-agg
anchovYu Dec 13, 2022
ccebc1c
revert some changes
anchovYu Dec 13, 2022
5540b70
fix few todos
anchovYu Dec 13, 2022
338ba11
Merge remote-tracking branch 'apache/master' into SPARK-27561-agg
anchovYu Dec 16, 2022
136a930
fix the failing test
anchovYu Dec 16, 2022
5076ad2
fix the missing_aggregate issue, turn on conf to see failed tests
anchovYu Dec 19, 2022
2f2dee5
remove few todos
anchovYu Dec 19, 2022
3a5509a
better fix to maintain aggregate error: only lift up in certain cases
anchovYu Dec 20, 2022
a23debb
Merge remote-tracking branch 'apache/master' into SPARK-27561-agg
anchovYu Dec 20, 2022
b200da0
typo
anchovYu Dec 20, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix few todos
  • Loading branch information
anchovYu committed Dec 13, 2022
commit 5540b70c5216e2f28cdc007530f892c66f650bff
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,7 @@ object ResolveLateralColumnAliasReference extends Rule[LogicalPlan] {
private def assignAlias(expr: Expression): NamedExpression = {
expr match {
case ne: NamedExpression => ne
case e =>
Alias(e, toPrettySQL(e))()
case e => Alias(e, toPrettySQL(e))()
}
}

Expand Down Expand Up @@ -203,9 +202,6 @@ object ResolveLateralColumnAliasReference extends Rule[LogicalPlan] {
)
}
// TODO withOrigin?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need. All the results from resolveOperatorsUpWithPruning will have withOrigin around it.

// TODO potential risk. named_struct('a', avg(bonus)) AS foo, foo.a AS bar..
// foo.a is resolved to LCA(get struct field .. ). But later avg(bonus) is pushed down.
// it just resolves to the ne in the struct. is it still valid?
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@ class LateralColumnAliasSuite extends LateralColumnAliasSuiteBase {
| FROM (SELECT dept * 2.0 AS id, id + 1 AS id2 FROM $testTable)) > 5
|ORDER BY id
|""".stripMargin
withLCAOff { intercept[AnalysisException] { sql(query4) } } // surprisingly can't run ..
withLCAOff { intercept[AnalysisException] { sql(query4) } }
withLCAOn {
val analyzedPlan = sql(query4).queryExecution.analyzed
assert(!analyzedPlan.containsPattern(OUTER_REFERENCE))
Expand All @@ -517,10 +517,6 @@ class LateralColumnAliasSuite extends LateralColumnAliasSuiteBase {
| SELECT id2
| FROM (SELECT avg(salary * 1.0) AS id, id + 1 AS id2 FROM $testTable GROUP BY dept)) > 5
|""".stripMargin
// TODO: It no longer returns the following failure:
// [UNSUPPORTED_SUBQUERY_EXPRESSION_CATEGORY.NON_CORRELATED_COLUMNS_IN_GROUP_BY]
// Unsupported subquery expression: A GROUP BY clause in a scalar correlated subquery cannot
// contain non-correlated columns
val analyzedPlan = sql(query).queryExecution.analyzed
assert(!analyzedPlan.containsPattern(OUTER_REFERENCE))
}
Expand Down Expand Up @@ -563,28 +559,28 @@ class LateralColumnAliasSuite extends LateralColumnAliasSuiteBase {
sql(s"SELECT properties AS foo, foo.joinYear AS bar, bar + 1 " +
s"FROM $testTable GROUP BY properties HAVING properties.mostRecentEmployer = 'B'"),
Row(Row(2020, "B"), 2020, 2021))
// TODO fix this case without clearing out the metadata
// After applying rule org.apache.spark.sql.catalyst.optimizer.CollapseProject in batch
// Operator Optimization before Inferring Filters, the structural integrity of the plan
// is broken.
// It is because one output with the same exprId has auto generated alias as metadata, but
// others not.

checkAnswer(
sql(s"SELECT named_struct('avg_salary', avg(salary)) AS foo, foo.avg_salary + 1 AS bar " +
s"FROM $testTable GROUP BY dept ORDER BY dept"),
Row(Row(9500), 9501) :: Row(Row(11000), 11001) :: Row(Row(12000), 12001) :: Nil
)
}

// test("Lateral alias reference attribute further be used by upper plan - Project") {
// // this is out of the scope of lateral alias project functionality requirements, but naturally
// // supported by the current design
// checkAnswer(
// sql(s"SELECT properties AS new_properties, new_properties.joinYear AS new_join_year " +
// s"FROM $testTable WHERE dept = 1 ORDER BY new_join_year DESC"),
// Row(Row(2020, "B"), 2020) :: Row(Row(2019, "A"), 2019) :: Nil
// )
// }
test("Lateral alias reference attribute further be used by upper plan") {
// underlying this is not in the scope of lateral alias project but things already supported
checkAnswer(
sql(s"SELECT properties AS new_properties, new_properties.joinYear AS new_join_year " +
s"FROM $testTable WHERE dept = 1 ORDER BY new_join_year DESC"),
Row(Row(2020, "B"), 2020) :: Row(Row(2019, "A"), 2019) :: Nil
)

checkAnswer(
sql(s"SELECT avg(bonus) AS avg_bonus, avg_bonus * 1.0 AS new_avg_bonus, avg(salary) " +
s"FROM $testTable GROUP BY dept ORDER BY new_avg_bonus"),
Row(1100, 1100, 9500.0) :: Row(1200, 1200, 12000) :: Row(1250, 1250, 11000) :: Nil
)
}

test("Lateral alias chaining") {
// Project
Expand Down Expand Up @@ -665,7 +661,10 @@ class LateralColumnAliasSuite extends LateralColumnAliasSuiteBase {
sql(s"SELECT count(name) AS cnt, cnt + 1, count(unresovled) FROM $testTable GROUP BY dept")
}.getErrorClass == "UNRESOLVED_COLUMN.WITH_SUGGESTION")

// TODO: subquery
assert(intercept[AnalysisException] {
sql(s"SELECT * FROM range(1, 7) WHERE (" +
s"SELECT id2 FROM (SELECT 1 AS id, other_id + 1 AS id2)) > 5")
}.getErrorClass == "UNRESOLVED_COLUMN.WITHOUT_SUGGESTION")
}

test("Pushed-down aggregateExpressions should have no duplicates") {
Expand Down