Package org.apache.calcite.test
Class SqlValidatorTestCase
- java.lang.Object
-
- org.apache.calcite.test.SqlValidatorTestCase
-
- Direct Known Subclasses:
SqlAdvisorTest
,SqlValidatorDynamicTest
,SqlValidatorFeatureTest
,SqlValidatorMatchTest
,SqlValidatorTest
public class SqlValidatorTestCase extends java.lang.Object
An abstract base class for implementing tests againstSqlValidator
.A derived class can refine this test in two ways. First, it can add
testXxx()
methods, to test more functionality.Second, it can override the
getTester()
method to return a different implementation of theSqlValidatorTestCase.Tester
object. This encapsulates the differences between test environments, for example, which SQL parser or validator to use.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static class
SqlValidatorTestCase.Sql
Fluent testing API.static interface
SqlValidatorTestCase.Tester
Encapsulates differences between test environments, for example, which SQL parser or validator to use.private static class
SqlValidatorTestCase.TesterConfigurationRule
Enables to configuretester
behavior on a per-test basis.
-
Field Summary
Fields Modifier and Type Field Description (package private) static SqlTester
EXTENDED_CATALOG_TESTER
(package private) static SqlTester
EXTENDED_CATALOG_TESTER_2003
(package private) static SqlTester
EXTENDED_CATALOG_TESTER_LENIENT
private static SqlTestFactory
EXTENDED_TEST_FACTORY
protected SqlTester
tester
static org.junit.rules.MethodRule
TESTER_CONFIGURATION_RULE
-
Constructor Summary
Constructors Constructor Description SqlValidatorTestCase()
Creates a test case.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
assertExceptionIsThrown(java.lang.String sql, java.lang.String expectedMsgPattern)
void
check(java.lang.String sql)
void
checkCharset(java.lang.String sql, java.nio.charset.Charset expectedCharset)
void
checkCollation(java.lang.String sql, java.lang.String expectedCollationName, org.apache.calcite.sql.SqlCollation.Coercibility expectedCoercibility)
void
checkColumnType(java.lang.String sql, java.lang.String expected)
Checks that a query returns a single column, and that the column has the expected type.static void
checkEx(java.lang.Throwable ex, java.lang.String expectedMsgPattern, org.apache.calcite.sql.parser.SqlParserUtil.StringAndPos sap)
Checks whether an exception matches the expected pattern.void
checkExp(java.lang.String sql)
void
checkExpFails(java.lang.String sql, java.lang.String expected)
Checks that a SQL expression gives a particular error.void
checkExpType(java.lang.String sql, java.lang.String expected)
void
checkFails(java.lang.String sql, java.lang.String expected)
Checks that a SQL query gives a particular error, or succeeds ifexpected
is null.void
checkIntervalConv(java.lang.String sql, java.lang.String expected)
Checks that the first column returned by a query has the expected type.void
checkResultType(java.lang.String sql, java.lang.String expected)
Checks that a query returns a row of the expected type.void
checkWholeExpFails(java.lang.String sql, java.lang.String expected)
Checks that a SQL expression gives a particular error, and that the location of the error is the whole expression.SqlValidatorTestCase.Sql
expr(java.lang.String sql)
SqlTester
getTester()
Returns a tester.SqlValidatorTestCase.Sql
sql(java.lang.String sql)
SqlValidatorTestCase.Sql
win(java.lang.String sql)
SqlValidatorTestCase.Sql
winExp(java.lang.String sql)
SqlValidatorTestCase.Sql
winExp2(java.lang.String sql)
SqlValidatorTestCase.Sql
winSql(java.lang.String sql)
-
-
-
Field Detail
-
EXTENDED_TEST_FACTORY
private static final SqlTestFactory EXTENDED_TEST_FACTORY
-
EXTENDED_CATALOG_TESTER
static final SqlTester EXTENDED_CATALOG_TESTER
-
EXTENDED_CATALOG_TESTER_2003
static final SqlTester EXTENDED_CATALOG_TESTER_2003
-
EXTENDED_CATALOG_TESTER_LENIENT
static final SqlTester EXTENDED_CATALOG_TESTER_LENIENT
-
TESTER_CONFIGURATION_RULE
public static final org.junit.rules.MethodRule TESTER_CONFIGURATION_RULE
-
tester
protected SqlTester tester
-
-
Method Detail
-
getTester
public SqlTester getTester()
Returns a tester. Derived classes should override this method to run the same set of tests in a different testing environment.
-
sql
public final SqlValidatorTestCase.Sql sql(java.lang.String sql)
-
expr
public final SqlValidatorTestCase.Sql expr(java.lang.String sql)
-
winSql
public final SqlValidatorTestCase.Sql winSql(java.lang.String sql)
-
win
public final SqlValidatorTestCase.Sql win(java.lang.String sql)
-
winExp
public SqlValidatorTestCase.Sql winExp(java.lang.String sql)
-
winExp2
public SqlValidatorTestCase.Sql winExp2(java.lang.String sql)
-
check
public void check(java.lang.String sql)
-
checkExp
public void checkExp(java.lang.String sql)
-
checkFails
public final void checkFails(java.lang.String sql, java.lang.String expected)
Checks that a SQL query gives a particular error, or succeeds ifexpected
is null.
-
checkExpFails
public final void checkExpFails(java.lang.String sql, java.lang.String expected)
Checks that a SQL expression gives a particular error.
-
checkWholeExpFails
public final void checkWholeExpFails(java.lang.String sql, java.lang.String expected)
Checks that a SQL expression gives a particular error, and that the location of the error is the whole expression.
-
checkExpType
public final void checkExpType(java.lang.String sql, java.lang.String expected)
-
checkColumnType
public final void checkColumnType(java.lang.String sql, java.lang.String expected)
Checks that a query returns a single column, and that the column has the expected type. For example,checkColumnType("SELECT empno FROM Emp", "INTEGER NOT NULL");
- Parameters:
sql
- Queryexpected
- Expected type, including nullability
-
checkResultType
public final void checkResultType(java.lang.String sql, java.lang.String expected)
Checks that a query returns a row of the expected type. For example,checkResultType("select empno, name from emp","{EMPNO INTEGER NOT NULL, NAME VARCHAR(10) NOT NULL}");
- Parameters:
sql
- Queryexpected
- Expected row type
-
checkIntervalConv
public final void checkIntervalConv(java.lang.String sql, java.lang.String expected)
Checks that the first column returned by a query has the expected type. For example,checkQueryType("SELECT empno FROM Emp", "INTEGER NOT NULL");
- Parameters:
sql
- Queryexpected
- Expected type, including nullability
-
assertExceptionIsThrown
protected final void assertExceptionIsThrown(java.lang.String sql, java.lang.String expectedMsgPattern)
-
checkCharset
public void checkCharset(java.lang.String sql, java.nio.charset.Charset expectedCharset)
-
checkCollation
public void checkCollation(java.lang.String sql, java.lang.String expectedCollationName, org.apache.calcite.sql.SqlCollation.Coercibility expectedCoercibility)
-
checkEx
public static void checkEx(java.lang.Throwable ex, java.lang.String expectedMsgPattern, org.apache.calcite.sql.parser.SqlParserUtil.StringAndPos sap)
Checks whether an exception matches the expected pattern. Ifsap
contains an error location, checks this too.- Parameters:
ex
- Exception thrownexpectedMsgPattern
- Expected patternsap
- Query and (optional) position in query
-
-