|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.eigenbase.test.SqlValidatorTestCase.TesterImpl
public static class SqlValidatorTestCase.TesterImpl
Implementation of SqlValidatorTestCase.Tester
which talks to a mock catalog.
It is also a pure-Java implementation of the SqlTester used by
SqlOperatorTests. It can parse and validate queries, but it does
not invoke Farrago, so it is very fast but cannot execute functions.
| Nested Class Summary |
|---|
| Nested classes/interfaces inherited from interface org.eigenbase.sql.test.SqlTester |
|---|
SqlTester.TypeChecker, SqlTester.VmName |
| Field Summary | |
|---|---|
protected SqlConformance |
conformance
|
protected SqlOperatorTable |
opTab
|
| Constructor Summary | |
|---|---|
SqlValidatorTestCase.TesterImpl(SqlConformance conformance)
|
|
| Method Summary | |
|---|---|
void |
assertExceptionIsThrown(String sql,
String expectedMsgPattern)
Checks that a query is valid, or, if invalid, throws the right message at the right location. |
private static String |
buildQuery(String expression)
|
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 |
checkCharset(String sql,
Charset expectedCharset)
|
void |
checkCollation(String sql,
String expectedCollationName,
SqlCollation.Coercibility expectedCoercibility)
|
void |
checkColumnType(String sql,
String expected)
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 |
checkIntervalConv(String sql,
String expected)
Checks if the interval value conversion to milliseconds is valid. |
void |
checkNull(String expression)
Tests that a SQL expression returns the SQL NULL value. |
void |
checkResultType(String sql,
String expected)
Checks that a query returns one column of an expected type. |
void |
checkRewrite(SqlValidator validator,
String query,
String expectedRewrite)
Checks that a query gets rewritten to an expected form. |
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 expectedType)
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. |
protected SqlOperatorTable |
createOperatorTable()
|
RelDataType |
getColumnType(String sql)
Returns the data type of the sole column of a SQL query. |
SqlConformance |
getConformance()
|
SqlMonotonicity |
getMonotonicity(String sql)
Given a SQL query, returns the monotonicity of the first item in the SELECT clause. |
RelDataType |
getResultType(String sql)
Returns the data type of the row returned by a SQL query. |
SqlValidator |
getValidator()
|
SqlNode |
parseAndValidate(SqlValidator validator,
String sql)
|
SqlNode |
parseQuery(String sql)
|
void |
setFor(SqlOperator operator,
SqlTester.VmName... unimplementedVmNames)
Declares that this test is for a given operator. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected final SqlOperatorTable opTab
protected final SqlConformance conformance
| Constructor Detail |
|---|
public SqlValidatorTestCase.TesterImpl(SqlConformance conformance)
| Method Detail |
|---|
public SqlConformance getConformance()
getConformance in interface SqlValidatorTestCase.Testerprotected SqlOperatorTable createOperatorTable()
public SqlValidator getValidator()
getValidator in interface SqlValidatorTestCase.Tester
public void assertExceptionIsThrown(String sql,
String expectedMsgPattern)
SqlValidatorTestCase.TesterIf expectedMsgPattern is null, the query must
succeed.
If expectedMsgPattern is not null, the query must
fail, and give an error location of (expectedLine, expectedColumn)
through (expectedEndLine, expectedEndColumn).
assertExceptionIsThrown in interface SqlValidatorTestCase.Testersql - SQL statementexpectedMsgPattern - If this parameter is null the query must be
valid for the test to pass; If this parameter is not null the query
must be malformed and the message given must match the patternpublic RelDataType getColumnType(String sql)
SqlValidatorTestCase.TesterFor example, getResultType("VALUES (1") returns
INTEGER.
Fails if query returns more than one column.
getColumnType in interface SqlValidatorTestCase.TesterSqlValidatorTestCase.Tester.getResultType(String)public RelDataType getResultType(String sql)
SqlValidatorTestCase.TesterFor example, getResultType("VALUES (1, 'foo')")
returns RecordType(INTEGER EXPR$0, CHAR(3) EXPR#1).
getResultType in interface SqlValidatorTestCase.Tester
public SqlNode parseAndValidate(SqlValidator validator,
String sql)
parseAndValidate in interface SqlValidatorTestCase.Tester
public SqlNode parseQuery(String sql)
throws SqlParseException
parseQuery in interface SqlValidatorTestCase.TesterSqlParseException
public void checkColumnType(String sql,
String expected)
SqlTestercheckType("VALUES (1 + 2)", "INTEGER NOT NULL").
checkColumnType in interface SqlTestercheckColumnType in interface SqlValidatorTestCase.Testersql - Query expressionexpected - Type string
public void checkResultType(String sql,
String expected)
SqlValidatorTestCase.TestercheckType("select empno, name from emp""{EMPNO INTEGER
NOT NULL, NAME VARCHAR(10) NOT NULL}").
checkResultType in interface SqlValidatorTestCase.Tester
public void checkIntervalConv(String sql,
String expected)
SqlValidatorTestCase.TestercheckIntervalConv(VALUES (INTERVAL '1' Minute),
"60000").
checkIntervalConv in interface SqlValidatorTestCase.Tester
public void checkType(String expression,
String type)
SqlTester
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 SqlTester.checkScalarExact(java.lang.String, java.lang.String).
checkType in interface SqlTesterexpression - Scalar expressiontype - Type string
public void checkCollation(String sql,
String expectedCollationName,
SqlCollation.Coercibility expectedCoercibility)
checkCollation in interface SqlValidatorTestCase.Tester
public void checkCharset(String sql,
Charset expectedCharset)
checkCharset in interface SqlValidatorTestCase.Tester
public void setFor(SqlOperator operator,
SqlTester.VmName... unimplementedVmNames)
SqlTester
setFor in interface SqlTesteroperator - OperatorunimplementedVmNames - Names of virtual machines for which this
public void checkAgg(String expr,
String[] inputValues,
Object result,
double delta)
SqlTesterFor example, checkAgg("AVG(DISTINCT x)", new String[] {"2", "3",
null, "3" }, new Double(2.5), 0);
checkAgg in interface SqlTesterexpr - 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
public void checkWinAgg(String expr,
String[] inputValues,
String windowSpec,
String type,
Object result,
double delta)
SqlTesterFor example, checkWinAgg("FIRST_VALUE(x)", new String[] {"2",
"3", null, "3" }, "INTEGER NOT NULL", 2, 0d);
checkWinAgg in interface SqlTesterexpr - 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
public void checkScalar(String expression,
Object result,
String resultType)
SqlTester
checkScalar("1.1 + 2.9", "4.0", "DECIMAL(2, 1) NOT NULL");
checkScalar in interface SqlTesterexpression - Scalar expressionresult - Expected resultresultType - Expected result type
public void checkScalarExact(String expression,
String result)
SqlTester
checkScalarExact("1 + 2", "3");
checkScalarExact in interface SqlTesterexpression - Scalar expressionresult - Expected result
public void checkScalarExact(String expression,
String expectedType,
String result)
SqlTester
checkScalarExact("1 + 2", "3");
checkScalarExact in interface SqlTesterexpression - Scalar expressionexpectedType - Type we expect the result to have, including
nullability, precision and scale, for example DECIMAL(2, 1) NOT
NULL.result - Expected result
public void checkScalarApprox(String expression,
String expectedType,
double expectedResult,
double delta)
SqlTester
checkScalarApprox("1.0 + 2.1", "3.1");
checkScalarApprox in interface SqlTesterexpression - 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
public void checkBoolean(String expression,
Boolean result)
SqlTester
checkScalarExact("TRUE AND FALSE", Boolean.TRUE);
The expected result can be null:
checkScalarExact("NOT UNKNOWN", null);
checkBoolean in interface SqlTesterexpression - Scalar expressionresult - Expected result (null signifies NULL).
public void checkString(String expression,
String result,
String expectedType)
SqlTester
checkScalarExact("'ab' || 'c'", "abc");
checkString in interface SqlTesterexpression - Scalar expressionresult - Expected resultexpectedType - Expected result typepublic void checkNull(String expression)
SqlTester
checkNull("CHAR_LENGTH(CAST(NULL AS VARCHAR(3))");
checkNull in interface SqlTesterexpression - Scalar expression
public void check(String query,
SqlTester.TypeChecker typeChecker,
Object result,
double delta)
SqlTester
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.
check in interface SqlTesterquery - SQL querytypeChecker - Checks whether the result is the expected type; must
not be nullresult - Expected resultdelta - The acceptable tolerance between the expected and actual
public void checkRewrite(SqlValidator validator,
String query,
String expectedRewrite)
SqlValidatorTestCase.Tester
checkRewrite in interface SqlValidatorTestCase.Testervalidator - validator to use; null for defaultquery - query to testexpectedRewrite - expected SQL text after rewrite and unparse
public void checkFails(String expression,
String expectedError,
boolean runtime)
SqlTester
checkFails in interface SqlTesterexpression - 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 timepublic SqlMonotonicity getMonotonicity(String sql)
SqlValidatorTestCase.Tester
getMonotonicity in interface SqlValidatorTestCase.Testersql - SQL query
private static String buildQuery(String expression)
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||