Interface SqlOperatorFixture
- All Superinterfaces:
- AutoCloseable
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.
The idea is that when you define an operator (or another piece of SQL functionality), you can define the logical behavior of that operator once, as part of that operator. Later you can define one or more physical implementations of that operator, and test them all using the same set of tests.
Depending on the implementation of SqlTester used
 (see withTester(UnaryOperator)), the fixture may or may not
 evaluate expressions and check their results.
- 
Nested Class SummaryNested ClassesModifier and TypeInterfaceDescriptionstatic enumTypes for cast.static enumName of a virtual machine that can potentially implement an operator.
- 
Field SummaryFields
- 
Method SummaryModifier and TypeMethodDescriptionbooleanReturns whether to run tests that are considered 'broken'.default voiddefault voidcheck(String query, SqlTester.TypeChecker typeChecker, Object result) Tests that a SQL query returns a single column with the given type.default voidcheck(String query, SqlTester.TypeChecker typeChecker, SqlTester.ParameterChecker parameterChecker, SqlTester.ResultChecker resultChecker) Tests that a SQL query returns a result of expected type and value.voidcheckAgg(String expr, String[] inputValues, String type, SqlTester.ResultChecker checker) Checks that an aggregate expression returns the expected result.voidcheckAgg(String expr, String[] inputValues, SqlTester.ResultChecker checker) Checks that an aggregate expression returns the expected result.voidcheckAggFails(String expr, String[] inputValues, String expectedError, boolean runtime) Tests that an aggregate expression fails at run time.default SqlOperatorFixturecheckAggType(String expr, String type) Very similar tocheckType(java.lang.String, java.lang.String), but generates inside a SELECT with a non-empty GROUP BY.voidcheckAggWithMultipleArgs(String expr, String[][] inputValues, SqlTester.ResultChecker resultChecker) Checks that an aggregate expression with multiple args returns the expected result.voidcheckBoolean(String expression, @Nullable Boolean result) Tests that a scalar SQL expression returns the expected boolean result.default voidcheckCastFails(String value, String targetType, String expectedError, boolean runtime, SqlOperatorFixture.CastType castType) default voidcheckCastToApproxOkay(String value, String targetType, Object expected, SqlOperatorFixture.CastType castType) default voidcheckCastToScalarOkay(String value, String targetType, String expected, SqlOperatorFixture.CastType castType) default voidcheckCastToScalarOkay(String value, String targetType, SqlOperatorFixture.CastType castType) default voidcheckCastToString(String value, @Nullable String type, @Nullable String expected, SqlOperatorFixture.CastType castType) default voidcheckCastToStringOkay(String value, String targetType, String expected, SqlOperatorFixture.CastType castType) voidcheckColumnType(String sql, String type) Checks that a query returns one column of an expected type.default voidcheckFails(String expression, String expectedError, boolean runtime) AscheckFails(StringAndPos, String, boolean), but with a string that contains carets.voidcheckFails(StringAndPos expression, String expectedError, boolean runtime) Tests that a scalar SQL expression fails at run time.voidTests that a SQL expression returns the SQL NULL value.voidcheckQuery(String sql) Tests that a SQL query succeeds at prepare time.voidcheckQueryFails(StringAndPos sap, String expectedError) Tests that a SQL query fails at prepare time.default voidcheckScalar(String expression, Object result, String resultType) Tests that a scalar SQL expression returns the expected result and the expected type.voidcheckScalar(String expression, SqlTester.TypeChecker typeChecker, SqlTester.ResultChecker resultChecker) voidcheckScalarApprox(String expression, String expectedType, Object result) Tests that a scalar SQL expression returns expected approximate numeric result.default voidcheckScalarExact(String expression, int result) Tests that a scalar SQL expression returns the expected exact numeric result as an integer.default voidcheckScalarExact(String expression, String expectedType, String result) Tests that a scalar SQL expression returns the expected exact numeric result.voidcheckScalarExact(String expression, String expectedType, SqlTester.ResultChecker resultChecker) voidcheckString(String expression, String result, String resultType) Tests that a scalar SQL expression returns the expected string result.voidTests that a SQL expression has a given type.voidcheckWinAgg(String expr, String[] inputValues, String windowSpec, String type, SqlTester.ResultChecker resultChecker) Checks that a windowed aggregate expression returns the expected result.default SqlConformanceReturns the conformance.default SqlOperatorFixtureenableTypeCoercion(boolean enabled) Returns a fixture that tests with implicit type coercion on/off.default voidforEachConformance(Iterable<? extends SqlConformanceEnum> conformances, Consumer<SqlOperatorFixture> consumer) Applies this fixture to some code for each of the given conformances.default voidforEachLibrary(Iterable<? extends SqlLibrary> libraries, Consumer<SqlOperatorFixture> consumer) Applies this fixture to some code for each of the given libraries.default SqlOperatorFixtureforOracle(SqlConformance conformance) default StringgetCastString(String value, String targetType, boolean errorLoc, SqlOperatorFixture.CastType castType) Returns the test factory.default StringgetTargetType(String targetType, SqlOperatorFixture.CastType castType) Returns the tester.setFor(SqlOperator operator, SqlOperatorFixture.VmName... unimplementedVmNames) Declares that this test is for a given operator.withBrokenTestsEnabled(boolean enableBrokenTests) SetsbrokenTestsEnabled().default SqlOperatorFixturewithCaseSensitive(boolean sensitive) Returns a fixture that matches identifiers by case-sensitive or case-insensitive.default SqlOperatorFixturewithConformance(SqlConformance conformance) Returns a fixture that tests conformance to a particular SQL language version.default SqlOperatorFixturewithConnectionFactory(UnaryOperator<ConnectionFactory> transform) Returns a fixture that gets connections from a given factory.withFactory(UnaryOperator<SqlTestFactory> transform) Creates a copy of this fixture with a new test factory.default SqlOperatorFixturewithLenientOperatorLookup(boolean lenient) Returns a fixture that does not fail validation if it encounters an unknown function.default SqlOperatorFixtureReturns a fixture that follows a given lexical policy.default SqlOperatorFixturewithLibraries(SqlLibrary... libraries) default SqlOperatorFixturewithLibrary(SqlLibrary library) default SqlOperatorFixturewithOperatorTable(SqlOperatorTable operatorTable) Returns a fixture that uses a given operator table.default SqlOperatorFixturewithParserConfig(UnaryOperator<SqlParser.Config> transform) Creates a copy of this fixture with a new parser configuration.default SqlOperatorFixturewithQuotedCasing(org.apache.calcite.avatica.util.Casing casing) Returns a fixture that applies a given casing policy to quoted identifiers.default SqlOperatorFixturewithQuoting(org.apache.calcite.avatica.util.Quoting quoting) Returns a fixture that tests a given SQL quoting style.withTester(UnaryOperator<SqlTester> transform) Creates a copy of this fixture with a new tester.default SqlOperatorFixturewithUnquotedCasing(org.apache.calcite.avatica.util.Casing casing) Returns a fixture that applies a given casing policy to unquoted identifiers.default SqlOperatorFixturewithValidatorConfig(UnaryOperator<SqlValidator.Config> transform) Returns a fixture with a given validator configuration.Methods inherited from interface java.lang.AutoCloseableclose
- 
Field Details- 
INVALID_CHAR_MESSAGE- See Also:
 
