diff --git a/sql/src/test/java/org/apache/druid/sql/calcite/BaseCalciteQueryTest.java b/sql/src/test/java/org/apache/druid/sql/calcite/BaseCalciteQueryTest.java index 16f64270172..fc76039982a 100644 --- a/sql/src/test/java/org/apache/druid/sql/calcite/BaseCalciteQueryTest.java +++ b/sql/src/test/java/org/apache/druid/sql/calcite/BaseCalciteQueryTest.java @@ -86,6 +86,7 @@ import org.apache.druid.server.security.AuthenticationResult; import org.apache.druid.server.security.ForbiddenException; import org.apache.druid.server.security.ResourceAction; import org.apache.druid.sql.SqlStatementFactory; +import org.apache.druid.sql.calcite.QueryTestRunner.QueryResults; import org.apache.druid.sql.calcite.expression.DruidExpression; import org.apache.druid.sql.calcite.planner.Calcites; import org.apache.druid.sql.calcite.planner.PlannerConfig; @@ -120,6 +121,8 @@ import org.junit.rules.ExpectedException; import org.junit.rules.TemporaryFolder; import javax.annotation.Nullable; + +import static org.junit.Assert.assertEquals; import java.io.IOException; import java.io.PrintStream; import java.util.Arrays; @@ -1054,6 +1057,36 @@ public class BaseCalciteQueryTest extends CalciteTestBase } } + public void assertResultsValid(String message, List expected, QueryResults queryResults) + { + + List results = queryResults.results; + int numRows = Math.min(results.size(), expected.size()); + for (int row = 0; row < numRows; row++) { + Object[] expectedRow = expected.get(row); + Object[] resultRow = results.get(row); + assertEquals("column count mismatch; at row#" + row, expectedRow.length, resultRow.length); + + for (int i = 0; i < resultRow.length; i++) { + Object resultCell = resultRow[i]; + Object expectedCell = expectedRow[i]; + + if(expectedCell == null) { + if(resultCell == null) { + continue; + } + expectedCell = NullHandling.defaultValueForType(queryResults.signature.getColumnType(i).get().getType()); + } + assertEquals( + String.format("column content mismatch at %d,%d", row, i), + expectedCell, + resultCell); + } + + } + + } + public void assertResultsEquals(String sql, List expectedResults, List results) { for (int i = 0; i < results.size(); i++) { diff --git a/sql/src/test/java/org/apache/druid/sql/calcite/CalciteWindowQueryTest.java b/sql/src/test/java/org/apache/druid/sql/calcite/CalciteWindowQueryTest.java index d73520023d2..464d10e93cb 100644 --- a/sql/src/test/java/org/apache/druid/sql/calcite/CalciteWindowQueryTest.java +++ b/sql/src/test/java/org/apache/druid/sql/calcite/CalciteWindowQueryTest.java @@ -79,9 +79,7 @@ public class CalciteWindowQueryTest extends BaseCalciteQueryTest final URL windowFolderUrl = ClassLoader.getSystemResource("calcite/tests/window"); File windowFolder = new File(windowFolderUrl.toURI()); - final File[] listedFiles = windowFolder.listFiles( - pathname -> pathname.getName().toLowerCase(Locale.ROOT).endsWith(".sqltest") - ); + final File[] listedFiles = windowFolder.listFiles(pathname -> pathname.getName().toLowerCase(Locale.ROOT).endsWith(".sqltest")); return Arrays .stream(Objects.requireNonNull(listedFiles)) @@ -198,12 +196,11 @@ public class CalciteWindowQueryTest extends BaseCalciteQueryTest throw new ISE("result[%s] was type[%s]!? Expected it to be numerical", i, types[i].getType()); } } - } else { - result[i] = NullHandling.defaultValueForType(types[i].getType()); } } } - assertResultsEquals(filename, input.expectedResults, results.results); + + assertResultsValid(filename, input.expectedResults, results); } }