org.eigenbase.reltype
Class RelDataTypeFactoryImpl

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

public abstract class RelDataTypeFactoryImpl
extends Object
implements RelDataTypeFactory

Abstract base for implementations of RelDataTypeFactory.

Since:
May 31, 2003
Version:
$Id: //open/dev/farrago/src/org/eigenbase/reltype/RelDataTypeFactoryImpl.java#24 $
Author:
jhyde

Nested Class Summary
protected  class RelDataTypeFactoryImpl.JavaType
          Type which is based upon a Java class.
 
Nested classes/interfaces inherited from interface org.eigenbase.reltype.RelDataTypeFactory
RelDataTypeFactory.FieldInfo, RelDataTypeFactory.ListFieldInfo
 
Field Summary
private  HashMap<RelDataType,RelDataType> map
           
 
Constructor Summary
protected RelDataTypeFactoryImpl()
           
 
Method Summary
private static void addFields(RelDataType type, ArrayList<RelDataTypeField> fieldList)
          Adds all fields in type to fieldList.
protected  RelDataType canonize(RelDataType type)
          Registers a type, or returns the existing type if it is already registered.
private  RelDataType copyRecordType(RelRecordType type, boolean ignoreNullable, boolean nullable)
           
private  RelDataType copySimpleType(RelDataType type, boolean nullable)
           
 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)
          implement RelDataTypeFactory with SQL 2003 compliant behavior.
 RelDataType createDecimalQuotient(RelDataType type1, RelDataType type2)
          implement RelDataTypeFactory Let p1, s1 be the precision and scale of the first operand Let p2, s2 be the precision and scale of the second operand Let p, s be the precision and scale of the result, Let d be the number of whole digits in the result Then the result type is a decimal with: d = p1 - s1 + s2 s <= max(6, s1 + p2 + 1) p = d + s p and s are capped at their maximum values
 RelDataType createJavaType(Class clazz)
          Creates a type which corresponds to a Java class.
 RelDataType createJoinType(RelDataType[] types)
          Creates a cartesian product type.
 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 createTypeWithNullability(RelDataType type, boolean nullable)
          Creates a type which is the same as another type but with possibly different nullability.
private  RelDataTypeField[] fieldsOf(Class clazz)
           
 Charset getDefaultCharset()
           
private static RelDataTypeField[] getFieldArray(RelDataType[] types)
          Returns an array of the fields in an array of types.
private static RelDataType[] getTypeArray(RelDataType[] types)
          Returns an array of all atomic types in an array.
private static void getTypeArray(RelDataType[] types, ArrayList<RelDataType> typeList)
           
static boolean isJavaType(RelDataType t)
           
 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.
protected  RelDataType leastRestrictiveStructuredType(RelDataType[] types)
           
 boolean useDoubleMultiplication(RelDataType type1, RelDataType type2)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.eigenbase.reltype.RelDataTypeFactory
createMultisetType, createSqlIntervalType, createSqlType, createSqlType, createSqlType, createTypeWithCharsetAndCollation
 

Field Detail

map

private HashMap<RelDataType,RelDataType> map
Constructor Detail

RelDataTypeFactoryImpl

protected RelDataTypeFactoryImpl()
Method Detail

createJavaType

public RelDataType createJavaType(Class clazz)
Description copied from interface: RelDataTypeFactory
Creates a type which corresponds to a Java class.

Specified by:
createJavaType in interface RelDataTypeFactory
Parameters:
clazz - the Java class used to define the type
Returns:
canonical Java type descriptor

createJoinType

public RelDataType createJoinType(RelDataType[] types)
Description copied from interface: RelDataTypeFactory
Creates a cartesian product type.

Specified by:
createJoinType in interface RelDataTypeFactory
Returns:
canonical join type descriptor

createStructType

public RelDataType createStructType(RelDataType[] types,
                                    String[] fieldNames)
Description copied from interface: RelDataTypeFactory
Creates a type which represents a structured collection of fields.