- 
OUT_OF_RANGE_MESSAGE- See Also:
 
- 
INTEGER_OVERFLOW- See Also:
 
- 
LONG_OVERFLOW- See Also:
 
- 
DECIMAL_OVERFLOW- See Also:
 
- 
WRONG_FORMAT_MESSAGE- See Also:
 
- 
DIVISION_BY_ZERO_MESSAGE- See Also:
 
- 
STRING_TRUNC_MESSAGE- See Also:
 
- 
BAD_DATETIME_MESSAGE- See Also:
 
- 
LITERAL_OUT_OF_RANGE_MESSAGE- See Also:
 
- 
INVALID_ARGUMENTS_NUMBER- See Also:
 
- 
INVALID_ARGUMENTS_TYPE_VALIDATION_ERROR- See Also:
 
 
- 
- 
Method Details- 
getFactorySqlTestFactory getFactory()Returns the test factory.
- 
withFactoryCreates a copy of this fixture with a new test factory.
- 
getTesterSqlTester getTester()Returns the tester.
- 
withTesterCreates a copy of this fixture with a new tester.
- 
withParserConfigCreates a copy of this fixture with a new parser configuration.
- 
withQuotingReturns a fixture that tests a given SQL quoting style.
- 
withQuotedCasingReturns a fixture that applies a given casing policy to quoted identifiers.
- 
withUnquotedCasingReturns a fixture that applies a given casing policy to unquoted identifiers.
- 
withCaseSensitiveReturns a fixture that matches identifiers by case-sensitive or case-insensitive.
- 
withLexReturns a fixture that follows a given lexical policy.
- 
withConformanceReturns a fixture that tests conformance to a particular SQL language version.
- 
conformanceReturns the conformance.
- 
withValidatorConfigReturns a fixture with a given validator configuration.
- 
enableTypeCoercionReturns a fixture that tests with implicit type coercion on/off.
- 
withLenientOperatorLookupReturns a fixture that does not fail validation if it encounters an unknown function.
- 
withConnectionFactoryReturns a fixture that gets connections from a given factory.
- 
withOperatorTableReturns a fixture that uses a given operator table.
- 
brokenTestsEnabledboolean brokenTestsEnabled()Returns whether to run tests that are considered 'broken'. Returns false by default, but it is useful to temporarily enable the 'broken' tests to see whether they are still broken.
- 
withBrokenTestsEnabledSetsbrokenTestsEnabled().
- 
checkScalarvoid checkScalar(String expression, SqlTester.TypeChecker typeChecker, SqlTester.ResultChecker resultChecker) 
- 
checkScalarTests that a scalar SQL expression returns the expected result and the expected type. For example,checkScalar("1.1 + 2.9", "4.0", "DECIMAL(2, 1) NOT NULL");- Parameters:
- expression- Scalar expression
- result- Expected result
- resultType- Expected result type
 
