public interface SqlOperatorFixture extends 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.
| 限定符和类型 | 接口和说明 |
|---|---|
static class |
SqlOperatorFixture.CastType
Types for cast.
|
static class |
SqlOperatorFixture.VmName
Name of a virtual machine that can potentially implement an operator.
|
| 限定符和类型 | 字段和说明 |
|---|---|
static String |
BAD_DATETIME_MESSAGE |
static String |
DIVISION_BY_ZERO_MESSAGE |
static String |
INVALID_ARGUMENTS_NUMBER |
static String |
INVALID_CHAR_MESSAGE |
static String |
INVALID_EXTRACT_UNIT_CONVERTLET_ERROR |
static String |
INVALID_EXTRACT_UNIT_VALIDATION_ERROR |
static String |
LITERAL_OUT_OF_RANGE_MESSAGE |
static String |
OUT_OF_RANGE_MESSAGE |
static String |
STRING_TRUNC_MESSAGE |
| 限定符和类型 | 方法和说明 |
|---|---|
boolean |
brokenTestsEnabled()
Returns whether to run tests that are considered 'broken'.
|
default void |
check(String query,
SqlTester.TypeChecker typeChecker,
Object result)
Tests that a SQL query returns a single column with the given type.
|
default 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.
|
default void |
check(String query,
String expectedType,
Object result) |
void |
checkAgg(String expr,
String[] inputValues,
SqlTester.ResultChecker checker)
Checks that an aggregate expression returns the expected result.
|
void |
checkAggFails(String expr,
String[] inputValues,
String expectedError,
boolean runtime)
Tests that an aggregate expression fails at run time.
|
default SqlOperatorFixture |
checkAggType(String expr,
String type)
Very similar to
checkType(java.lang.String, java.lang.String), but generates inside a SELECT
with a non-empty GROUP BY. |
void |
checkAggWithMultipleArgs(String expr,
String[][] inputValues,
SqlTester.ResultChecker resultChecker)
Checks that an aggregate expression with multiple args returns the expected
result.
|
void |
checkBoolean(String expression,
@Nullable Boolean result)
Tests that a scalar SQL expression returns the expected boolean result.
|
default void |
checkCastFails(String value,
String targetType,
String expectedError,
boolean runtime,
SqlOperatorFixture.CastType castType) |
default void |
checkCastToApproxOkay(String value,
String targetType,
Object expected,
SqlOperatorFixture.CastType castType) |
default void |
checkCastToScalarOkay(String value,
String targetType,
SqlOperatorFixture.CastType castType) |
default void |
checkCastToScalarOkay(String value,
String targetType,
String expected,
SqlOperatorFixture.CastType castType) |
default void |
checkCastToString(String value,
@Nullable String type,
@Nullable String expected,
SqlOperatorFixture.CastType castType) |
default void |
checkCastToStringOkay(String value,
String targetType,
String expected,
SqlOperatorFixture.CastType castType) |
void |
checkColumnType(String sql,
String type)
Checks that a query returns one column of an expected type.
|
void |
checkFails(org.apache.calcite.sql.parser.StringAndPos expression,
String expectedError,
boolean runtime)
Tests that a scalar SQL expression fails at run time.
|
default void |
checkFails(String expression,
String expectedError,
boolean runtime)
As
checkFails(StringAndPos, String, boolean), but with a string
that contains carets. |
void |
checkNull(String expression)
Tests that a SQL expression returns the SQL NULL value.
|
void |
checkQuery(String sql)
Tests that a SQL query succeeds at prepare time.
|
void |
checkQueryFails(org.apache.calcite.sql.parser.StringAndPos sap,
String expectedError)
Tests that a SQL query fails at prepare time.
|
default void |
checkScalar(String expression,
Object result,
String resultType)
Tests that a scalar SQL expression returns the expected result and the
expected type.
|
void |
checkScalar(String expression,
SqlTester.TypeChecker typeChecker,
SqlTester.ResultChecker resultChecker) |
void |
checkScalarApprox(String expression,
String expectedType,
Object result)
Tests that a scalar SQL expression returns expected approximate numeric
result.
|
default void |
checkScalarExact(String expression,
int result)
Tests that a scalar SQL expression returns the expected exact numeric
result as an integer.
|
void |
checkScalarExact(String expression,
String expectedType,
SqlTester.ResultChecker resultChecker) |
default void |
checkScalarExact(String expression,
String expectedType,
String result)
Tests that a scalar SQL expression returns the expected exact numeric
result.
|
void |
checkString(String expression,
String result,
String resultType)
Tests that a scalar SQL expression returns the expected string result.
|
void |
checkType(String expression,
String type)
Tests that a SQL expression has a given type.
|
void |
checkWinAgg(String expr,
String[] inputValues,
String windowSpec,
String type,
SqlTester.ResultChecker resultChecker)
Checks that a windowed aggregate expression returns the expected result.
|
default org.apache.calcite.sql.validate.SqlConformance |
conformance()
Returns the conformance.
|
default SqlOperatorFixture |
enableTypeCoercion(boolean enabled)
Returns a fixture that tests with implicit type coercion on/off.
|
default void |
forEachConformance(Iterable<? extends org.apache.calcite.sql.validate.SqlConformanceEnum> conformances,
Consumer<SqlOperatorFixture> consumer)
Applies this fixture to some code for each of the given conformances.
|
default void |
forEachLibrary(Iterable<? extends org.apache.calcite.sql.fun.SqlLibrary> libraries,
Consumer<SqlOperatorFixture> consumer)
Applies this fixture to some code for each of the given libraries.
|
default SqlOperatorFixture |
forOracle(org.apache.calcite.sql.validate.SqlConformance conformance) |
default String |
getCastString(String value,
String targetType,
boolean errorLoc,
SqlOperatorFixture.CastType castType) |
SqlTestFactory |
getFactory()
Returns the test factory.
|
default String |
getTargetType(String targetType,
SqlOperatorFixture.CastType castType) |
SqlTester |
getTester()
Returns the tester.
|
SqlOperatorFixture |
setFor(org.apache.calcite.sql.SqlOperator operator,
SqlOperatorFixture.VmName... unimplementedVmNames)
Declares that this test is for a given operator.
|
SqlOperatorFixture |
withBrokenTestsEnabled(boolean enableBrokenTests)
Sets
brokenTestsEnabled(). |
default SqlOperatorFixture |
withCaseSensitive(boolean sensitive)
Returns a fixture that matches identifiers by case-sensitive or
case-insensitive.
|
default SqlOperatorFixture |
withConformance(org.apache.calcite.sql.validate.SqlConformance conformance)
Returns a fixture that tests conformance to a particular SQL language
version.
|
default SqlOperatorFixture |
withConnectionFactory(UnaryOperator<ConnectionFactory> transform)
Returns a fixture that gets connections from a given factory.
|
SqlOperatorFixture |
withFactory(UnaryOperator<SqlTestFactory> transform)
Creates a copy of this fixture with a new test factory.
|
default SqlOperatorFixture |
withLenientOperatorLookup(boolean lenient)
Returns a fixture that does not fail validation if it encounters an
unknown function.
|
default SqlOperatorFixture |
withLex(org.apache.calcite.config.Lex lex)
Returns a fixture that follows a given lexical policy.
|
default SqlOperatorFixture |
withLibrary(org.apache.calcite.sql.fun.SqlLibrary library) |
default SqlOperatorFixture |
withOperatorTable(org.apache.calcite.sql.SqlOperatorTable operatorTable)
Returns a fixture that uses a given operator table.
|
default SqlOperatorFixture |
withParserConfig(UnaryOperator<org.apache.calcite.sql.parser.SqlParser.Config> transform)
Creates a copy of this fixture with a new parser configuration.
|
default SqlOperatorFixture |
withQuotedCasing(org.apache.calcite.avatica.util.Casing casing)
Returns a fixture that applies a given casing policy to quoted
identifiers.
|
default SqlOperatorFixture |
withQuoting(org.apache.calcite.avatica.util.Quoting quoting)
Returns a fixture that tests a given SQL quoting style.
|
SqlOperatorFixture |
withTester(UnaryOperator<SqlTester> transform)
Creates a copy of this fixture with a new tester.
|
default SqlOperatorFixture |
withUnquotedCasing(org.apache.calcite.avatica.util.Casing casing)
Returns a fixture that applies a given casing policy to unquoted
identifiers.
|
default SqlOperatorFixture |
withValidatorConfig(UnaryOperator<org.apache.calcite.sql.validate.SqlValidator.Config> transform)
Returns a fixture with a given validator configuration.
|
closestatic final String INVALID_EXTRACT_UNIT_CONVERTLET_ERROR
static final String INVALID_EXTRACT_UNIT_VALIDATION_ERROR
SqlTestFactory getFactory()
SqlOperatorFixture withFactory(UnaryOperator<SqlTestFactory> transform)
SqlTester getTester()
SqlOperatorFixture withTester(UnaryOperator<SqlTester> transform)
default SqlOperatorFixture withParserConfig(UnaryOperator<org.apache.calcite.sql.parser.SqlParser.Config> transform)
default SqlOperatorFixture withQuoting(org.apache.calcite.avatica.util.Quoting quoting)
default SqlOperatorFixture withQuotedCasing(org.apache.calcite.avatica.util.Casing casing)
default SqlOperatorFixture withUnquotedCasing(org.apache.calcite.avatica.util.Casing casing)
default SqlOperatorFixture withCaseSensitive(boolean sensitive)
default SqlOperatorFixture withLex(org.apache.calcite.config.Lex lex)
default SqlOperatorFixture withConformance(org.apache.calcite.sql.validate.SqlConformance conformance)
default org.apache.calcite.sql.validate.SqlConformance conformance()
default SqlOperatorFixture withValidatorConfig(UnaryOperator<org.apache.calcite.sql.validate.SqlValidator.Config> transform)
default SqlOperatorFixture enableTypeCoercion(boolean enabled)
default SqlOperatorFixture withLenientOperatorLookup(boolean lenient)
default SqlOperatorFixture withConnectionFactory(UnaryOperator<ConnectionFactory> transform)
default SqlOperatorFixture withOperatorTable(org.apache.calcite.sql.SqlOperatorTable operatorTable)
boolean brokenTestsEnabled()
SqlOperatorFixture withBrokenTestsEnabled(boolean enableBrokenTests)
brokenTestsEnabled().void checkScalar(String expression, SqlTester.TypeChecker typeChecker, SqlTester.ResultChecker resultChecker)
default void checkScalar(String expression, Object result, String resultType)
checkScalar("1.1 + 2.9", "4.0", "DECIMAL(2, 1) NOT NULL");
expression - Scalar expressionresult - Expected resultresultType - Expected result typedefault void checkScalarExact(String expression, int result)
checkScalarExact("1 + 2", 3);
expression - Scalar expressionresult - Expected resultdefault void checkScalarExact(String expression, String expectedType, String result)
checkScalarExact("1 + 2", "3");
expression - Scalar expressionexpectedType - Type we expect the result to have, including
nullability, precision and scale, for example
DECIMAL(2, 1) NOT NULL.result - Expected resultvoid checkScalarExact(String expression, String expectedType, SqlTester.ResultChecker resultChecker)
void checkScalarApprox(String expression, String expectedType, Object result)
checkScalarApprox("1.0 + 2.1", "3.1");
expression - Scalar expressionexpectedType - Type we expect the result to have, including
nullability, precision and scale, for example
DECIMAL(2, 1) NOT NULL.result - Expected result, or a matcherMatchers.within(Number, double)void checkBoolean(String expression, @Nullable Boolean result)
checkScalarExact("TRUE AND FALSE", Boolean.TRUE);
The expected result can be null:
checkScalarExact("NOT UNKNOWN", null);
expression - Scalar expressionresult - Expected result (null signifies NULL).void checkString(String expression, String result, String resultType)
checkScalarExact("'ab' || 'c'", "abc");
expression - Scalar expressionresult - Expected resultresultType - Expected result typevoid checkNull(String expression)
checkNull("CHAR_LENGTH(CAST(NULL AS VARCHAR(3))");
expression - Scalar expressionvoid checkType(String expression, String type)
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).
expression - Scalar expressiontype - Type stringdefault SqlOperatorFixture checkAggType(String expr, String type)
checkType(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 emp has type "INTEGER",
SELECT sum(1) FROM emp GROUP BY deptno has type "INTEGER NOT NULL",
void checkColumnType(String sql, String type)
checkType("VALUES (1 + 2)", "INTEGER NOT NULL").sql - Query expressiontype - Type stringdefault void check(String query, SqlTester.TypeChecker typeChecker, Object result)
check("VALUES (1 + 2)", "3", SqlTypeName.Integer);
If result is null, the expression must yield the SQL NULL
value. If result is a Pattern, the
result must match that pattern.
query - SQL querytypeChecker - Checks whether the result is the expected type; must
not be nullresult - Expected result, or matcherdefault void check(String query, SqlTester.TypeChecker typeChecker, SqlTester.ParameterChecker parameterChecker, SqlTester.ResultChecker resultChecker)
SqlTester.TypeChecker
and SqlTester.ResultChecker functors.query - SQL querytypeChecker - Checks whether the result is the expected typeparameterChecker - Checks whether the parameters are of expected
typesresultChecker - Checks whether the result has the expected valueSqlOperatorFixture setFor(org.apache.calcite.sql.SqlOperator operator, SqlOperatorFixture.VmName... unimplementedVmNames)
operator - OperatorunimplementedVmNames - Names of virtual machines for which thisvoid checkAgg(String expr, String[] inputValues, SqlTester.ResultChecker checker)
For example, checkAgg("AVG(DISTINCT x)", new String[] {"2", "3",
null, "3" }, new Double(2.5), 0);
expr - Aggregate expression, e.g. SUM(DISTINCT x)inputValues - Array of input values, e.g. ["1", null,
"2"].checker - Result checkervoid checkAggWithMultipleArgs(String expr, String[][] inputValues, SqlTester.ResultChecker resultChecker)
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 valuevoid checkWinAgg(String expr, String[] inputValues, String windowSpec, String type, SqlTester.ResultChecker resultChecker)
For example, checkWinAgg("FIRST_VALUE(x)", new String[] {"2",
"3", null, "3" }, "INTEGER NOT NULL", 2, 0d);
expr - Aggregate expression, e.g. SUM(DISTINCT x)inputValues - Array of input values, e.g. ["1", null, "2"]type - Expected result typeresultChecker - Checks whether the result has the expected valuevoid checkAggFails(String expr, String[] inputValues, String expectedError, boolean runtime)
expr - An aggregate expressioninputValues - Array of input valuesexpectedError - Pattern for expected errorruntime - If true, must fail at runtime; if false, must fail at
validate timevoid checkFails(org.apache.calcite.sql.parser.StringAndPos expression,
String expectedError,
boolean runtime)
expression - SQL scalar expressionexpectedError - Pattern for expected error. If !runtime, must
include an error location.runtime - If true, must fail at runtime; if false, must fail at
validate timedefault void checkFails(String expression, String expectedError, boolean runtime)
checkFails(StringAndPos, String, boolean), but with a string
that contains carets.void checkQueryFails(org.apache.calcite.sql.parser.StringAndPos sap,
String expectedError)
sap - SQL query and error positionexpectedError - Pattern for expected error. Must
include an error location.void checkQuery(String sql)
sql - SQL querydefault SqlOperatorFixture withLibrary(org.apache.calcite.sql.fun.SqlLibrary library)
default void forEachLibrary(Iterable<? extends org.apache.calcite.sql.fun.SqlLibrary> libraries, Consumer<SqlOperatorFixture> consumer)
default void forEachConformance(Iterable<? extends org.apache.calcite.sql.validate.SqlConformanceEnum> conformances, Consumer<SqlOperatorFixture> consumer)
default SqlOperatorFixture forOracle(org.apache.calcite.sql.validate.SqlConformance conformance)
default String getCastString(String value, String targetType, boolean errorLoc, SqlOperatorFixture.CastType castType)
default void checkCastToApproxOkay(String value, String targetType, Object expected, SqlOperatorFixture.CastType castType)
default void checkCastToStringOkay(String value, String targetType, String expected, SqlOperatorFixture.CastType castType)
default void checkCastToScalarOkay(String value, String targetType, String expected, SqlOperatorFixture.CastType castType)
default String getTargetType(String targetType, SqlOperatorFixture.CastType castType)
default void checkCastToScalarOkay(String value, String targetType, SqlOperatorFixture.CastType castType)
default void checkCastFails(String value, String targetType, String expectedError, boolean runtime, SqlOperatorFixture.CastType castType)
default void checkCastToString(String value, @Nullable String type, @Nullable String expected, SqlOperatorFixture.CastType castType)
Copyright © 2012-2023 Apache Software Foundation. All Rights Reserved.