@TestInstance(value=PER_CLASS) public class SqlOperatorTest extends Object
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:
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:
| 限定符和类型 | 类和说明 |
|---|---|
protected static class |
SqlOperatorTest.TesterImpl
Implementation of
SqlTester based on a
JDBC connection. |
| 限定符和类型 | 字段和说明 |
|---|---|
protected static TimeZone |
CURRENT_TZ |
static Pattern |
DATE_PATTERN
Regular expression for a SQL DATE value.
|
static List<String> |
DAY_VARIANTS |
static boolean |
DECIMAL
Whether DECIMAL type is implemented.
|
static List<String> |
HOUR_VARIANTS |
protected static TimeZone |
LOCAL_TZ |
static List<String> |
MICROSECOND_VARIANTS |
static List<String> |
MINUTE_VARIANTS |
static List<String> |
MONTH_VARIANTS |
static List<String> |
NANOSECOND_VARIANTS |
static List<String> |
QUARTER_VARIANTS |
static List<String> |
SECOND_VARIANTS |
static SqlOperatorTest.TesterImpl |
TESTER |
static Pattern |
TIME_PATTERN
Regular expression for a SQL TIME(0) value.
|
static Pattern |
TIMESTAMP_PATTERN
Regular expression for a SQL TIMESTAMP(0) value.
|
static boolean |
TODO |
protected static TimeZone |
UTC_TZ |
static List<String> |
WEEK_VARIANTS |
static List<String> |
YEAR_VARIANTS |
| 构造器和说明 |
|---|
SqlOperatorTest() |
| 限定符和类型 | 方法和说明 |
|---|---|
protected static org.apache.calcite.util.Pair<String,org.apache.calcite.runtime.Hook.Closeable> |
currentTimeString(TimeZone tz)
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.
|
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 |
testConstantCast()
|
void |
testJsonInsert() |
void |
testJsonReplace() |
void |
testJsonSet() |
public static final SqlOperatorTest.TesterImpl TESTER
public static final boolean TODO
public static final Pattern TIME_PATTERN
public static final Pattern TIMESTAMP_PATTERN
public static final Pattern DATE_PATTERN
protected static final TimeZone UTC_TZ
protected static final TimeZone LOCAL_TZ
protected static final TimeZone CURRENT_TZ
public static final boolean DECIMAL
protected SqlOperatorFixture fixture()
@Test public void testConstantCast()
protected static Calendar getCalendarNotTooNear(int timeUnit)
timeUnit - Time unit@Test public void testJsonInsert()
@Test public void testJsonReplace()
@Test public void testJsonSet()
protected static org.apache.calcite.util.Pair<String,org.apache.calcite.runtime.Hook.Closeable> currentTimeString(TimeZone tz)
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:".
tz - Time zoneCopyright © 2012-2023 Apache Software Foundation. All Rights Reserved.