Class SqlOperatorTest

java.lang.Object
org.apache.calcite.test.SqlOperatorTest

@TestInstance(PER_CLASS) public class SqlOperatorTest extends Object
Contains unit tests for all operators. Each of the methods is named after an operator.

To run, you also need an execution mechanism: parse, validate, and execute expressions on the operators. This is left to a SqlTester object which is obtained via the fixture() method. The default tester merely validates calls to operators, but CalciteSqlOperatorTest uses a tester that executes calls and checks that results are valid.

Different implementations of SqlTester are possible, such as:

  • Execute against a JDBC database;
  • Parse and validate but do not evaluate expressions;
  • Generate a SQL script;
  • Analyze which operators are adequately tested.

A typical method will be named after the operator it is testing (say testSubstringFunc). It first calls SqlOperatorFixture.setFor(SqlOperator, VmName...) to declare which operator it is testing.


 public void testSubstringFunc() {
     tester.setFor(SqlStdOperatorTable.substringFunc);
     tester.checkScalar("sin(0)", "0");
     tester.checkScalar("sin(1.5707)", "1");
 }

The rest of the method contains calls to the various checkXxx methods in the SqlTester interface. For an operator to be adequately tested, there need to be tests for:

  • Parsing all of its the syntactic variants.
  • Deriving the type of in all combinations of arguments.
    • Pay particular attention to nullability. For example, the result of the "+" operator is NOT NULL if and only if both of its arguments are NOT NULL.
    • Also pay attention to precision/scale/length. For example, the maximum length of the "||" operator is the sum of the maximum lengths of its arguments.
  • Executing the function. Pay particular attention to corner cases such as null arguments or null results.
  • Field Details

    • TESTER

      public static final SqlOperatorTest.TesterImpl TESTER
    • TODO

      public static final boolean TODO
      See Also:
    • TIME_PATTERN

      public static final Pattern TIME_PATTERN
      Regular expression for a SQL TIME(0/1) value.
    • TIMESTAMP_PATTERN

      public static final Pattern TIMESTAMP_PATTERN
      Regular expression for a SQL TIMESTAMP(0/1) value.
    • DATE_PATTERN

      public static final Pattern DATE_PATTERN
      Regular expression for a SQL DATE value.
    • MICROSECOND_VARIANTS

      public static final List<String> MICROSECOND_VARIANTS
    • NANOSECOND_VARIANTS

      public static final List<String> NANOSECOND_VARIANTS
    • SECOND_VARIANTS

      public static final List<String> SECOND_VARIANTS
    • MINUTE_VARIANTS

      public static final List<String> MINUTE_VARIANTS
    • HOUR_VARIANTS

      public static final List<String> HOUR_VARIANTS
    • DAY_VARIANTS

      public static final List<String> DAY_VARIANTS
    • WEEK_VARIANTS

      public static final List<String> WEEK_VARIANTS
    • MONTH_VARIANTS

      public static final List<String> MONTH_VARIANTS
    • QUARTER_VARIANTS

      public static final List<String> QUARTER_VARIANTS
    • YEAR_VARIANTS

      public static final List<String> YEAR_VARIANTS
    • UTC_TZ

      protected static final TimeZone UTC_TZ
    • LOCAL_TZ

      protected static final TimeZone LOCAL_TZ
    • CURRENT_TZ

      protected static final TimeZone CURRENT_TZ
    • DECIMAL

      public static final boolean DECIMAL
      Whether DECIMAL type is implemented.
      See Also:
  • Constructor Details

    • SqlOperatorTest

      public SqlOperatorTest()
  • Method Details