Interface SqlTester

  • All Superinterfaces:
    java.lang.AutoCloseable, SqlValidatorTestCase.Tester
    All Known Implementing Classes:
    AbstractSqlTester, SqlOperatorBaseTest.TesterImpl, SqlRuntimeTester, SqlValidatorTester

    public interface SqlTester
    extends java.lang.AutoCloseable, SqlValidatorTestCase.Tester
    SqlTester defines a callback for testing SQL queries and expressions.

    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.

    Specific implementations of SqlTester might evaluate the queries in different ways, for example, using a C++ versus Java calculator. An implementation might even ignore certain calls altogether.

    • Method Summary

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      void check​(java.lang.String query, SqlTester.TypeChecker typeChecker, java.lang.Object result, double delta)
      Tests that a SQL query returns a single column with the given type.
      void check​(java.lang.String query, SqlTester.TypeChecker typeChecker, SqlTester.ParameterChecker parameterChecker, SqlTester.ResultChecker resultChecker)
      Tests that a SQL query returns a result of expected type and value.
      void checkAgg​(java.lang.String expr, java.lang.String[] inputValues, java.lang.Object result, double delta)
      Checks that an aggregate expression returns the expected result.
      void checkAggWithMultipleArgs​(java.lang.String expr, java.lang.String[][] inputValues, java.lang.Object result, double delta)
      Checks that an aggregate expression with multiple args returns the expected result.
      void checkBoolean​(java.lang.String expression, java.lang.Boolean result)
      Tests that a scalar SQL expression returns the expected boolean result.
      void checkColumnType​(java.lang.String sql, java.lang.String type)
      Checks that a query returns one column of an expected type.
      void checkFails​(java.lang.String expression, java.lang.String expectedError, boolean runtime)
      Tests that a scalar SQL expression fails at run time.
      void checkMonotonic​(java.lang.String query, org.apache.calcite.sql.validate.SqlMonotonicity expectedMonotonicity)
      Tests that the first column of a SQL query has a given monotonicity.
      void checkNull​(java.lang.String expression)
      Tests that a SQL expression returns the SQL NULL value.
      void checkQuery​(java.lang.String sql)
      Tests that a SQL query succeeds at prepare time.
      void checkQueryFails​(java.lang.String sql, java.lang.String expectedError)
      Tests that a SQL query fails at prepare time.
      void checkScalar​(java.lang.String expression, java.lang.Object result, java.lang.String resultType)
      Tests that a scalar SQL expression returns the expected result and the expected type.
      void checkScalarApprox​(java.lang.String expression, java.lang.String expectedType, double expectedResult, double delta)
      Tests that a scalar SQL expression returns expected appoximate numeric result.
      void checkScalarExact​(java.lang.String expression, java.lang.String result)
      Tests that a scalar SQL expression returns the expected exact numeric result as an integer.
      void checkScalarExact​(java.lang.String expression, java.lang.String expectedType, java.lang.String result)
      Tests that a scalar SQL expression returns the expected exact numeric result.
      void checkString​(java.lang.String expression, java.lang.String result, java.lang.String resultType)
      Tests that a scalar SQL expression returns the expected string result.
      void checkType​(java.lang.String expression, java.lang.String type)
      Tests that a SQL expression has a given type.
      void checkWinAgg​(java.lang.String expr, java.lang.String[] inputValues, java.lang.String windowSpec, java.lang.String type, java.lang.Object result, double delta)
      Checks that a windowed aggregate expression returns the expected result.
      SqlTester enableTypeCoercion​(boolean enabled)
      Returns a tester that tests with implicit type coercion on/off.
      SqlTestFactory getFactory()  
      void setFor​(org.apache.calcite.sql.SqlOperator operator, SqlTester.VmName... unimplementedVmNames)
      Declares that this test is for a given operator.
      SqlTester withCaseSensitive​(boolean sensitive)
      Returns a tester that matches identifiers by case-sensitive or case-insensitive.
      SqlTester withConformance​(org.apache.calcite.sql.validate.SqlConformance conformance)
      Returns a tester that tests conformance to a particular SQL language version.
      SqlTester withConnectionFactory​(CalciteAssert.ConnectionFactory connectionFactory)
      Returns a tester that gets connections from a given factory.
      SqlTester withLex​(org.apache.calcite.config.Lex lex)
      Returns a tester that follows a lex policy.
      SqlTester withOperatorTable​(org.apache.calcite.sql.SqlOperatorTable operatorTable)
      Returns a tester that uses a given operator table.
      SqlTester withQuotedCasing​(org.apache.calcite.avatica.util.Casing casing)
      Returns a tester that applies a given casing policy to quoted identifiers.
      SqlTester withQuoting​(org.apache.calcite.avatica.util.Quoting quoting)
      Returns a tester that tests a given SQL quoting style.
      SqlTester withUnquotedCasing​(org.apache.calcite.avatica.util.Casing casing)
      Returns a tester that applies a given casing policy to unquoted identifiers.
      • Methods inherited from interface java.lang.AutoCloseable

        close
    • Method Detail

      • withQuoting

        SqlTester withQuoting​(org.apache.calcite.avatica.util.Quoting quoting)
        Returns a tester that tests a given SQL quoting style.
      • withQuotedCasing

        SqlTester withQuotedCasing​(org.apache.calcite.avatica.util.Casing casing)
        Returns a tester that applies a given casing policy to quoted identifiers.
      • withUnquotedCasing

        SqlTester withUnquotedCasing​(org.apache.calcite.avatica.util.Casing casing)
        Returns a tester that applies a given casing policy to unquoted identifiers.
      • withCaseSensitive

        SqlTester withCaseSensitive​(boolean sensitive)
        Returns a tester that matches identifiers by case-sensitive or case-insensitive.
      • withLex

        SqlTester withLex​(org.apache.calcite.config.Lex lex)
        Returns a tester that follows a lex policy.
      • withConformance

        SqlTester withConformance​(org.apache.calcite.sql.validate.SqlConformance conformance)
        Returns a tester that tests conformance to a particular SQL language version.
      • enableTypeCoercion

        SqlTester enableTypeCoercion​(boolean enabled)
        Returns a tester that tests with implicit type coercion on/off.
      • withOperatorTable

        SqlTester withOperatorTable​(org.apache.calcite.sql.SqlOperatorTable operatorTable)
        Returns a tester that uses a given operator table.
      • checkScalar

        void checkScalar​(java.lang.String expression,
                         java.lang.Object result,
                         java.lang.String resultType)
        Tests 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
      • checkScalarExact

        void checkScalarExact​(java.lang.String expression,
                              java.lang.String result)
        Tests 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
      • checkScalarExact

        void checkScalarExact​(java.lang.String expression,
                              java.lang.String expectedType,
                              java.lang.String result)
        Tests 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
      • checkScalarApprox

        void checkScalarApprox​(java.lang.String expression,
                               java.lang.String expectedType,
                               double expectedResult,
                               double delta)
        Tests that a scalar SQL expression returns expected appoximate 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.
        expectedResult - Expected result
        delta - Allowed margin of error between expected and actual result
      • checkBoolean

        void checkBoolean​(java.lang.String expression,
                          java.lang.Boolean result)
        Tests 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).
      • checkString

        void checkString​(java.lang.String expression,
                         java.lang.String result,
                         java.lang.String resultType)
        Tests 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
      • checkNull

        void checkNull​(java.lang.String expression)
        Tests that a SQL expression returns the SQL NULL value. For example,
        checkNull("CHAR_LENGTH(CAST(NULL AS VARCHAR(3))");
        Parameters:
        expression - Scalar expression
      • checkType

        void checkType​(java.lang.String expression,
                       java.lang.String type)
        Tests 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, java.lang.String).

        Parameters:
        expression - Scalar expression
        type - Type string
      • checkColumnType

        void checkColumnType​(java.lang.String sql,
                             java.lang.String type)
        Checks that a query returns one column of an expected type. For example, checkType("VALUES (1 + 2)", "INTEGER NOT NULL").
        Specified by:
        checkColumnType in interface SqlValidatorTestCase.Tester
        Parameters:
        sql - Query expression
        type - Type string
      • check

        void check​(java.lang.String query,
                   SqlTester.TypeChecker typeChecker,
                   java.lang.Object result,
                   double delta)
        Tests that a SQL query returns a single column with the given type. For example,
        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.

        Parameters:
        query - SQL query
        typeChecker - Checks whether the result is the expected type; must not be null
        result - Expected result
        delta - The acceptable tolerance between the expected and actual
      • check

        void check​(java.lang.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 using SqlTester.TypeChecker and SqlTester.ResultChecker functors.
        Parameters:
        query - SQL query
        typeChecker - Checks whether the result is the expected type; must not be null
        parameterChecker - Checks whether the parameters are of expected types
        resultChecker - Checks whether the result has the expected value; must not be null
      • checkMonotonic

        void checkMonotonic​(java.lang.String query,
                            org.apache.calcite.sql.validate.SqlMonotonicity expectedMonotonicity)
        Tests that the first column of a SQL query has a given monotonicity.
        Parameters:
        expectedMonotonicity - Expected monotonicity
        query - SQL query
      • setFor

        void setFor​(org.apache.calcite.sql.SqlOperator operator,
                    SqlTester.VmName... unimplementedVmNames)
        Declares 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
      • checkAgg

        void checkAgg​(java.lang.String expr,
                      java.lang.String[] inputValues,
                      java.lang.Object result,
                      double delta)
        Checks 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"].
        result - Expected result
        delta - Allowable variance from expected result
      • checkAggWithMultipleArgs

        void checkAggWithMultipleArgs​(java.lang.String expr,
                                      java.lang.String[][] inputValues,
                                      java.lang.Object result,
                                      double delta)
        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] ].
        result - Expected result
        delta - Allowable variance from expected result
      • checkWinAgg

        void checkWinAgg​(java.lang.String expr,
                         java.lang.String[] inputValues,
                         java.lang.String windowSpec,
                         java.lang.String type,
                         java.lang.Object result,
                         double delta)
        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
        result - Expected result
        delta - Allowable variance from expected result
      • checkFails

        void checkFails​(java.lang.String expression,
                        java.lang.String expectedError,
                        boolean runtime)
        Tests 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
      • checkQueryFails

        void checkQueryFails​(java.lang.String sql,
                             java.lang.String expectedError)
        Tests that a SQL query fails at prepare time.
        Parameters:
        sql - SQL query
        expectedError - Pattern for expected error. Must include an error location.
      • checkQuery

        void checkQuery​(java.lang.String sql)
        Tests that a SQL query succeeds at prepare time.
        Parameters:
        sql - SQL query