xy720 commented on code in PR #66981:
URL: https://github.com/apache/doris/pull/66981#discussion_r3820216116
##########
fe/fe-core/src/test/java/org/apache/doris/nereids/rules/rewrite/CTEInlineTest.java:
##########
@@ -119,4 +128,69 @@ public void
refreshCteConsumersAfterNormalizeEliminatesEmptyBranch() {
connectContext.getSessionVariable().setDisableNereidsRules("");
}
}
+
+ @Test
+ public void testConstantOneRowCteAlwaysInlined() {
+ String sql = "WITH c AS (SELECT 1 AS a, 'x' AS b) "
+ + "SELECT * FROM c c1 JOIN c c2 ON c1.a = c2.a";
+
+ LogicalPlan analyzed = (LogicalPlan) PlanChecker.from(connectContext)
+ .analyze(sql)
+ .applyCustom(new PullUpCteAnchor())
+ .applyCustom(new CTEInline())
+ .getPlan();
+
+ assertNoCteNodes(analyzed);
+ }
+
+ @Test
+ public void testConstantOneRowCteWithManyConsumersInlined() {
+ String sql = "WITH consts AS ("
+ + " SELECT '2026-01-01' AS day_start, '2026-08-17' AS
day_end, "
+ + " '2025-01-01' AS tq_start, '2025-08-17' AS tq_end)"
+ + "SELECT * FROM consts c1, consts c2, consts c3, consts c4, "
+ + " consts c5, consts c6, consts c7, consts c8";
+
+ LogicalPlan analyzed = (LogicalPlan) PlanChecker.from(connectContext)
+ .analyze(sql)
+ .applyCustom(new PullUpCteAnchor())
+ .applyCustom(new CTEInline())
+ .getPlan();
+
+ assertNoCteNodes(analyzed);
+ }
+
+ @Test
+ public void testTableBackedCteNotForcedInline() {
+ String sql = "WITH t AS (SELECT id, score FROM T1) "
+ + "SELECT * FROM t x JOIN t y ON x.id = y.id";
+
+ PlanChecker.from(connectContext)
+ .analyze(sql)
+ .applyCustom(new PullUpCteAnchor())
+ .applyCustom(new CTEInline())
+ .matches(logicalCTEAnchor());
+ }
+
+ @Test
+ public void testNonDeterministicOneRowCteNotForcedInline() {
+ String sql = "WITH r AS (SELECT RANDOM() AS x) "
+ + "SELECT * FROM r r1 JOIN r r2 ON r1.x = r2.x";
+
+ PlanChecker.from(connectContext)
+ .analyze(sql)
+ .applyCustom(new PullUpCteAnchor())
+ .applyCustom(new CTEInline())
+ .matches(logicalCTEAnchor());
+ }
+
+ private static void assertNoCteNodes(LogicalPlan plan) {
+ plan.foreach(p -> {
+ if (p instanceof LogicalCTEAnchor || p instanceof
LogicalCTEProducer) {
Review Comment:
This is a ut case, no need to worry that.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]