xiedeyantu commented on code in PR #4544:
URL: https://github.com/apache/calcite/pull/4544#discussion_r2446463103
##########
core/src/test/java/org/apache/calcite/test/RelBuilderTest.java:
##########
@@ -5609,6 +5898,55 @@ private static RelNode
buildCorrelateWithJoin(JoinRelType type, RelBuilder build
"empid=150; name=Sebastian");
}
+ /** Test case for
+ * <a
href="https://issues.apache.org/jira/browse/CALCITE-1440">[CALCITE-1440]
+ * Combine operator - combines multiple SQL queries into a single plan</a>.
*/
+ @Test void testCombineExplain() {
+ final RelBuilder builder = RelBuilder.create(config().build());
+
+ // Query 1: Simple filter on department 10
+ RelNode query1 = builder
+ .scan("EMP")
+ .filter(builder.equals(builder.field("DEPTNO"), builder.literal(10)))
+ .project(builder.field("ENAME"), builder.field("SAL"))
+ .build();
+
+ // Query 2: Aggregate to get average salary by department
+ RelNode query2 = builder
+ .scan("EMP")
+ .aggregate(builder.groupKey("DEPTNO"),
+ builder.avg(false, "AVG_SAL", builder.field("SAL")))
+ .build();
+
+ // Query 3: Find all departments
+ RelNode query3 = builder
+ .scan("DEPT")
+ .project(builder.field("DEPTNO"), builder.field("DNAME"))
+ .build();
+
+ // Combine all three queries
+ RelNode combined = builder.combine(query1, query2, query3).build();
+
+ // Test that the combine node is of the correct type
+ assertThat(combined, instanceOf(Combine.class));
+ Combine combineNode = (Combine) combined;
+ assertThat(combineNode.getInputs(), hasSize(3));
+
+ String expectedPlan =
Review Comment:
Yes, this is one part I'd like to see. The other part is automatically
adding the Combine operator during volcano optimization. As you mentioned, this
could be handled by subsequent optimization rules or default volcano behaviors,
which can be addressed through a new JIRA ticket.
--
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]