org.eigenbase.sql.test
Class AbstractSqlTester

java.lang.Object
  extended by org.eigenbase.sql.test.AbstractSqlTester
All Implemented Interfaces:
SqlTester
Direct Known Subclasses:
FarragoSqlOperatorsSuite.FarragoSqlTester

public abstract class AbstractSqlTester
extends Object
implements SqlTester

Abstract implementation of SqlTester. A derived class only needs to implement SqlTester.check(java.lang.String, org.eigenbase.sql.test.SqlTester.TypeChecker, java.lang.Object, double), SqlTester.checkColumnType(java.lang.String, java.lang.String) and SqlTester.checkFails(java.lang.String, java.lang.String, boolean).

Since:
May 22, 2004
Version:
$Id: //open/dev/farrago/src/org/eigenbase/sql/test/AbstractSqlTester.java#23 $
Author:
wael

Nested Class Summary
private static class AbstractSqlTester.SqlTypeChecker
          Checks that a type matches a given SQL type.
static class AbstractSqlTester.StringTypeChecker
          Type checker which compares types to a specified string.
 
Nested classes/interfaces inherited from interface org.eigenbase.sql.test.SqlTester
SqlTester.TypeChecker, SqlTester.VmName
 
Field Summary
static SqlTester.TypeChecker AnyTypeChecker
          Checker which allows any type.
static SqlTester.TypeChecker BooleanTypeChecker
           
static SqlTester.TypeChecker IntegerTypeChecker
           
private  SqlOperator operator
           
 
Constructor Summary
AbstractSqlTester()
           
 
Method Summary
protected  String buildQuery(String expression)
          Helper method which converts a scalar expression into a SQL query.
 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 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 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.
static String generateAggQuery(String expr, String[] inputValues)
           
static String generateWinAggQuery(String expr, String windowSpec, String[] inputValues)
           
protected  SqlOperator getFor()
          Returns the operator this test is for.
static String getTypeString(RelDataType sqlType)
          Helper function to get the string representation of a RelDataType (include precision/scale but no charset or collation)
 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
 
Methods inherited from interface org.eigenbase.sql.test.SqlTester
check, checkColumnType, checkFails
 

Field Detail

IntegerTypeChecker

public static final SqlTester.TypeChecker IntegerTypeChecker

BooleanTypeChecker

public static final SqlTester.TypeChecker BooleanTypeChecker

AnyTypeChecker

public static final SqlTester.TypeChecker AnyTypeChecker
Checker which allows any type.


operator

private SqlOperator operator
Constructor Detail

AbstractSqlTester

public AbstractSqlTester()
Method Detail

setFor

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

Specified by:
setFor in interface SqlTester
Parameters:
operator - Operator
unimplementedVmNames - Names of virtual machines for which this

checkAgg

public void checkAgg(String expr,
                     String[] inputValues,
                     Object result,
                     double delta)
Description copied from interface: SqlTester
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);

Specified by:
checkAgg in interface SqlTester
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

public void checkWinAgg(String expr,
                        String[] inputValues,
                        String windowSpec,
                        String type,
                        Object result,
                        double delta)
Description copied from interface: SqlTester
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);

Specified by:
checkWinAgg in interface SqlTester
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

getTypeString

public static String getTypeString(RelDataType sqlType)
Helper function to get the string representation of a RelDataType (include precision/scale but no charset or collation)

Parameters:
sqlType - Type
Returns:
String representation of type

generateAggQuery

public static String generateAggQuery(String expr,
                                      String[] inputValues)

generateWinAggQuery

public static String generateWinAggQuery(String expr,
                                         String windowSpec,
                                         String[] inputValues)

buildQuery

protected String buildQuery(String expression)
Helper method which converts a scalar expression into a SQL query.

By default, "expr" becomes "VALUES (expr)". Derived classes may override.

Parameters:
expression - Expression
Returns:
Query that returns expression

checkType

public void checkType(String expression,
                      String type)
Description copied from interface: SqlTester
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 SqlTester.checkScalarExact(java.lang.String, java.lang.String).

Specified by:
checkType in interface SqlTester
Parameters:
expression - Scalar expression
type - Type string

checkScalarExact

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

Specified by:
checkScalarExact in interface SqlTester
Parameters:
expression - Scalar expression
result - Expected result

checkScalarExact

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

Specified by:
checkScalarExact in interface SqlTester
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

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

Specified by:
checkScalarApprox in interface SqlTester
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

public void checkBoolean(String expression,
                         Boolean result)
Description copied from interface: SqlTester
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);

Specified by:
checkBoolean in interface SqlTester
Parameters:
expression - Scalar expression
result - Expected result (null signifies NULL).

checkString

public void checkString(String expression,
                        String result,
                        String expectedType)
Description copied from interface: SqlTester
Tests that a scalar SQL expression returns the expected string result. For example,
checkScalarExact("'ab' || 'c'", "abc");

Specified by:
checkString in interface SqlTester
Parameters:
expression - Scalar expression
result - Expected result
expectedType - Expected result type

checkNull

public void checkNull(String expression)
Description copied from interface: SqlTester
Tests that a SQL expression returns the SQL NULL value. For example,
checkNull("CHAR_LENGTH(CAST(NULL AS VARCHAR(3))");

Specified by:
checkNull in interface SqlTester
Parameters:
expression - Scalar expression

checkScalar

public void checkScalar(String expression,
                        Object result,
                        String resultType)
Description copied from interface: SqlTester
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");

Specified by:
checkScalar in interface SqlTester
Parameters:
expression - Scalar expression
result - Expected result
resultType - Expected result type

getFor

protected SqlOperator getFor()
Returns the operator this test is for. Throws if no operator has been set.

Returns:
the operator this test is for, never null