org.eigenbase.sql.test
Interface SqlTester

All Known Implementing Classes:
AbstractSqlTester, FarragoSqlOperatorsSuite.FarragoSqlTester, SqlAdvisorTest.AdvisorTestImpl, SqlValidatorFeatureTest.FeatureTesterImpl, SqlValidatorTestCase.TesterImpl

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.

Since:
May 22, 2004
Version:
$Id: //open/dev/farrago/src/org/eigenbase/sql/test/SqlTester.java#17 $
Author:
Wael Chatila

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

checkScalar

void checkScalar(String expression,
                 Object result,
                 String resultType)
Tests that a scalar SQL expression returns the expected result and the expected type. For example,
checkScalar("1.1 + 2.9", "4.0", "DECIMAL(2, 1) NOT NULL");

Parameters:
expression - Scalar expression
result - Expected result
resultType - Expected result type

checkScalarExact

void checkScalarExact(String expression,
                      String result)
Tests that a scalar SQL expression returns the expected exact numeric result as an integer. For example,
checkScalarExact("1 + 2", "3");

Parameters:
expression - Scalar expression
result - Expected result

checkScalarExact

void checkScalarExact(String expression,
                      String expectedType,
                      String result)
Tests that a scalar SQL expression returns the expected exact numeric result. For example,
checkScalarExact("1 + 2", "3");

Parameters:
expression - Scalar expression
expectedType - Type we expect the result to have, including nullability, precision and scale, for example DECIMAL(2, 1) NOT NULL.
result - Expected result

checkScalarApprox

void checkScalarApprox(String expression,
                       String expectedType,
                       double expectedResult,
                       double delta)
Tests that a scalar SQL expression returns expected appoximate numeric result. For example,
checkScalarApprox("1.0 + 2.1", "3.1");

Parameters:
expression - Scalar expression
expectedType - Type we expect the result to have, including nullability, precision and scale, for example DECIMAL(2, 1) NOT NULL.
expectedResult - Expected result
delta - Allowed margin of error between expected and actual result

checkBoolean

void checkBoolean(String expression,
                  Boolean result)
Tests that a scalar SQL expression returns the expected boolean result. For example,
checkScalarExact("TRUE AND FALSE", Boolean.TRUE);
The expected result can be null:
checkScalarExact("NOT UNKNOWN", null);

Parameters:
expression - Scalar expression
result - Expected result (null signifies NULL).

checkString

void checkString(String expression,
                 String result,
                 String resultType)
Tests that a scalar SQL expression returns the expected string result. For example,
checkScalarExact("'ab' || 'c'", "abc");

Parameters:
expression - Scalar expression
result - Expected result
resultType - Expected result type

checkNull

void checkNull(String expression)
Tests that a SQL expression returns the SQL NULL value. For example,
checkNull("CHAR_LENGTH(CAST(NULL AS VARCHAR(3))");

Parameters:
expression - Scalar expression

checkType

void checkType(String expression,
               String type)
Tests that a SQL expression has a given type. For example,
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).

Parameters:
expression - Scalar expression
type - Type string

checkColumnType

void checkColumnType(String sql,
                     String type)
Checks that a query returns one column of an expected type. For example, checkType("VALUES (1 + 2)", "INTEGER NOT NULL").

Parameters:
sql - Query expression
type - Type string

check

void check(String query,
           SqlTester.TypeChecker typeChecker,
           Object result,
           double delta)
Tests that a SQL query returns a single column with the given type. For example,
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.

Parameters:
query - SQL query
typeChecker - Checks whether the result is the expected type; must not be null
result - Expected result
delta - The acceptable tolerance between the expected and actual

setFor

void setFor(SqlOperator operator,
            SqlTester.VmName... unimplementedVmNames)
Declares that this test is for a given operator. So we can check that all operators are tested.

Parameters:
operator - Operator
unimplementedVmNames - Names of virtual machines for which this

checkAgg

void checkAgg(String expr,
              String[] inputValues,
              Object result,
              double delta)
Checks that an aggregate expression returns the expected result.

For example, checkAgg("AVG(DISTINCT x)", new String[] {"2", "3", null, "3" }, new Double(2.5), 0);

Parameters:
expr - Aggregate expression, e.g. SUM(DISTINCT x)
inputValues - Array of input values, e.g. ["1", null, "2"].
result - Expected result
delta - Allowable variance from expected result

checkWinAgg

void checkWinAgg(String expr,
                 String[] inputValues,
                 String windowSpec,
                 String type,
                 Object result,
                 double delta)
Checks that a windowed aggregate expression returns the expected result.

For example, checkWinAgg("FIRST_VALUE(x)", new String[] {"2", "3", null, "3" }, "INTEGER NOT NULL", 2, 0d);

Parameters:
expr - Aggregate expression, e.g. SUM(DISTINCT x)
inputValues - Array of input values, e.g. ["1", null, "2"].
type - Expected result type
result - Expected result
delta - Allowable variance from expected result

checkFails

void checkFails(String expression,
                String expectedError,
                boolean runtime)
Tests that a scalar SQL expression fails at run time.

Parameters:
expression - SQL scalar expression
expectedError - 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