Class RelDataTypeImpl
- All Implemented Interfaces:
RelDataType,RelDataTypeFamily
- Direct Known Subclasses:
AbstractSqlType,DynamicRecordType,RelCrossType,RelDataTypeFactoryImpl.JavaType,RelRecordType
RelDataType.
Identity is based upon the digest field, which each derived class
should set during construction.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected @Nullable Stringprotected final @Nullable List<RelDataTypeField>static final StringSuffix for the digests of non-nullable types.Fields inherited from interface org.apache.calcite.rel.type.RelDataType
PRECISION_NOT_SPECIFIED, SCALE_NOT_SPECIFIED -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedDefault constructor, to allow derived classes such asBasicSqlTypeto beSerializable.protectedRelDataTypeImpl(@Nullable List<? extends RelDataTypeField> fieldList) Creates a RelDataTypeImpl. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidComputes the digest field.booleanstatic @Nullable RelDataTypeFieldextra(RelDataType rowType) Returns the "extra" field in a row type whose presence signals that fields will come into existence just by asking for them.protected abstract voidgenerateTypeString(StringBuilder sb, boolean withDetail) Generates a string representation of this type.@Nullable CharsetGets this type's character set, or null if this type cannot carry a character set or has no character set defined.@Nullable SqlCollationGets this type's collation, or null if this type cannot carry a collation or has no collation defined.Returns the category of comparison operators that make sense when applied to values of this type.@Nullable RelDataTypeGets the component type if this type is a collection, otherwise null.Gets a canonical object representing the family of this type.@Nullable RelDataTypeFieldLooks up a field by name.intReturns the number of fields in a struct type.Gets the fields in a struct type.protected @Nullable Map<String,RelDataTypeField> Returns a map from field names to fields.Returns the names of the fields in a struct type.Gets a string representation of this type with full detail such as character set and nullability.@Nullable SqlIntervalQualifierGets this type's interval qualifier, or null if this is not an interval type.@Nullable RelDataTypeGets the key type if this type is a map, otherwise null.Returns the precedence list for this type.intGets the JDBC-defined precision for values of this type.intgetScale()Gets the scale of this type.@Nullable SqlIdentifierGets theSqlIdentifierassociated with this type.Gets theSqlTypeNameof this type.Returns the rule for resolving the fields of a structured type, orStructKind.NONEif this is not a structured type.@Nullable RelDataTypeGets the value type if this type is a map, otherwise null.inthashCode()booleanReturns whether this type has dynamic structure (for "schema-on-read" table).booleanQueries whether this type allows null values.booleanisStruct()Queries whether this is a structured type.static RelProtoDataTypeproto(RelDataType protoType) Returns an implementation ofRelProtoDataTypethat copies a given type using the given type factory.static RelProtoDataTypeproto(SqlTypeName typeName, boolean nullable) Returns aRelProtoDataTypethat will create a typetypeName.static RelProtoDataTypeproto(SqlTypeName typeName, int precision, boolean nullable) Returns aRelProtoDataTypethat will create a typetypeName(precision).static RelProtoDataTypeproto(SqlTypeName typeName, int precision, int scale, boolean nullable) Returns aRelProtoDataTypethat will create a typetypeName(precision, scale).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, waitMethods inherited from interface org.apache.calcite.rel.type.RelDataType
equalsSansFieldNames, equalsSansFieldNamesAndNullability, getMeasureElementType, isMeasure
-
Field Details
-
NON_NULLABLE_SUFFIX
Suffix for the digests of non-nullable types.- See Also:
-
fieldList
-
digest
-
-
Constructor Details
-
RelDataTypeImpl
Creates a RelDataTypeImpl.- Parameters:
fieldList- List of fields
-
RelDataTypeImpl
protected RelDataTypeImpl()Default constructor, to allow derived classes such asBasicSqlTypeto beSerializable.(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 Details
-
getField
public @Nullable RelDataTypeField getField(String fieldName, boolean caseSensitive, boolean elideRecord) Description copied from interface:RelDataTypeLooks up a field by name.NOTE: Be careful choosing the value of
caseSensitive:- If the field name was supplied by an end-user (e.g. as a column alias in SQL), use your session's case-sensitivity setting.
- Only hard-code
trueif you are sure that the field name is internally generated. - Hard-coding
falseis almost certainly wrong.
- Specified by:
getFieldin interfaceRelDataType- Parameters:
fieldName- Name of field to findcaseSensitive- Whether match is case-sensitiveelideRecord- Whether to find fields nested within records- Returns:
- named field, or null if not found
-
getFieldMap
Returns a map from field names to fields.Matching is case-sensitive.
If several fields have the same name, the map contains the first.
A
dynamic star fieldis indexed under its own name and "" (the empty string).If the map is null, the type must do lookup the long way.
-
getFieldList
Description copied from interface:RelDataTypeGets the fields in a struct type. The field count is equal to the size of the returned list.- Specified by:
getFieldListin interfaceRelDataType- Returns:
- read-only list of fields
-
getFieldNames
Description copied from interface:RelDataTypeReturns the names of the fields in a struct type. The field count is equal to the size of the returned list.- Specified by:
getFieldNamesin interfaceRelDataType- Returns:
- read-only list of field names
-
getFieldCount
public int getFieldCount()Description copied from interface:RelDataTypeReturns the number of fields in a struct type.This method is equivalent to
.RelDataType.getFieldList().size()- Specified by:
getFieldCountin interfaceRelDataType
-
getStructKind
Description copied from interface:RelDataTypeReturns the rule for resolving the fields of a structured type, orStructKind.NONEif this is not a structured type.- Specified by:
getStructKindin interfaceRelDataType- Returns:
- the StructKind that determines how this type's fields are resolved
-
getComponentType
Description copied from interface:RelDataTypeGets the component type if this type is a collection, otherwise null.- Specified by:
getComponentTypein interfaceRelDataType- Returns:
- canonical type descriptor for components
-
getKeyType
Description copied from interface:RelDataTypeGets the key type if this type is a map, otherwise null.- Specified by:
getKeyTypein interfaceRelDataType- Returns:
- canonical type descriptor for key
-
getValueType
Description copied from interface:RelDataTypeGets the value type if this type is a map, otherwise null.- Specified by:
getValueTypein interfaceRelDataType- Returns:
- canonical type descriptor for value
-
isStruct
public boolean isStruct()Description copied from interface:RelDataTypeQueries whether this is a structured type.- Specified by:
isStructin interfaceRelDataType- Returns:
- whether this type has fields; examples include rows and user-defined structured types in SQL, and classes in Java
-
equals
-
hashCode
public int hashCode() -
getFullTypeString
Description copied from interface:RelDataTypeGets 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:
getFullTypeStringin interfaceRelDataType- Returns:
- full type string
-
isNullable
public boolean isNullable()Description copied from interface:RelDataTypeQueries whether this type allows null values.- Specified by:
isNullablein interfaceRelDataType- Returns:
- whether type allows null values
-
getCharset
Description copied from interface:RelDataTypeGets this type's character set, or null if this type cannot carry a character set or has no character set defined.- Specified by:
getCharsetin interfaceRelDataType- Returns:
- charset of type
-
getCollation
Description copied from interface:RelDataTypeGets this type's collation, or null if this type cannot carry a collation or has no collation defined.- Specified by:
getCollationin interfaceRelDataType- Returns:
- collation of type
-
getIntervalQualifier
Description copied from interface:RelDataTypeGets this type's interval qualifier, or null if this is not an interval type.- Specified by:
getIntervalQualifierin interfaceRelDataType- Returns:
- interval qualifier
-
getPrecision
public int getPrecision()Description copied from interface:RelDataTypeGets 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.Returns
RelDataType.PRECISION_NOT_SPECIFIED(-1) if precision is not applicable for this type.- Specified by:
getPrecisionin interfaceRelDataType- 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; -1 if precision is not valid for this type
-
getScale
public int getScale()Description copied from interface:RelDataTypeGets the scale of this type. ReturnsRelDataType.SCALE_NOT_SPECIFIED(-1) if scale is not valid for this type.- Specified by:
getScalein interfaceRelDataType- Returns:
- number of digits of scale
-
getSqlTypeName
Gets theSqlTypeNameof this type. Sub-classes must override the method to ensure the resulting value is non-nullable.- Specified by:
getSqlTypeNamein interfaceRelDataType- Returns:
- SqlTypeName, never null
-
getSqlIdentifier
Description copied from interface:RelDataTypeGets theSqlIdentifierassociated with this type. For a predefined type, this is a simple identifier based onRelDataType.getSqlTypeName(). For a user-defined type, this is a compound identifier which uniquely names the type.- Specified by:
getSqlIdentifierin interfaceRelDataType- Returns:
- SqlIdentifier, or null if this is not an SQL type
-
getFamily
Description copied from interface:RelDataTypeGets 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:
getFamilyin interfaceRelDataType- Returns:
- canonical object representing type family, never null
-
generateTypeString
Generates a string representation of this type.- Parameters:
sb- StringBuilder into which to generate the stringwithDetail- when true, all detail information needed to compute a unique digest (and return from getFullTypeString) should be included;
-
computeDigest
protected void computeDigest(@UnknownInitialization RelDataTypeImpl this) Computes the digest field. This should be called in every non-abstract subclass constructor once the type is fully defined. -
toString
Description copied from interface:RelDataTypeGets a string representation of this type without detail such as character set and nullability.- Specified by:
toStringin interfaceRelDataType- Overrides:
toStringin classObject- Returns:
- abbreviated type string
-
getPrecedenceList
Description copied from interface:RelDataTypeReturns the precedence list for this type.- Specified by:
getPrecedenceListin interfaceRelDataType
-
getComparability
Description copied from interface:RelDataTypeReturns the category of comparison operators that make sense when applied to values of this type.- Specified by:
getComparabilityin interfaceRelDataType
-
proto
Returns an implementation ofRelProtoDataTypethat copies a given type using the given type factory. -
proto
Returns aRelProtoDataTypethat will create a typetypeName.For example,
proto(SqlTypeName.DATE), falsewill createDATE NOT NULL.- Parameters:
typeName- Type namenullable- Whether nullable- Returns:
- Proto data type
-
proto
Returns aRelProtoDataTypethat will create a typetypeName(precision).For example,
proto(SqlTypeName.VARCHAR, 100, false)will createVARCHAR(100) NOT NULL.- Parameters:
typeName- Type nameprecision- Precisionnullable- Whether nullable- Returns:
- Proto data type
-
proto
public static RelProtoDataType proto(SqlTypeName typeName, int precision, int scale, boolean nullable) Returns aRelProtoDataTypethat will create a typetypeName(precision, scale).For example,
proto(SqlTypeName.DECIMAL, 7, 2, false)will createDECIMAL(7, 2) NOT NULL.- Parameters:
typeName- Type nameprecision- Precisionscale- Scalenullable- Whether nullable- Returns:
- Proto data type
-
extra
Returns the "extra" field in a row type whose presence signals that fields will come into existence just by asking for them.- Parameters:
rowType- Row type- Returns:
- The "extra" field, or null
-
isDynamicStruct
public boolean isDynamicStruct()Description copied from interface:RelDataTypeReturns whether this type has dynamic structure (for "schema-on-read" table).- Specified by:
isDynamicStructin interfaceRelDataType
-