Package org.apache.calcite.test
Class SqlValidatorFixture
java.lang.Object
org.apache.calcite.test.SqlValidatorFixture
A fixture for testing the SQL validator.
It provides a fluent API so that you can write tests by chaining method calls.
It is immutable. If you have two test cases that require a similar set up (for example, the same SQL expression and parser configuration), it is safe to use the same fixture object as a starting point for both tests.
-
Field Summary
Modifier and TypeFieldDescriptionfinal boolean
final SqlTestFactory
final StringAndPos
final SqlTester
final boolean
-
Constructor Summary
ModifierConstructorDescriptionprotected
SqlValidatorFixture
(SqlTester tester, SqlTestFactory factory, StringAndPos sap, boolean expression, boolean whole) Creates a SqlValidatorFixture. -
Method Summary
Modifier and TypeMethodDescriptionassertBindType
(org.hamcrest.Matcher<String> matcher) void
assertCharset
(org.hamcrest.Matcher<Charset> charsetMatcher) void
assertCollation
(org.hamcrest.Matcher<String> collationMatcher, org.hamcrest.Matcher<SqlCollation.Coercibility> coercibilityMatcher) assertFieldOrigin
(org.hamcrest.Matcher<String> matcher) Tests that the list of the origins of each result field of the current query match expected.void
assertInterval
(org.hamcrest.Matcher<Long> matcher) Checks if the interval value conversion to milliseconds is valid.assertMeasure
(int column, org.hamcrest.Matcher<Boolean> matcher) Checks that columncolumn
is or is not a measure.assertMonotonicity
(org.hamcrest.Matcher<SqlMonotonicity> matcher) Tests that the first column of the query has a given monotonicity.columnType
(String expectedType) Checks that a query returns a single column, and that the column has the expected type.Checks that a SQL expression gives a particular error.Checks that a SQL expression fails, giving anexpected
error, ifb
is true, otherwise succeeds.isAggregate
(org.hamcrest.Matcher<Boolean> matcher) ok()
rewritesTo
(String expected) void
setFor
(SqlOperator operator) toSql
(boolean withCaret) Checks that a query returns a row of the expected type.withCaseSensitive
(boolean caseSensitive) withCatalogReader
(SqlTestFactory.CatalogReaderFactory catalogReaderFactory) withConformance
(SqlConformance conformance) withFactory
(UnaryOperator<SqlTestFactory> transform) withLenientOperatorLookup
(boolean lenient) Returns a tester that does not fail validation if it encounters an unknown function.withOperatorTable
(SqlOperatorTable operatorTable) withParserConfig
(UnaryOperator<SqlParser.Config> transform) withQuotedCasing
(org.apache.calcite.avatica.util.Casing casing) withQuoting
(org.apache.calcite.avatica.util.Quoting quoting) withTester
(UnaryOperator<SqlTester> transform) withTypeCoercion
(boolean typeCoercion) withUnquotedCasing
(org.apache.calcite.avatica.util.Casing casing) withValidatorCallRewrite
(boolean rewrite) withValidatorColumnReferenceExpansion
(boolean expansion) withValidatorConfig
(UnaryOperator<SqlValidator.Config> transform) withValidatorIdentifierExpansion
(boolean expansion) withWhole
(boolean whole)
-
Field Details
-
tester
-
factory
-
sap
-
expression
public final boolean expression -
whole
public final boolean whole
-
-
Constructor Details
-
SqlValidatorFixture
protected SqlValidatorFixture(SqlTester tester, SqlTestFactory factory, StringAndPos sap, boolean expression, boolean whole) Creates a SqlValidatorFixture.- Parameters:
tester
- Testersap
- SQL query or expressionexpression
- True ifsql
is an expression, false if it is a querywhole
- Whether the failure location is the whole query or expression
-
-
Method Details
-
withTester
-
withFactory
-
withParserConfig
-
parserConfig
-
withSql
-
withExpr
-
toSql
-
withExtendedCatalog
-
withCatalogReader
public SqlValidatorFixture withCatalogReader(SqlTestFactory.CatalogReaderFactory catalogReaderFactory) -
withQuoting
-
withLex
-
withConformance
-
conformance
-
withTypeCoercion
-
withLenientOperatorLookup
Returns a tester that does not fail validation if it encounters an unknown function. -
withWhole
-
ok
-
fails
Checks that a SQL expression gives a particular error. -
failsIf
Checks that a SQL expression fails, giving anexpected
error, ifb
is true, otherwise succeeds. -
type
Checks that a query returns a row of the expected type. For example,sql("select empno, name from emp")
.type("{EMPNO INTEGER NOT NULL, NAME VARCHAR(10) NOT NULL}");- Parameters:
expectedType
- Expected row type
-
columnType
Checks that a query returns a single column, and that the column has the expected type. For example,sql("SELECT empno FROM Emp").columnType("INTEGER NOT NULL");
- Parameters:
expectedType
- Expected type, including nullability
-
assertMeasure
Checks that columncolumn
is or is not a measure. -
assertMonotonicity
Tests that the first column of the query has a given monotonicity.- Parameters:
matcher
- Expected monotonicity
-
assertBindType
-
assertCharset
-
assertCollation
public void assertCollation(org.hamcrest.Matcher<String> collationMatcher, org.hamcrest.Matcher<SqlCollation.Coercibility> coercibilityMatcher) -
assertInterval
Checks if the interval value conversion to milliseconds is valid. For example,sql("VALUES (INTERVAL '1' Minute)").intervalConv("60000");
-
withCaseSensitive
-
withOperatorTable
-
withQuotedCasing
-
withUnquotedCasing
-
withValidatorConfig
-
withValidatorIdentifierExpansion
-
withValidatorCallRewrite
-
withValidatorColumnReferenceExpansion
-
rewritesTo
-
isAggregate
-
assertFieldOrigin
Tests that the list of the origins of each result field of the current query match expected.The field origin list looks like this:
"{(CATALOG.SALES.EMP.EMPNO, null)}"
. -
setFor
-