- 
checkScalarExactTests that a scalar SQL expression returns the expected exact numeric result as an integer. For example,checkScalarExact("1 + 2", 3);- Parameters:
- expression- Scalar expression
- result- Expected result
 
- 
checkScalarExactTests that a scalar SQL expression returns the expected exact numeric result. For example,checkScalarExact("1 + 2", "3");- Parameters:
- expression- Scalar expression
- expectedType- Type we expect the result to have, including nullability, precision and scale, for example- DECIMAL(2, 1) NOT NULL.
- result- Expected result
 
- 
checkScalarExactvoid checkScalarExact(String expression, String expectedType, SqlTester.ResultChecker resultChecker) 
- 
checkScalarApproxTests that a scalar SQL expression returns expected approximate numeric result. For example,checkScalarApprox("1.0 + 2.1", "3.1");- Parameters:
- expression- Scalar expression
- expectedType- Type we expect the result to have, including nullability, precision and scale, for example- DECIMAL(2, 1) NOT NULL.
- result- Expected result, or a matcher
- See Also:
 
- 
checkBooleanTests that a scalar SQL expression returns the expected boolean result. For example,checkScalarExact("TRUE AND FALSE", Boolean.TRUE);The expected result can be null: checkScalarExact("NOT UNKNOWN", null);- Parameters:
- expression- Scalar expression
- result- Expected result (null signifies NULL).
 
- 
checkStringTests that a scalar SQL expression returns the expected string result. For example,checkScalarExact("'ab' || 'c'", "abc");- Parameters:
- expression- Scalar expression
- result- Expected result
- resultType- Expected result type
 
- 
checkNullTests that a SQL expression returns the SQL NULL value. For example,checkNull("CHAR_LENGTH(CAST(NULL AS VARCHAR(3))");- Parameters:
- expression- Scalar expression
 
- 
checkTypeTests that a SQL expression has a given type. For example,checkType("SUBSTR('hello' FROM 1 FOR 3)", "VARCHAR(3) NOT NULL");This method checks length/precision, scale, and whether the type allows NULL values, so is more precise than the type-checking done by methods such as checkScalarExact(java.lang.String, int).- Parameters:
- expression- Scalar expression
- type- Type string
 
- 
checkAggTypeVery similar tocheckType(java.lang.String, java.lang.String), but generates inside a SELECT with a non-empty GROUP BY. Aggregate functions may be nullable if executed in a SELECT with an empty GROUP BY.Viz: SELECT sum(1) FROM emphas type "INTEGER",SELECT sum(1) FROM emp GROUP BY deptnohas type "INTEGER NOT NULL",
- 
checkColumnTypeChecks that a query returns one column of an expected type. For example,checkType("VALUES (1 + 2)", "INTEGER NOT NULL").- Parameters:
- sql- Query expression
- type- Type string
 
- 
checkTests that a SQL query returns a single column with the given type. For example,check("VALUES (1 + 2)", "3", SqlTypeName.Integer);If resultis null, the expression must yield the SQL NULL value. Ifresultis aPattern, the result must match that pattern.- Parameters:
- query- SQL query
- typeChecker- Checks whether the result is the expected type; must not be null
- result- Expected result, or matcher
 
- 
check
- 
checkdefault void check(String query, SqlTester.TypeChecker typeChecker, SqlTester.ParameterChecker parameterChecker, SqlTester.ResultChecker resultChecker) Tests that a SQL query returns a result of expected type and value. Checking of type and value are abstracted usingSqlTester.TypeCheckerandSqlTester.ResultCheckerfunctors.- Parameters:
- query- SQL query
- typeChecker- Checks whether the result is the expected type
- parameterChecker- Checks whether the parameters are of expected types
- resultChecker- Checks whether the result has the expected value
 
