Class SqlOperatorTest
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.
-
Nested Class Summary
Modifier and TypeClassDescriptionprotected static class
Implementation ofSqlTester
based on a JDBC connection. -
Field Summary
Modifier and TypeFieldDescriptionprotected static final TimeZone
static final Pattern
Regular expression for a SQL DATE value.protected static final TimeZone
static final SqlOperatorTest.TesterImpl
static final Pattern
Regular expression for a SQL TIME(0/1) value.static final Pattern
Regular expression for a SQL TIMESTAMP(0/1) value.static final boolean
protected static final TimeZone
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected static Pair<String,
Hook.Closeable> Returns a time string, in GMT, that will be valid for at least 2 minutes.protected SqlOperatorFixture
fixture()
Sub-classes should override to run tests in a different environment.void
protected static Calendar
getCalendarNotTooNear
(int timeUnit) Returns a Calendar that is the current time, pausing if we are within 2 minutes of midnight or the top of the hour.void
void
Test cases for [CALCITE-6322] Casts to DECIMAL types are ignored.void
void
void
void
void
Test case for Cast to VARBINARY causes an assertion failure.void
-
Field Details
-
TESTER
-
TODO
public static final boolean TODO- See Also:
-
TIME_PATTERN
Regular expression for a SQL TIME(0/1) value. -
TIMESTAMP_PATTERN
Regular expression for a SQL TIMESTAMP(0/1) value. -
DATE_PATTERN
Regular expression for a SQL DATE value. -
MICROSECOND_VARIANTS
-
NANOSECOND_VARIANTS
-
SECOND_VARIANTS
-
MINUTE_VARIANTS
-
HOUR_VARIANTS
-
DAY_VARIANTS
-
WEEK_VARIANTS
-
MONTH_VARIANTS
-
QUARTER_VARIANTS
-
YEAR_VARIANTS
-
UTC_TZ
-
LOCAL_TZ
-
CURRENT_TZ
-
-
Constructor Details
-
SqlOperatorTest
public SqlOperatorTest()
-
-
Method Details
-
fixture
Sub-classes should override to run tests in a different environment. -
floatPrecisionTest
@Test public void floatPrecisionTest() -
testIssue6322
@Test public void testIssue6322()Test cases for [CALCITE-6322] Casts to DECIMAL types are ignored. -
testConstantCast
@Test public void testConstantCast() -
testVarbinaryCast
@Test public void testVarbinaryCast()Test case for Cast to VARBINARY causes an assertion failure. -
getCalendarNotTooNear
Returns a Calendar that is the current time, pausing if we are within 2 minutes of midnight or the top of the hour.- Parameters:
timeUnit
- Time unit- Returns:
- calendar
-
testVarbitArithmetic
@Test public void testVarbitArithmetic() -
testJsonInsert
@Test public void testJsonInsert() -
testJsonReplace
@Test public void testJsonReplace() -
testJsonSet
@Test public void testJsonSet() -
currentTimeString
Returns a time string, in GMT, that will be valid for at least 2 minutes.For example, at "2005-01-01 12:34:56 PST", returns "2005-01-01 20:". At "2005-01-01 12:34:59 PST", waits a minute, then returns "2005-01-01 21:".
- Parameters:
tz
- Time zone- Returns:
- Time string
-
testOverflow
@Test public void testOverflow()
-