org.eigenbase.reltype
Class RelDataTypeImpl

java.lang.Object
  extended by org.eigenbase.reltype.RelDataTypeImpl
All Implemented Interfaces:
RelDataType, RelDataTypeFamily
Direct Known Subclasses:
AbstractSqlType, OJTypeFactoryImpl.OJScalarType, RelCrossType, RelDataTypeFactoryImpl.JavaType, RelRecordType

public abstract class RelDataTypeImpl
extends Object
implements RelDataType, RelDataTypeFamily

RelDataTypeImpl is an abstract base for implementations of RelDataType.

Identity is based upon the digest field, which each derived class should set during construction.

Version:
$Id: //open/dev/farrago/src/org/eigenbase/reltype/RelDataTypeImpl.java#19 $
Author:
jhyde

Field Summary
protected  String digest
           
protected  List<RelDataTypeField> fieldList
           
protected  RelDataTypeField[] fields
           
 
Constructor Summary
protected RelDataTypeImpl()
          Default constructor, to allow derived classes such as BasicSqlType to be Serializable.
protected RelDataTypeImpl(RelDataTypeField[] fields)
          Creates a RelDataTypeImpl.
 
Method Summary
protected  void computeDigest()
          Computes the digest field.
 boolean equals(Object obj)
           
protected abstract  void generateTypeString(StringBuilder sb, boolean withDetail)
          Generates a string representation of this type.
 Charset getCharset()
          Gets this type's character set, or null if this type cannot carry a character set or has no character set defined.
 SqlCollation getCollation()
          Gets this type's collation, or null if this type cannot carry a collation or has no collation defined.
 RelDataTypeComparability getComparability()
           
 RelDataType getComponentType()
          Gets the component type if this type is a collection, otherwise null.
 RelDataTypeFamily getFamily()
          Gets a canonical object representing the family of this type.
 RelDataTypeField getField(String fieldName)
          Looks up a field by name.
 int getFieldCount()
          Returns the number of fields in a struct type.
 List<RelDataTypeField> getFieldList()
          Gets the fields in a struct type.
 int getFieldOrdinal(String fieldName)
          Looks up the ordinal of a field by name.
 RelDataTypeField[] getFields()
          Gets the fields in a struct type.
 String getFullTypeString()
          Gets a string representation of this type with full detail such as character set and nullability.
 SqlIntervalQualifier getIntervalQualifier()
          Gets this type's interval qualifier, or null if this is not an interval type.
 RelDataTypePrecedenceList getPrecedenceList()
           
 int getPrecision()
          Gets the JDBC-defined precision for values of this type.
 int getScale()
          Gets the scale of this type.
 SqlIdentifier getSqlIdentifier()
          Gets the SqlIdentifier associated with this type.
 SqlTypeName getSqlTypeName()
          Gets the SqlTypeName of this type.
 int hashCode()
           
 boolean isNullable()
          Queries whether this type allows null values.
 boolean isStruct()
          Queries whether this is a structured type.
 String toString()
          Gets a string representation of this type without detail such as character set and nullability.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

fields

protected RelDataTypeField[] fields

fieldList

protected List<RelDataTypeField> fieldList

digest

protected String digest
Constructor Detail

RelDataTypeImpl

protected RelDataTypeImpl(RelDataTypeField[] fields)
Creates a RelDataTypeImpl.

Parameters:
fields - Array of fields

RelDataTypeImpl

protected RelDataTypeImpl()
Default constructor, to allow derived classes such as BasicSqlType to be Serializable.

(The serialization specification says that a class can be serializable even if its base class is not serializable, provided that the base class has a public or protected zero-args constructor.)

Method Detail

getField

public RelDataTypeField getField(String fieldName)
Description copied from interface: RelDataType
Looks up a field by name.

Specified by:
getField in interface RelDataType
Parameters:
fieldName - name of field to find
Returns:
named field, or null if not found

getFieldOrdinal

public int getFieldOrdinal(String fieldName)
Description copied from interface: RelDataType
Looks up the ordinal of a field by name.

Specified by:
getFieldOrdinal in interface RelDataType
Parameters:
fieldName - name of field to find
Returns:
0-based ordinal of named field, or -1 if not found

getFieldList

public List<RelDataTypeField> getFieldList()
Description copied from interface: RelDataType
Gets the fields in a struct type. The field count is equal to the size of the returned list.

Specified by:
getFieldList in interface RelDataType
Returns:
read-only list of fields

getFields

public RelDataTypeField[] getFields()
Description copied from interface: RelDataType
Gets the fields in a struct type. The field count is equal to the length of the returned array.

NOTE jvs 17-Dec-2004: this method will become deprecated once we move to Java generics, and eventually eliminated

Specified by:
getFields in interface RelDataType
Returns:
array of fields

getFieldCount

