Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BugFix] Fix NPE when cte forced inlined #40550

Merged
merged 2 commits into from
Feb 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,9 @@ public LogicalPlan transform(Relation relation) {

OptExprBuilder optExprBuilder;
Pair<OptExprBuilder, OptExprBuilder> cteRootAndMostDeepAnchor = buildCTEAnchorAndProducer(queryRelation);
if (cteRootAndMostDeepAnchor.first == null || cteRootAndMostDeepAnchor.second == null) {
return visit(relation);
}
optExprBuilder = cteRootAndMostDeepAnchor.first;
LogicalPlan logicalPlan = visit(relation);
cteRootAndMostDeepAnchor.second.addChild(logicalPlan.getRootBuilder());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,78 @@ public void testUnion() {
public void testUnionUnGather() {
runFileUnitTest("scheduler/union/union_ungather");
}

@Test
public void test() throws Exception {
String sql = "select met1.* from (\n" +
" with denominator as (select 1 as num),\n" +
" numerator as (select 1 as num)\n" +
" SELECT ROUND((SELECT COUNT(*) * 100 FROM numerator)\n" +
" / (SELECT COUNT(*) FROM denominator), 2)\n" +
" AS measure_score\n" +
" , (SELECT COUNT(*) FROM numerator) AS numerator_count\n" +
" , (SELECT COUNT(*) FROM denominator) AS denominator_count\n" +
") as met1\n" +
"union all\n" +
"select met2.* from (\n" +
" with denominator as (select 1 as num),\n" +
" numerator as (select 1 as num)\n" +
" SELECT ROUND((SELECT COUNT(*) * 100 FROM numerator)\n" +
" / (SELECT COUNT(*) FROM denominator), 2)\n" +
" AS measure_score\n" +
" , (SELECT COUNT(*) FROM numerator) AS numerator_count\n" +
" , (SELECT COUNT(*) FROM denominator) AS denominator_count\n" +
") as met2\n" +
"union all\n" +
"select met3.* from (\n" +
" with denominator as (select 1 as num),\n" +
" numerator as (select 1 as num)\n" +
" SELECT ROUND((SELECT COUNT(*) * 100 FROM numerator)\n" +
" / (SELECT COUNT(*) FROM denominator), 2)\n" +
" AS measure_score\n" +
" , (SELECT COUNT(*) FROM numerator) AS numerator_count\n" +
" , (SELECT COUNT(*) FROM denominator) AS denominator_count\n" +
") as met3\n" +
"union all\n" +
"select met4.* from (\n" +
" with denominator as (select 1 as num),\n" +
" numerator as (select 1 as num)\n" +
" SELECT ROUND((SELECT COUNT(*) * 100 FROM numerator)\n" +
" / (SELECT COUNT(*) FROM denominator), 2)\n" +
" AS measure_score\n" +
" , (SELECT COUNT(*) FROM numerator) AS numerator_count\n" +
" , (SELECT COUNT(*) FROM denominator) AS denominator_count\n" +
") as met4\n" +
"union all\n" +
"select met5.* from (\n" +
" with denominator as (select 1 as num),\n" +
" numerator as (select 1 as num)\n" +
" SELECT ROUND((SELECT COUNT(*) * 100 FROM numerator)\n" +
" / (SELECT COUNT(*) FROM denominator), 2)\n" +
" AS measure_score\n" +
" , (SELECT COUNT(*) FROM numerator) AS numerator_count\n" +
" , (SELECT COUNT(*) FROM denominator) AS denominator_count\n" +
") as met5\n" +
"union all\n" +
"select met6.* from (\n" +
" with denominator as (select 1 as num),\n" +
" numerator as (select 1 as num)\n" +
" SELECT ROUND((SELECT COUNT(*) * 100 FROM numerator)\n" +
" / (SELECT COUNT(*) FROM denominator), 2)\n" +
" AS measure_score\n" +
" , (SELECT COUNT(*) FROM numerator) AS numerator_count\n" +
" , (SELECT COUNT(*) FROM denominator) AS denominator_count\n" +
") as met6\n" +
"union all\n" +
"select met7.* from (\n" +
" with denominator as (select 1 as num),\n" +
" numerator as (select 1 as num)\n" +
" SELECT ROUND((SELECT COUNT(*) * 100 FROM numerator)\n" +
" / (SELECT COUNT(*) FROM denominator), 2)\n" +
" AS measure_score\n" +
" , (SELECT COUNT(*) FROM numerator) AS numerator_count\n" +
" , (SELECT COUNT(*) FROM denominator) AS denominator_count\n" +
") as met7";
getFragmentPlan(sql);
}
}
Loading