|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
public interface SqlTester
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 SqlTestser might evaluate the
queries in different ways, for example, using a C++ versus Java calculator.
An implementation might even ignore certain calls altogether.
| Nested Class Summary | |
|---|---|
static interface |
SqlTester.TypeChecker
|
static class |
SqlTester.VmName
Name of a virtual machine that can potentially implement an operator. |
| Method Summary | |
|---|---|
void |
check(String query,
SqlTester.TypeChecker typeChecker,
Object result,
double delta)
Tests that a SQL query returns a single column with the given type. |
void |
checkAgg(String expr,
String[] inputValues,
Object result,
double delta)
Checks that an aggregate expression returns the expected result. |
void |
checkBoolean(String expression,
Boolean result)
Tests that a scalar SQL expression returns the expected boolean result. |
void |
checkColumnType(String sql,
String type)
Checks that a query returns one column of an expected type. |
void |
checkFails(String expression,
String expectedError,
boolean runtime)
Tests that a scalar SQL expression fails at run time. |
void |
checkNull(String expression)
Tests that a SQL expression returns the SQL NULL value. |
void |
checkScalar(String expression,
Object result,
String resultType)
Tests that a scalar SQL expression returns the expected result and the expected type. |
void |
checkScalarApprox(String expression,
String expectedType,
double expectedResult,
double delta)
Tests that a scalar SQL expression returns expected appoximate numeric result. |
void |
checkScalarExact(String expression,
String result)
Tests that a scalar SQL expression returns the expected exact numeric result as an integer. |
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,
Object result,
double delta)
Checks that a windowed aggregate expression returns the expected result. |
void |
setFor(SqlOperator operator,
SqlTester.VmName... unimplementedVmNames)
Declares that this test is for a given operator. |
| Method Detail |
|---|
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 type
void checkScalarExact(String expression,
String result)
checkScalarExact("1 + 2", "3");
expression - Scalar expressionresult - Expected result
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 result
void checkScalarApprox(String expression,
String expectedType,
double expectedResult,
double delta)
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.expectedResult - Expected resultdelta - Allowed margin of error between expected and actual result
void checkBoolean(String expression,
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 expression
void 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, java.lang.String).
expression - Scalar expressiontype - Type string
void checkColumnType(String sql,
String type)
checkType("VALUES (1 + 2)", "INTEGER NOT NULL").
sql - Query expressiontype - Type string
void check(String query,
SqlTester.TypeChecker typeChecker,
Object result,
double delta)
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 resultdelta - The acceptable tolerance between the expected and actual
void setFor(SqlOperator operator,
SqlTester.VmName... unimplementedVmNames)
operator - OperatorunimplementedVmNames - Names of virtual machines for which this
void checkAgg(String expr,
String[] inputValues,
Object result,
double delta)
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"].result - Expected resultdelta - Allowable variance from expected result
void checkWinAgg(String expr,
String[] inputValues,
String windowSpec,
String type,
Object result,
double delta)
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 typeresult - Expected resultdelta - Allowable variance from expected result
void checkFails(String 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 time
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||