org.eigenbase.reltype
Interface RelDataTypeFactory

All Known Subinterfaces:
FarragoTypeFactory, OJTypeFactory
All Known Implementing Classes:
FarragoTypeFactoryImpl, LucidDbTypeFactory, OJTypeFactoryImpl, RelDataTypeFactoryImpl, SqlTypeFactoryImpl

public interface RelDataTypeFactory

RelDataTypeFactory is a factory for datatype descriptors. It defines methods for instantiating and combining SQL, Java, and collection types. The factory also provides methods for return type inference for arithmetic in cases where SQL 2003 is implementation defined or impractical.

This interface is an example of the abstract factory pattern. Any implementation of RelDataTypeFactory must ensure that type objects are canonical: two types are equal if and only if they are represented by the same Java object. This reduces memory consumption and comparison cost.

Since:
May 29, 2003
Version:
$Id: //open/dev/farrago/src/org/eigenbase/reltype/RelDataTypeFactory.java#18 $
Author:
jhyde

Nested Class Summary
static interface RelDataTypeFactory.FieldInfo
          Callback which provides enough information to create fields.
static class RelDataTypeFactory.ListFieldInfo
          Simple implementation of RelDataTypeFactory.FieldInfo, based on a list of fields.
 
Method Summary
 RelDataType copyType(RelDataType type)
          Duplicates a type, making a deep copy.
 RelDataType createArrayType(RelDataType elementType, long maxCardinality)
          Creates an array type.
 RelDataType createDecimalProduct(RelDataType type1, RelDataType type2)
          Infers the return type of a decimal multiplication.
 RelDataType createDecimalQuotient(RelDataType type1, RelDataType type2)
          Infers the return type of a decimal division.
 RelDataType createJavaType(Class clazz)
          Creates a type which corresponds to a Java class.
 RelDataType createJoinType(RelDataType[] types)
          Creates a cartesian product type.
 RelDataType createMultisetType(RelDataType elementType, 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 createStructType(List<RelDataType> typeList, List<String> fieldNameList)
          Creates a type which represents a structured collection of fields, given lists of the names and types of the fields.
 RelDataType createStructType(RelDataType[] types, String[] fieldNames)
          Creates a type which represents a structured collection of fields.
 RelDataType createStructType(RelDataTypeFactory.FieldInfo fieldInfo)
          Creates a type which represents a structured collection of fields, obtaining the field information via a callback.
 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.
 Charset getDefaultCharset()
           
 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.
 boolean useDoubleMultiplication(RelDataType type1, RelDataType type2)
           
 

Method Detail

createJavaType

RelDataType createJavaType(Class clazz)
Creates a type which corresponds to a Java class.

Parameters:
clazz - the Java class used to define the type
Returns:
canonical Java type descriptor

createJoinType

RelDataType createJoinType(RelDataType[] types)
Creates a cartesian product type.

Returns:
canonical join type descriptor
"Precondition:"
types array of types to be joined, types != null, types.length >= 1

createStructType

RelDataType createStructType(RelDataType[] types,
                             String[] fieldNames)
Creates a type which represents a structured collection of fields.

Parameters:
types - types of the fields
fieldNames - names of the fields
Returns:
canonical struct type descriptor
"Precondition:"
types.length == fieldNames.length
"Postcondition:"
return != null

createStructType

RelDataType createStructType(List<RelDataType> typeList,
                             List<String> fieldNameList)
Creates a type which represents a structured collection of fields, given lists of the names and types of the fields.

Parameters:
typeList - types of the fields
fieldNameList - names of the fields
Returns:
canonical struct type descriptor
"Precondition:"
typeList.size() == fieldNameList.size()
"Postcondition:"
return != null

createStructType

RelDataType createStructType(RelDataTypeFactory.FieldInfo fieldInfo)
Creates a type which represents a structured collection of fields, obtaining the field information via a callback.

Parameters:
fieldInfo - callback for field information
Returns:
canonical struct type descriptor

createArrayType

RelDataType createArrayType(RelDataType elementType,
                            long maxCardinality)
Creates an array type. Arrays are ordered collections of elements.

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

createMultisetType

RelDataType createMultisetType(RelDataType elementType,
                               long maxCardinality)
Creates a multiset type. Multisets are unordered collections of elements.

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

copyType

RelDataType copyType(RelDataType type)
Duplicates a type, making a deep copy. Normally, this is a no-op, since canonical type objects are returned. However, it is useful when copying a type from one factory to another.

Parameters:
type - input type
Returns:
output type, a new object equivalent to input type

createTypeWithNullability

RelDataType createTypeWithNullability(RelDataType type,
                                      boolean nullable)
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.

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

createTypeWithCharsetAndCollation

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. 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
"Precondition:"
SqlTypeUtil.inCharFamily(type)

getDefaultCharset

Charset getDefaultCharset()
Returns:
the default Charset for string types

leastRestrictive

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. 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).

Parameters:
types - input types to be unioned
Returns:
canonical union type descriptor
"Precondition:"
types != null, types.length >= 1

createSqlType

RelDataType createSqlType(SqlTypeName typeName)
Creates a SQL type with no precision or scale.

Parameters:
typeName - Name of the type, for example SqlTypeName.BOOLEAN.
Returns:
canonical type descriptor
"Precondition:"
typeName != null
"Postcondition:"
return != null

createSqlType

RelDataType createSqlType(SqlTypeName typeName,
                          int precision)
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
"Precondition:"
typeName != null, length >= 0
"Postcondition:"
return != null

createSqlType

RelDataType createSqlType(SqlTypeName typeName,
                          int precision,
                          int scale)
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
"Precondition:"
typeName != null, length >= 0
"Postcondition:"
return != null

createSqlIntervalType

RelDataType createSqlIntervalType(SqlIntervalQualifier intervalQualifier)
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

createDecimalProduct

RelDataType createDecimalProduct(RelDataType type1,
                                 RelDataType type2)
Infers the return type of a decimal multiplication. Decimal multiplication involves at least one decimal operand and requires both operands to have exact numeric types.

Parameters:
type1 - type of the first operand
type2 - type of the second operand
Returns:
the result type for a decimal multiplication, or null if decimal multiplication should not be applied to the operands.

useDoubleMultiplication

boolean useDoubleMultiplication(RelDataType type1,
                                RelDataType type2)
Returns:
whether a decimal multiplication should be implemented by casting arguments to double values.
"Precondition:"
createDecimalProduct(type1, type2) != null

createDecimalQuotient

RelDataType createDecimalQuotient(RelDataType type1,
                                  RelDataType type2)
Infers the return type of a decimal division. Decimal division involves at least one decimal operand and requires both operands to have exact numeric types.

Parameters:
type1 - type of the first operand
type2 - type of the second operand
Returns:
the result type for a decimal division, or null if decimal division should not be applied to the operands.