Repository: calcite Updated Branches: refs/heads/master 337f24797 -> 37a6f9f4f
http://git-wip-us.apache.org/repos/asf/calcite/blob/c69e1bcb/core/src/test/java/org/apache/calcite/test/SqlValidatorTestCase.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/calcite/test/SqlValidatorTestCase.java b/core/src/test/java/org/apache/calcite/test/SqlValidatorTestCase.java index 9160d57..eb34b57 100644 --- a/core/src/test/java/org/apache/calcite/test/SqlValidatorTestCase.java +++ b/core/src/test/java/org/apache/calcite/test/SqlValidatorTestCase.java @@ -17,33 +17,29 @@ package org.apache.calcite.test; import org.apache.calcite.rel.type.RelDataType; -import org.apache.calcite.runtime.CalciteContextException; import org.apache.calcite.sql.SqlCollation; import org.apache.calcite.sql.SqlNode; import org.apache.calcite.sql.parser.SqlParseException; import org.apache.calcite.sql.parser.SqlParserUtil; +import org.apache.calcite.sql.test.AbstractSqlTester; import org.apache.calcite.sql.test.SqlTestFactory; import org.apache.calcite.sql.test.SqlTester; -import org.apache.calcite.sql.test.SqlTesterImpl; +import org.apache.calcite.sql.test.SqlTests; +import org.apache.calcite.sql.test.SqlValidatorTester; import org.apache.calcite.sql.validate.SqlConformance; import org.apache.calcite.sql.validate.SqlConformanceEnum; import org.apache.calcite.sql.validate.SqlMonotonicity; import org.apache.calcite.sql.validate.SqlValidator; import org.apache.calcite.test.catalog.MockCatalogReaderExtended; -import org.apache.calcite.util.TestUtil; -import org.apache.calcite.util.Util; import org.junit.rules.MethodRule; import org.junit.runners.model.FrameworkMethod; import org.junit.runners.model.Statement; import java.nio.charset.Charset; -import java.util.regex.Matcher; -import java.util.regex.Pattern; import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.assertThat; -import static org.junit.Assert.fail; /** * An abstract base class for implementing tests against {@link SqlValidator}. @@ -59,25 +55,18 @@ import static org.junit.Assert.fail; public class SqlValidatorTestCase { //~ Static fields/initializers --------------------------------------------- - private static final Pattern LINE_COL_PATTERN = - Pattern.compile("At line ([0-9]+), column ([0-9]+)"); - - private static final Pattern LINE_COL_TWICE_PATTERN = - Pattern.compile( - "(?s)From line ([0-9]+), column ([0-9]+) to line ([0-9]+), column ([0-9]+): (.*)"); - private static final SqlTestFactory EXTENDED_TEST_FACTORY = SqlTestFactory.INSTANCE.withCatalogReader(MockCatalogReaderExtended::new); - static final SqlTesterImpl EXTENDED_CATALOG_TESTER = - new SqlTesterImpl(EXTENDED_TEST_FACTORY); + static final SqlTester EXTENDED_CATALOG_TESTER = + new SqlValidatorTester(EXTENDED_TEST_FACTORY); - static final SqlTesterImpl EXTENDED_CATALOG_TESTER_2003 = - new SqlTesterImpl(EXTENDED_TEST_FACTORY) + static final SqlTester EXTENDED_CATALOG_TESTER_2003 = + new SqlValidatorTester(EXTENDED_TEST_FACTORY) .withConformance(SqlConformanceEnum.PRAGMATIC_2003); - static final SqlTesterImpl EXTENDED_CATALOG_TESTER_LENIENT = - new SqlTesterImpl(EXTENDED_TEST_FACTORY) + static final SqlTester EXTENDED_CATALOG_TESTER_LENIENT = + new SqlValidatorTester(EXTENDED_TEST_FACTORY) .withConformance(SqlConformanceEnum.LENIENT); public static final MethodRule TESTER_CONFIGURATION_RULE = new TesterConfigurationRule(); @@ -102,7 +91,7 @@ public class SqlValidatorTestCase { * same set of tests in a different testing environment. */ public SqlTester getTester() { - return new SqlTesterImpl(SqlTestFactory.INSTANCE); + return new SqlValidatorTester(SqlTestFactory.INSTANCE); } public final Sql sql(String sql) { @@ -135,7 +124,7 @@ public class SqlValidatorTestCase { public void checkExp(String sql) { tester.assertExceptionIsThrown( - SqlTesterImpl.buildQuery(sql), + AbstractSqlTester.buildQuery(sql), null); } @@ -156,7 +145,7 @@ public class SqlValidatorTestCase { String sql, String expected) { tester.assertExceptionIsThrown( - SqlTesterImpl.buildQuery(sql), + AbstractSqlTester.buildQuery(sql), expected); } @@ -175,7 +164,7 @@ public class SqlValidatorTestCase { String sql, String expected) { checkColumnType( - SqlTesterImpl.buildQuery(sql), + AbstractSqlTester.buildQuery(sql), expected); } @@ -224,7 +213,7 @@ public class SqlValidatorTestCase { String sql, String expected) { tester.checkIntervalConv( - SqlTesterImpl.buildQuery(sql), + AbstractSqlTester.buildQuery(sql), expected); } @@ -260,174 +249,7 @@ public class SqlValidatorTestCase { Throwable ex, String expectedMsgPattern, SqlParserUtil.StringAndPos sap) { - if (null == ex) { - if (expectedMsgPattern == null) { - // No error expected, and no error happened. - return; - } else { - throw new AssertionError("Expected query to throw exception, " - + "but it did not; query [" + sap.sql - + "]; expected [" + expectedMsgPattern + "]"); - } - } - Throwable actualException = ex; - String actualMessage = actualException.getMessage(); - int actualLine = -1; - int actualColumn = -1; - int actualEndLine = 100; - int actualEndColumn = 99; - - // Search for an CalciteContextException somewhere in the stack. - CalciteContextException ece = null; - for (Throwable x = ex; x != null; x = x.getCause()) { - if (x instanceof CalciteContextException) { - ece = (CalciteContextException) x; - break; - } - if (x.getCause() == x) { - break; - } - } - - // Search for a SqlParseException -- with its position set -- somewhere - // in the stack. - SqlParseException spe = null; - for (Throwable x = ex; x != null; x = x.getCause()) { - if ((x instanceof SqlParseException) - && (((SqlParseException) x).getPos() != null)) { - spe = (SqlParseException) x; - break; - } - if (x.getCause() == x) { - break; - } - } - - if (ece != null) { - actualLine = ece.getPosLine(); - actualColumn = ece.getPosColumn(); - actualEndLine = ece.getEndPosLine(); - actualEndColumn = ece.getEndPosColumn(); - if (ece.getCause() != null) { - actualException = ece.getCause(); - actualMessage = actualException.getMessage(); - } - } else if (spe != null) { - actualLine = spe.getPos().getLineNum(); - actualColumn = spe.getPos().getColumnNum(); - actualEndLine = spe.getPos().getEndLineNum(); - actualEndColumn = spe.getPos().getEndColumnNum(); - if (spe.getCause() != null) { - actualException = spe.getCause(); - actualMessage = actualException.getMessage(); - } - } else { - final String message = ex.getMessage(); - if (message != null) { - Matcher matcher = LINE_COL_TWICE_PATTERN.matcher(message); - if (matcher.matches()) { - actualLine = Integer.parseInt(matcher.group(1)); - actualColumn = Integer.parseInt(matcher.group(2)); - actualEndLine = Integer.parseInt(matcher.group(3)); - actualEndColumn = Integer.parseInt(matcher.group(4)); - actualMessage = matcher.group(5); - } else { - matcher = LINE_COL_PATTERN.matcher(message); - if (matcher.matches()) { - actualLine = Integer.parseInt(matcher.group(1)); - actualColumn = Integer.parseInt(matcher.group(2)); - } else { - if (expectedMsgPattern != null - && actualMessage.matches(expectedMsgPattern)) { - return; - } - } - } - } - } - - if (null == expectedMsgPattern) { - actualException.printStackTrace(); - fail("Validator threw unexpected exception" - + "; query [" + sap.sql - + "]; exception [" + actualMessage - + "]; class [" + actualException.getClass() - + "]; pos [line " + actualLine - + " col " + actualColumn - + " thru line " + actualLine - + " col " + actualColumn + "]"); - } - - String sqlWithCarets; - if (actualColumn <= 0 - || actualLine <= 0 - || actualEndColumn <= 0 - || actualEndLine <= 0) { - if (sap.pos != null) { - AssertionError e = - new AssertionError("Expected error to have position," - + " but actual error did not: " - + " actual pos [line " + actualLine - + " col " + actualColumn - + " thru line " + actualEndLine + " col " - + actualEndColumn + "]"); - e.initCause(actualException); - throw e; - } - sqlWithCarets = sap.sql; - } else { - sqlWithCarets = - SqlParserUtil.addCarets( - sap.sql, - actualLine, - actualColumn, - actualEndLine, - actualEndColumn + 1); - if (sap.pos == null) { - throw new AssertionError("Actual error had a position, but expected " - + "error did not. Add error position carets to sql:\n" - + sqlWithCarets); - } - } - - if (actualMessage != null) { - actualMessage = Util.toLinux(actualMessage); - } - - if (actualMessage == null - || !actualMessage.matches(expectedMsgPattern)) { - actualException.printStackTrace(); - final String actualJavaRegexp = - (actualMessage == null) - ? "null" - : TestUtil.quoteForJava( - TestUtil.quotePattern(actualMessage)); - fail("Validator threw different " - + "exception than expected; query [" + sap.sql - + "];\n" - + " expected pattern [" + expectedMsgPattern - + "];\n" - + " actual [" + actualMessage - + "];\n" - + " actual as java regexp [" + actualJavaRegexp - + "]; pos [" + actualLine - + " col " + actualColumn - + " thru line " + actualEndLine - + " col " + actualEndColumn - + "]; sql [" + sqlWithCarets + "]"); - } else if (sap.pos != null - && (actualLine != sap.pos.getLineNum() - || actualColumn != sap.pos.getColumnNum() - || actualEndLine != sap.pos.getEndLineNum() - || actualEndColumn != sap.pos.getEndColumnNum())) { - fail("Validator threw expected " - + "exception [" + actualMessage - + "];\nbut at pos [line " + actualLine - + " col " + actualColumn - + " thru line " + actualEndLine - + " col " + actualEndColumn - + "];\nsql [" + sqlWithCarets + "]"); - } + SqlTests.checkEx(ex, expectedMsgPattern, sap, SqlTests.Stage.VALIDATE); } //~ Inner Interfaces ------------------------------------------------------- @@ -570,7 +392,7 @@ public class SqlValidatorTestCase { */ Sql(SqlTester tester, String sql, boolean query) { this.tester = tester; - this.sql = query ? sql : SqlTesterImpl.buildQuery(sql); + this.sql = query ? sql : AbstractSqlTester.buildQuery(sql); } Sql tester(SqlTester tester) { http://git-wip-us.apache.org/repos/asf/calcite/blob/c69e1bcb/core/src/test/resources/sql/misc.iq ---------------------------------------------------------------------- diff --git a/core/src/test/resources/sql/misc.iq b/core/src/test/resources/sql/misc.iq index 2bce8fd..fdb691d 100644 --- a/core/src/test/resources/sql/misc.iq +++ b/core/src/test/resources/sql/misc.iq @@ -1762,6 +1762,8 @@ EnumerableCalc(expr#0=[{inputs}], expr#1=['TR'], expr#2=['UE'], expr#3=[||($t1, EnumerableValues(tuples=[[{ 0 }]]) !plan +!if (fixed.calcite2539) { + # In the following, that we get an error at run time, # and that the plan shows that the expression has not been reduced. values cast('null' as boolean); @@ -1824,6 +1826,7 @@ Caused by: java.lang.NumberFormatException: For input string: "4567891234" values cast('12345678901234567890' as bigint); Caused by: java.lang.NumberFormatException: For input string: "12345678901234567890" !error +!} # Out of REAL range # (Should give an error, not infinity.) http://git-wip-us.apache.org/repos/asf/calcite/blob/c69e1bcb/core/src/test/resources/sql/spatial.iq ---------------------------------------------------------------------- diff --git a/core/src/test/resources/sql/spatial.iq b/core/src/test/resources/sql/spatial.iq index 95003ff..fa32f49 100755 --- a/core/src/test/resources/sql/spatial.iq +++ b/core/src/test/resources/sql/spatial.iq @@ -802,6 +802,7 @@ EXPR$0 {"rings":[[[11,11],[11,19],[19,19],[19,11],[11,11]]]} !ok +!if (fixed.calcite2539) { # ST_BUFFER(geom, bufferSize, style) variant - not implemented SELECT ST_Buffer( ST_GeomFromText('POINT(100 90)'), @@ -816,6 +817,7 @@ SELECT ST_Buffer( 50, 2); at org.apache.calcite.runtime.GeoFunctions.todo !error GeoFunctions +!} # ST_ConvexHull(geom) Computes the smallest convex polygon that contains all the points in the Geometry # Not implemented