- 
setForDeclares that this test is for a given operator. So we can check that all operators are tested.- Parameters:
- operator- Operator
- unimplementedVmNames- Names of virtual machines for which this
 
- 
checkAggChecks that an aggregate expression returns the expected result.For example, checkAgg("AVG(DISTINCT x)", new String[] {"2", "3", null, "3" }, new Double(2.5), 0);- Parameters:
- expr- Aggregate expression, e.g.- SUM(DISTINCT x)
- inputValues- Array of input values, e.g.- ["1", null, "2"].
- checker- Result checker
 
- 
checkAggChecks that an aggregate expression returns the expected result.For example, checkAgg("AVG(DISTINCT x)", new String[] {"2", "3", null, "3" }, "INTEGER", isSingle([2, 3]));- Parameters:
- expr- Aggregate expression, e.g.- SUM(DISTINCT x)
- inputValues- Array of input values, e.g.- ["1", null, "2"].
- type- Expected result type
- checker- Result checker
 
- 
checkAggWithMultipleArgsvoid checkAggWithMultipleArgs(String expr, String[][] inputValues, SqlTester.ResultChecker resultChecker) Checks that an aggregate expression with multiple args returns the expected result.- Parameters:
- expr- Aggregate expression, e.g.- AGG_FUNC(x, x2, x3)
- inputValues- Nested array of input values, e.g.- [ ["1", null, "2"] ["3", "4", null] ]
- resultChecker- Checks whether the result has the expected value
 
- 
checkWinAggvoid checkWinAgg(String expr, String[] inputValues, String windowSpec, String type, SqlTester.ResultChecker resultChecker) Checks that a windowed aggregate expression returns the expected result.For example, checkWinAgg("FIRST_VALUE(x)", new String[] {"2", "3", null, "3" }, "INTEGER NOT NULL", 2, 0d);- Parameters:
- expr- Aggregate expression, e.g.- SUM(DISTINCT x)
- inputValues- Array of input values, e.g.- ["1", null, "2"]
- type- Expected result type
- resultChecker- Checks whether the result has the expected value
 
- 
checkAggFailsTests that an aggregate expression fails at run time.- Parameters:
- expr- An aggregate expression
- inputValues- Array of input values
- expectedError- Pattern for expected error
- runtime- If true, must fail at runtime; if false, must fail at validate time
 
- 
checkFailsTests that a scalar SQL expression fails at run time.- Parameters:
- expression- SQL scalar expression
- expectedError- Pattern for expected error. If !runtime, must include an error location.
- runtime- If true, must fail at runtime; if false, must fail at validate time
 
- 
checkFailsAscheckFails(StringAndPos, String, boolean), but with a string that contains carets.
- 
checkQueryFailsTests that a SQL query fails at prepare time.- Parameters:
- sap- SQL query and error position
- expectedError- Pattern for expected error. Must include an error location.
 
- 
checkQueryTests that a SQL query succeeds at prepare time.- Parameters:
- sql- SQL query
 
- 
withLibrary
- 
withLibraries
- 
forEachLibrarydefault void forEachLibrary(Iterable<? extends SqlLibrary> libraries, Consumer<SqlOperatorFixture> consumer) Applies this fixture to some code for each of the given libraries.
- 
forEachConformancedefault void forEachConformance(Iterable<? extends SqlConformanceEnum> conformances, Consumer<SqlOperatorFixture> consumer) Applies this fixture to some code for each of the given conformances.
- 
forOracle
- 
getCastStringdefault String getCastString(String value, String targetType, boolean errorLoc, SqlOperatorFixture.CastType castType) 
- 
checkCastToApproxOkaydefault void checkCastToApproxOkay(String value, String targetType, Object expected, SqlOperatorFixture.CastType castType) 
- 
checkCastToStringOkaydefault void checkCastToStringOkay(String value, String targetType, String expected, SqlOperatorFixture.CastType castType) 
- 
checkCastToScalarOkaydefault void checkCastToScalarOkay(String value, String targetType, String expected, SqlOperatorFixture.CastType castType) 
- 
getTargetType
- 
checkCastToScalarOkaydefault void checkCastToScalarOkay(String value, String targetType, SqlOperatorFixture.CastType castType) 
- 
checkCastFailsdefault void checkCastFails(String value, String targetType, String expectedError, boolean runtime, SqlOperatorFixture.CastType castType) 
- 
checkCastToStringdefault void checkCastToString(String value, @Nullable String type, @Nullable String expected, SqlOperatorFixture.CastType castType) 
 
-