Skip to content

Commit 698d62a

Browse files
committed
Fix tests and lint
1 parent b8b0882 commit 698d62a

File tree

3 files changed

+36
-56
lines changed

3 files changed

+36
-56
lines changed

core/src/main/java/org/apache/calcite/runtime/SqlFunctions.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6894,7 +6894,7 @@ public static Map map(Object... args) {
68946894
* @param queryLists array of lists, one per query
68956895
* @return list of Object arrays representing combined rows
68966896
*/
6897-
public static List<Object[]> combineQueryResults(List[] queryLists) {
6897+
public static List<@Nullable Object[]> combineQueryResults(List[] queryLists) {
68986898
// Find the maximum row count across all queries
68996899
int maxRows = 0;
69006900
for (List list : queryLists) {
@@ -6904,9 +6904,9 @@ public static List<Object[]> combineQueryResults(List[] queryLists) {
69046904
}
69056905

69066906
// Build the result rows
6907-
List<Object[]> result = new ArrayList<>(maxRows);
6907+
List<@Nullable Object[]> result = new ArrayList<>(maxRows);
69086908
for (int rowIdx = 0; rowIdx < maxRows; rowIdx++) {
6909-
Object[] row = new Object[queryLists.length];
6909+
@Nullable Object[] row = new Object[queryLists.length];
69106910
for (int queryIdx = 0; queryIdx < queryLists.length; queryIdx++) {
69116911
List queryList = queryLists[queryIdx];
69126912
if (rowIdx < queryList.size()) {

core/src/test/java/org/apache/calcite/test/SqlFunctionsTest.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@
8585
import static org.hamcrest.CoreMatchers.nullValue;
8686
import static org.hamcrest.MatcherAssert.assertThat;
8787
import static org.hamcrest.Matchers.closeTo;
88+
import static org.hamcrest.Matchers.hasSize;
8889
import static org.hamcrest.Matchers.hasToString;
8990
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
9091
import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -2057,4 +2058,36 @@ private long sqlTimestamp(String str) {
20572058
assertArrayEquals(new byte[]{(byte) 0x80, (byte) 0x00},
20582059
SqlFunctions.leftShift(new byte[]{(byte) 0x40, (byte) 0x00}, 1));
20592060
}
2061+
2062+
@Test void testCombineQueryResults() {
2063+
// Test combining two equal-length lists
2064+
List<Integer> list1 = Arrays.asList(1, 2, 3);
2065+
List<Integer> list2 = Arrays.asList(10, 20, 30);
2066+
List<Object[]> result = SqlFunctions.combineQueryResults(new List[]{list1, list2});
2067+
2068+
assertThat(result, hasSize(3));
2069+
assertArrayEquals(new Object[]{1, 10}, result.get(0));
2070+
assertArrayEquals(new Object[]{2, 20}, result.get(1));
2071+
assertArrayEquals(new Object[]{3, 30}, result.get(2));
2072+
2073+
// Test combining lists of different lengths (shorter list padded with nulls)
2074+
List<String> listA = Arrays.asList("a", "b");
2075+
List<String> listB = Arrays.asList("x", "y", "z", "w");
2076+
result = SqlFunctions.combineQueryResults(new List[]{listA, listB});
2077+
2078+
assertThat(result, hasSize(4));
2079+
assertArrayEquals(new Object[]{"a", "x"}, result.get(0));
2080+
assertArrayEquals(new Object[]{"b", "y"}, result.get(1));
2081+
assertArrayEquals(new Object[]{null, "z"}, result.get(2));
2082+
assertArrayEquals(new Object[]{null, "w"}, result.get(3));
2083+
2084+
// Test with empty list
2085+
List<Integer> emptyList = Collections.emptyList();
2086+
List<Integer> nonEmpty = Arrays.asList(100, 200);
2087+
result = SqlFunctions.combineQueryResults(new List[]{emptyList, nonEmpty});
2088+
2089+
assertThat(result, hasSize(2));
2090+
assertArrayEquals(new Object[]{null, 100}, result.get(0));
2091+
assertArrayEquals(new Object[]{null, 200}, result.get(1));
2092+
}
20602093
}

core/src/test/java/org/apache/calcite/test/enumerable/EnumerableCombineTest.java

Lines changed: 0 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -159,59 +159,6 @@ class EnumerableCombineTest {
159159
"QUERY_0={name=HR}; QUERY_1={empid=110, name=Theodore, deptno=10}");
160160
}
161161

162-
/**
163-
* Test that two queries selecting from the same table with different sort
164-
* orders do not conflict with each other. Each query maintains its own
165-
* independent results without one sort order overriding the other.
166-
*
167-
* <p>Query 1 sorts employees by empid ascending, Query 2 sorts by name descending.
168-
* The key verification is that both queries execute independently and produce
169-
* their own ordered results.
170-
*/
171-
@Test void testCombineSameTableDifferentSortOrders() {
172-
tester(new HrSchema())
173-
.withRel(
174-
builder -> {
175-
// Query 1: SELECT empid, name FROM emps ORDER BY empid ASC
176-
builder.scan("s", "emps")
177-
.project(
178-
builder.field("empid"),
179-
builder.field("name"))
180-
.sort(builder.field("empid"));
181-
182-
// Query 2: SELECT empid, name FROM emps ORDER BY name DESC
183-
builder.scan("s", "emps")
184-
.project(
185-
builder.field("empid"),
186-
builder.field("name"))
187-
.sort(builder.desc(builder.field("name")));
188-
189-
// Combine both queries
190-
return builder.combine(2).build();
191-
})
192-
.returns(resultSet -> {
193-
try {
194-
int rowCount = 0;
195-
while (resultSet.next()) {
196-
rowCount++;
197-
// Verify both columns have values (no cross-contamination)
198-
Object query0 = resultSet.getObject("QUERY_0");
199-
Object query1 = resultSet.getObject("QUERY_1");
200-
if (query0 == null || query1 == null) {
201-
throw new AssertionError(
202-
"Expected non-null values for both queries in row " + rowCount
203-
+ ", got QUERY_0=" + query0 + ", QUERY_1=" + query1);
204-
}
205-
}
206-
if (rowCount != 4) {
207-
throw new AssertionError("Expected 4 rows, got " + rowCount);
208-
}
209-
} catch (java.sql.SQLException e) {
210-
throw new RuntimeException(e);
211-
}
212-
});
213-
}
214-
215162
private CalciteAssert.AssertThat tester(Object schema) {
216163
return CalciteAssert.that()
217164
.with(CalciteConnectionProperty.LEX, Lex.JAVA)

0 commit comments

Comments
 (0)