org.eigenbase.sql.type
Class SqlTypeFactoryImpl

java.lang.Object
  extended by org.eigenbase.reltype.RelDataTypeFactoryImpl
      extended by org.eigenbase.sql.type.SqlTypeFactoryImpl
All Implemented Interfaces:
RelDataTypeFactory
Direct Known Subclasses:
OJTypeFactoryImpl

public class SqlTypeFactoryImpl
extends RelDataTypeFactoryImpl

SqlTypeFactoryImpl provides a default implementation of RelDataTypeFactory which supports SQL types.

Version:
$Id: //open/dev/farrago/src/org/eigenbase/sql/type/SqlTypeFactoryImpl.java#26 $
Author:
John V. Sichi

Nested Class Summary
 
Nested classes/interfaces inherited from class org.eigenbase.reltype.RelDataTypeFactoryImpl
RelDataTypeFactoryImpl.JavaType
 
Nested classes/interfaces inherited from interface org.eigenbase.reltype.RelDataTypeFactory
RelDataTypeFactory.FieldInfo, RelDataTypeFactory.ListFieldInfo
 
Constructor Summary
SqlTypeFactoryImpl()
           
 
Method Summary
private  void assertBasic(SqlTypeName typeName)
           
protected  RelDataType canonize(RelDataType type)
          Registers a type, or returns the existing type if it is already registered.
private  RelDataType copyIntervalType(RelDataType type, boolean nullable)
           
private  RelDataType copyMultisetType(RelDataType type, boolean nullable)
           
private  RelDataType copyObjectType(RelDataType type, boolean nullable)
           
private  RelDataType createDoublePrecisionType()
           
 RelDataType createMultisetType(RelDataType type, long maxCardinality)
          Creates a multiset type.
 RelDataType createSqlIntervalType(SqlIntervalQualifier intervalQualifier)
          Creates a SQL interval type.
 RelDataType createSqlType(SqlTypeName typeName)
          Creates a SQL type with no precision or scale.
 RelDataType createSqlType(SqlTypeName typeName, int precision)
          Creates a SQL type with length (precision) but no scale.
 RelDataType createSqlType(SqlTypeName typeName, int precision, int scale)
          Creates a SQL type with precision and scale.
 RelDataType createTypeWithCharsetAndCollation(RelDataType type, Charset charset, SqlCollation collation)
          Creates a Type which is the same as another type but with possibily different charset or collation.
 RelDataType createTypeWithNullability(RelDataType type, boolean nullable)
          Creates a type which is the same as another type but with possibly different nullability.
 RelDataType leastRestrictive(RelDataType[] types)
          Returns the most general of a set of types (that is, one type to which they can all be cast), or null if conversion is not possible.
private  RelDataType leastRestrictiveByCast(RelDataType[] types)
           
private  RelDataType leastRestrictiveSqlType(RelDataType[] types)
           
protected  boolean shouldRaggedFixedLengthValueUnionBeVariable()
          Controls behavior discussed here.
 
Methods inherited from class org.eigenbase.reltype.RelDataTypeFactoryImpl
copyType, createArrayType, createDecimalProduct, createDecimalQuotient, createJavaType, createJoinType, createStructType, createStructType, createStructType, getDefaultCharset, isJavaType, leastRestrictiveStructuredType, useDoubleMultiplication
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SqlTypeFactoryImpl

public SqlTypeFactoryImpl()
Method Detail

createSqlType

public RelDataType createSqlType(SqlTypeName typeName)
Description copied from interface: RelDataTypeFactory
Creates a SQL type with no precision or scale.

Parameters:
typeName - Name of the type, for example SqlTypeName.BOOLEAN.
Returns:
canonical type descriptor

createSqlType

public RelDataType createSqlType(SqlTypeName typeName,
                                 int precision)
Description copied from interface: RelDataTypeFactory
Creates a SQL type with length (precision) but no scale.

Parameters:
typeName - Name of the type, for example SqlTypeName.VARCHAR.
precision - maximum length of the value (non-numeric types) or the precision of the value (numeric/datetime types) requires both operands to have exact numeric types.
Returns:
canonical type descriptor

createSqlType