public int getFieldCount()
Description copied from interface: RelDataType
Returns the number of fields in a struct type.

This method is equivalent to RelDataType.getFieldList() ().size().

Specified by:
getFieldCount in interface RelDataType

getComponentType

public RelDataType getComponentType()
Description copied from interface: RelDataType
Gets the component type if this type is a collection, otherwise null.

Specified by:
getComponentType in interface RelDataType
Returns:
canonical type descriptor for components

isStruct

public boolean isStruct()
Description copied from interface: RelDataType
Queries whether this is a structured type.

Specified by:
isStruct in interface RelDataType
Returns:
whether this type has fields; examples include rows and user-defined structured types in SQL, and classes in Java

equals

public boolean equals(Object obj)
Overrides:
equals in class Object

hashCode

public int hashCode()
Overrides:
hashCode in class Object

getFullTypeString

public String getFullTypeString()
Description copied from interface: RelDataType
Gets a string representation of this type with full detail such as character set and nullability. The string must serve as a "digest" for this type, meaning two types can be considered identical iff their digests are equal.

Specified by:
getFullTypeString in interface RelDataType
Returns:
full type string

isNullable

public boolean isNullable()
Description copied from interface: RelDataType
Queries whether this type allows null values.

Specified by:
isNullable in interface RelDataType
Returns:
whether type allows null values

getCharset

public Charset getCharset()
Description copied from interface: RelDataType
Gets this type's character set, or null if this type cannot carry a character set or has no character set defined.

Specified by:
getCharset in interface RelDataType
Returns:
charset of type

getCollation

public SqlCollation getCollation()
                          throws RuntimeException
Description copied from interface: RelDataType
Gets this type's collation, or null if this type cannot carry a collation or has no collation defined.

Specified by:
getCollation in interface RelDataType
Returns:
collation of type
Throws:
RuntimeException

getIntervalQualifier

public SqlIntervalQualifier getIntervalQualifier()
Description copied from interface: RelDataType
Gets this type's interval qualifier, or null if this is not an interval type.

Specified by:
getIntervalQualifier in interface RelDataType
Returns:
interval qualifier

getPrecision

public int getPrecision()
Description copied from interface: RelDataType
Gets the JDBC-defined precision for values of this type. Note that this is not always the same as the user-specified precision. For example, the type INTEGER has no user-specified precision, but this method returns 10 for an INTEGER type.

Specified by:
getPrecision in interface RelDataType
Returns:
number of decimal digits for exact numeric types; number of decimal digits in mantissa for approximate numeric types; number of decimal digits for fractional seconds of datetime types; length in characters for character types; length in bytes for binary types; length in bits for bit types; 1 for BOOLEAN

getScale

public int getScale()
Description copied from interface: RelDataType
Gets the scale of this type.

Specified by:
getScale in interface RelDataType
Returns:
number of digits of scale

getSqlTypeName

public SqlTypeName getSqlTypeName()
Description copied from interface: RelDataType
Gets the SqlTypeName of this type.

Specified by:
getSqlTypeName in interface RelDataType
Returns:
SqlTypeName, or null if this is not an SQL predefined type

getSqlIdentifier

public SqlIdentifier getSqlIdentifier()
Description copied from interface: RelDataType
Gets the SqlIdentifier associated with this type. For a predefined type, this is a simple identifier based on RelDataType.getSqlTypeName(). For a user-defined type, this is a compound identifier which uniquely names the type.

Specified by:
getSqlIdentifier in interface RelDataType
Returns:
SqlIdentifier, or null if this is not an SQL type

getFamily

public RelDataTypeFamily getFamily()
Description copied from interface: RelDataType
Gets a canonical object representing the family of this type. Two values can be compared if and only if their types are in the same family.

Specified by:
getFamily in interface RelDataType
Returns:
canonical object representing type family

generateTypeString

protected abstract void generateTypeString(StringBuilder sb,
                                           boolean withDetail)
Generates a string representation of this type.

Parameters:
sb - StringBuffer into which to generate the string
withDetail - when true, all detail information needed to compute a unique digest (and return from getFullTypeString) should be included;

computeDigest

protected void computeDigest()
Computes the digest field. This should be called in every non-abstract subclass constructor once the type is fully defined.


toString

public String toString()
Description copied from interface: RelDataType
Gets a string representation of this type without detail such as character set and nullability.

Specified by:
toString in interface RelDataType
Overrides:
toString in class Object
Returns:
abbreviated type string

getPrecedenceList

public RelDataTypePrecedenceList getPrecedenceList()
Specified by:
getPrecedenceList in interface RelDataType
Returns:
precedence list for this type

getComparability

public RelDataTypeComparability getComparability()
Specified by:
getComparability in interface RelDataType
Returns:
the category of comparison operators which make sense when applied to values of this type