diff --git a/core/src/test/java/org/apache/calcite/test/SqlToRelConverterTest.java b/core/src/test/java/org/apache/calcite/test/SqlToRelConverterTest.java index e07c77b..38975aa 100644 --- a/core/src/test/java/org/apache/calcite/test/SqlToRelConverterTest.java +++ b/core/src/test/java/org/apache/calcite/test/SqlToRelConverterTest.java @@ -16,8 +16,10 @@ */ package org.apache.calcite.test; +import org.apache.calcite.plan.RelOptUtil; import org.apache.calcite.prepare.Prepare; import org.apache.calcite.rel.RelNode; +import org.apache.calcite.rel.RelRoot; import org.apache.calcite.rel.RelVisitor; import org.apache.calcite.rel.externalize.RelXmlWriter; import org.apache.calcite.rel.type.RelDataType; @@ -38,6 +40,9 @@ import java.io.PrintWriter; import java.io.StringWriter; +import static org.hamcrest.CoreMatchers.notNullValue; +import static org.junit.Assert.assertThat; + /** * Unit test for {@link org.apache.calcite.sql2rel.SqlToRelConverter}. */ @@ -1879,6 +1884,18 @@ private Tester getTesterWithDynamicTable() { }); } + @Test public void testLarge() { + SqlValidatorTest.testLarge(400, + new Function() { + public Void apply(String input) { + final RelRoot root = tester.convertSqlToRel(input); + final String s = RelOptUtil.toString(root.project()); + assertThat(s, notNullValue()); + return null; + } + }); + } + /** * Visitor that checks that every {@link RelNode} in a tree is valid. * diff --git a/core/src/test/java/org/apache/calcite/test/SqlValidatorTest.java b/core/src/test/java/org/apache/calcite/test/SqlValidatorTest.java index 57f71d1..e9d0007 100644 --- a/core/src/test/java/org/apache/calcite/test/SqlValidatorTest.java +++ b/core/src/test/java/org/apache/calcite/test/SqlValidatorTest.java @@ -16,6 +16,7 @@ */ package org.apache.calcite.test; +import com.google.common.base.Function; import org.apache.calcite.avatica.util.Casing; import org.apache.calcite.avatica.util.Quoting; import org.apache.calcite.avatica.util.TimeUnit; @@ -5668,7 +5669,16 @@ public void _testJoinUsing() { * lurking in the validation process. */ @Test public void testLarge() { - int x = 700; + testLarge(700, + new Function() { + public Void apply(String input) { + check(input); + return null; + } + }); + } + + public static void testLarge(int x, Function f) { if (System.getProperty("os.name").startsWith("Windows")) { // NOTE jvs 1-Nov-2006: Default thread stack size // on Windows is too small, so avoid stack overflow @@ -5677,29 +5687,29 @@ public void _testJoinUsing() { // E.g. large = "deptno * 1 + deptno * 2 + deptno * 3". String large = list(" + ", "deptno * ", x); - check("select " + large + "from emp"); - check("select distinct " + large + "from emp"); - check("select " + large + " from emp " + "group by deptno"); - check("select * from emp where " + large + " > 5"); - check("select * from emp order by " + large + " desc"); - check("select " + large + " from emp order by 1"); - check("select distinct " + large + " from emp order by " + large); + f.apply("select " + large + "from emp"); + f.apply("select distinct " + large + "from emp"); + f.apply("select " + large + " from emp " + "group by deptno"); + f.apply("select * from emp where " + large + " > 5"); + f.apply("select * from emp order by " + large + " desc"); + f.apply("select " + large + " from emp order by 1"); + f.apply("select distinct " + large + " from emp order by " + large); // E.g. "in (0, 1, 2, ...)" - check("select * from emp where deptno in (" + list(", ", "", x) + ")"); + f.apply("select * from emp where deptno in (" + list(", ", "", x) + ")"); // E.g. "where x = 1 or x = 2 or x = 3 ..." - check("select * from emp where " + list(" or ", "deptno = ", x)); + f.apply("select * from emp where " + list(" or ", "deptno = ", x)); // E.g. "select x1, x2 ... from ( // select 'a' as x1, 'a' as x2, ... from emp union // select 'bb' as x1, 'bb' as x2, ... from dept)" - check("select " + list(", ", "x", x) + f.apply("select " + list(", ", "x", x) + " from (select " + list(", ", "'a' as x", x) + " from emp " + "union all select " + list(", ", "'bb' as x", x) + " from dept)"); } - private String list(String sep, String before, int count) { + private static String list(String sep, String before, int count) { StringBuilder buf = new StringBuilder(); for (int i = 0; i 0) {