public RelDataType createSqlType(SqlTypeName typeName,
                                 int precision,
                                 int scale)
Description copied from interface: RelDataTypeFactory
Creates a SQL type with precision and scale.

Parameters:
typeName - Name of the type, for example SqlTypeName.DECIMAL.
precision - precision of the value
scale - scale of the values, i.e. the number of decimal places to shift the value. For example, a NUMBER(10,3) value of "123.45" is represented "123450" (that is, multiplied by 10^3). A negative scale is valid.
Returns:
canonical type descriptor

createMultisetType

public RelDataType createMultisetType(RelDataType type,
                                      long maxCardinality)
Description copied from interface: RelDataTypeFactory
Creates a multiset type. Multisets are unordered collections of elements.

Parameters:
type - type of the elements of the multiset
maxCardinality - maximum collection size, or -1 for unlimited
Returns:
canonical multiset type descriptor

createSqlIntervalType

public RelDataType createSqlIntervalType(SqlIntervalQualifier intervalQualifier)
Description copied from interface: RelDataTypeFactory
Creates a SQL interval type.

Parameters:
intervalQualifier - contains information if it is a year-month or a day-time interval along with precision information
Returns:
canonical type descriptor

createTypeWithCharsetAndCollation

public RelDataType createTypeWithCharsetAndCollation(RelDataType type,
                                                     Charset charset,
                                                     SqlCollation collation)
Description copied from interface: RelDataTypeFactory
Creates a Type which is the same as another type but with possibily different charset or collation. For types without a concept of charset or collation this function must throw an error.

Parameters:
type - input type
charset - charset to assign
collation - collation to assign
Returns:
output type, same as input type except with specified charset and collation

leastRestrictive

public RelDataType leastRestrictive(RelDataType[] types)
Description copied from interface: RelDataTypeFactory
Returns the most general of a set of types (that is, one type to which they can all be cast), or null if conversion is not possible. The result may be a new type which is less restrictive than any of the input types, e.g. leastRestrictive(INT, NUMERIC(3,2)) could be NUMERIC(12,2).

Specified by:
leastRestrictive in interface RelDataTypeFactory
Overrides:
leastRestrictive in class RelDataTypeFactoryImpl
Parameters:
types - input types to be unioned
Returns:
canonical union type descriptor

leastRestrictiveByCast

private RelDataType leastRestrictiveByCast(RelDataType[] types)

createTypeWithNullability

public RelDataType createTypeWithNullability(RelDataType type,
                                             boolean nullable)
Description copied from interface: RelDataTypeFactory
Creates a type which is the same as another type but with possibly different nullability. The output type may be identical to the input type. For type systems without a concept of nullability, the return value is always the same as the input.

Specified by:
createTypeWithNullability in interface RelDataTypeFactory
Overrides:
createTypeWithNullability in class RelDataTypeFactoryImpl
Parameters:
type - input type
nullable - true to request a nullable type; false to request a NOT NULL type
Returns:
output type, same as input type except with specified nullability

assertBasic

private void assertBasic(SqlTypeName typeName)

leastRestrictiveSqlType

private RelDataType leastRestrictiveSqlType(RelDataType[] types)

shouldRaggedFixedLengthValueUnionBeVariable

protected boolean shouldRaggedFixedLengthValueUnionBeVariable()
Controls behavior discussed here.

Returns:
false (the default) to provide strict SQL:2003 behavior; true to provide pragmatic behavior
Reference to SQL:2003 standard:
Part 2 Section 9.3 Syntax Rule 3.a.iii.3

createDoublePrecisionType

private RelDataType createDoublePrecisionType()

copyMultisetType

private RelDataType copyMultisetType(RelDataType type,
                                     boolean nullable)

copyIntervalType

private RelDataType copyIntervalType(RelDataType type,
                                     boolean nullable)

copyObjectType

private RelDataType copyObjectType(RelDataType type,
                                   boolean nullable)

canonize

protected RelDataType canonize(RelDataType type)
Description copied from class: RelDataTypeFactoryImpl
Registers a type, or returns the existing type if it is already registered.

Overrides:
canonize in class RelDataTypeFactoryImpl