xiedeyantu commented on code in PR #4658:
URL: https://github.com/apache/calcite/pull/4658#discussion_r2587675293
##########
core/src/test/java/org/apache/calcite/test/enumerable/EnumerableCombineTest.java:
##########
@@ -149,9 +154,62 @@ class EnumerableCombineTest {
return builder.combine(2).build();
})
.returnsUnordered(
- "QUERY=[{name=Sales}, {name=Marketing}, {name=HR}]",
- "QUERY=[{empid=100, name=Bill, deptno=10}, {empid=150,
name=Sebastian, deptno=10}, "
- + "{empid=110, name=Theodore, deptno=10}]");
+ "QUERY_0={name=Sales}; QUERY_1={empid=100, name=Bill, deptno=10}",
+ "QUERY_0={name=Marketing}; QUERY_1={empid=150, name=Sebastian,
deptno=10}",
+ "QUERY_0={name=HR}; QUERY_1={empid=110, name=Theodore,
deptno=10}");
+ }
+
+ /**
+ * Test that two queries selecting from the same table with different sort
+ * orders do not conflict with each other. Each query maintains its own
+ * independent results without one sort order overriding the other.
+ *
+ * <p>Query 1 sorts employees by empid ascending, Query 2 sorts by name
descending.
+ * The key verification is that both queries execute independently and
produce
+ * their own ordered results.
+ */
+ @Test void testCombineSameTableDifferentSortOrders() {
+ tester(new HrSchema())
+ .withRel(
+ builder -> {
+ // Query 1: SELECT empid, name FROM emps ORDER BY empid ASC
+ builder.scan("s", "emps")
+ .project(
+ builder.field("empid"),
+ builder.field("name"))
+ .sort(builder.field("empid"));
+
+ // Query 2: SELECT empid, name FROM emps ORDER BY name DESC
+ builder.scan("s", "emps")
+ .project(
+ builder.field("empid"),
+ builder.field("name"))
+ .sort(builder.desc(builder.field("name")));
+
+ // Combine both queries
+ return builder.combine(2).build();
+ })
+ .returns(resultSet -> {
+ try {
+ int rowCount = 0;
+ while (resultSet.next()) {
+ rowCount++;
+ // Verify both columns have values (no cross-contamination)
+ Object query0 = resultSet.getObject("QUERY_0");
+ Object query1 = resultSet.getObject("QUERY_1");
+ if (query0 == null || query1 == null) {
Review Comment:
Would it be better to use AssertThat for positive validation? I don't
understand why the throw new AssertionError approach is used here.
##########
core/src/main/java/org/apache/calcite/runtime/SqlFunctions.java:
##########
@@ -6884,6 +6884,43 @@ public static Map map(Object... args) {
return map;
}
+ /** Combines multiple query result lists into rows for the Combine operator.
+ *
+ * <p>Each input list contains maps representing rows from a query.
+ * The output is a list of Object arrays, where each array is a row
+ * with one element per query. The number of output rows equals the
+ * maximum size across all input lists. Shorter lists are padded with nulls.
+ *
+ * @param queryLists array of lists, one per query
+ * @return list of Object arrays representing combined rows
+ */
+ public static List<Object[]> combineQueryResults(List[] queryLists) {
Review Comment:
Can you add a small test for this method?
--
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]