Specified by:
createStructType in interface RelDataTypeFactory
Parameters:
types - types of the fields
fieldNames - names of the fields
Returns:
canonical struct type descriptor

createStructType

public RelDataType createStructType(List<RelDataType> typeList,
                                    List<String> fieldNameList)
Description copied from interface: RelDataTypeFactory
Creates a type which represents a structured collection of fields, given lists of the names and types of the fields.

Specified by:
createStructType in interface RelDataTypeFactory
Parameters:
typeList - types of the fields
fieldNameList - names of the fields
Returns:
canonical struct type descriptor

createStructType

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

Specified by:
createStructType in interface RelDataTypeFactory
Parameters:
fieldInfo - callback for field information
Returns:
canonical struct type descriptor

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
Parameters:
types - input types to be unioned
Returns:
canonical union type descriptor

leastRestrictiveStructuredType

protected RelDataType leastRestrictiveStructuredType(RelDataType[] types)

copySimpleType

private RelDataType copySimpleType(RelDataType type,
                                   boolean nullable)

copyRecordType

private RelDataType copyRecordType(RelRecordType type,
                                   boolean ignoreNullable,
                                   boolean nullable)

copyType

public RelDataType copyType(RelDataType type)
Description copied from interface: RelDataTypeFactory
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.

Specified by:
copyType in interface RelDataTypeFactory
Parameters:
type - input type
Returns:
output type, a new object equivalent to input type

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

canonize

protected RelDataType canonize(RelDataType type)
Registers a type, or returns the existing type if it is already registered.


getFieldArray

private static RelDataTypeField[] getFieldArray(RelDataType[] types)
Returns an array of the fields in an array of types.


getTypeArray

private static RelDataType[] getTypeArray(RelDataType[] types)
Returns an array of all atomic types in an array.


getTypeArray

private static void getTypeArray(RelDataType[] types,
                                 ArrayList<RelDataType> typeList)

addFields

private static void addFields(RelDataType type,
                              ArrayList<RelDataTypeField> fieldList)
Adds all fields in type to fieldList.


isJavaType

public static boolean isJavaType(RelDataType t)

fieldsOf

private RelDataTypeField[] fieldsOf(Class clazz)

createArrayType

public RelDataType createArrayType(RelDataType elementType,
                                   long maxCardinality)
Description copied from interface: RelDataTypeFactory
Creates an array type. Arrays are ordered collections of elements.

Specified by:
createArrayType in interface RelDataTypeFactory
Parameters:
elementType - type of the elements of the array
maxCardinality - maximum array size, or -1 for unlimited
Returns:
canonical array type descriptor

createDecimalProduct

public RelDataType createDecimalProduct(RelDataType type1,
                                        RelDataType type2)
implement RelDataTypeFactory with SQL 2003 compliant behavior. Let p1, s1 be the precision and scale of the first operand Let p2, s2 be the precision and scale of the second operand Let p, s be the precision and scale of the result, Then the result type is a decimal with: p and s are capped at their maximum values

Specified by:
createDecimalProduct in interface RelDataTypeFactory
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.
Reference to SQL:2003 standard:
Part 2 Section 6.26

useDoubleMultiplication

public boolean useDoubleMultiplication(RelDataType type1,
                                       RelDataType type2)
Specified by:
useDoubleMultiplication in interface RelDataTypeFactory
Returns:
whether a decimal multiplication should be implemented by casting arguments to double values.

createDecimalQuotient

public RelDataType createDecimalQuotient(RelDataType type1,
                                         RelDataType type2)
implement RelDataTypeFactory Let p1, s1 be the precision and scale of the first operand Let p2, s2 be the precision and scale of the second operand Let p, s be the precision and scale of the result, Let d be the number of whole digits in the result Then the result type is a decimal with: p and s are capped at their maximum values

Specified by:
createDecimalQuotient in interface RelDataTypeFactory
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.
Reference to SQL:2003 standard:
Part 2 Section 6.26

getDefaultCharset

public Charset getDefaultCharset()
Specified by:
getDefaultCharset in interface RelDataTypeFactory
Returns:
the default Charset for string types