Package org.apache.calcite.sql.type
Class BasicSqlType
- java.lang.Object
-
- org.apache.calcite.rel.type.RelDataTypeImpl
-
- org.apache.calcite.sql.type.AbstractSqlType
-
- org.apache.calcite.sql.type.BasicSqlType
-
- All Implemented Interfaces:
java.io.Serializable
,java.lang.Cloneable
,RelDataType
,RelDataTypeFamily
- Direct Known Subclasses:
SqlTypeFactoryImpl.UnknownSqlType
public class BasicSqlType extends AbstractSqlType
BasicSqlType represents a standard atomic SQL type (excluding interval types).Instances of this class are immutable.
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description private SqlCollation
collation
private int
precision
private int
scale
private RelDataTypeSystem
typeSystem
private SerializableCharset
wrappedCharset
-
Fields inherited from class org.apache.calcite.sql.type.AbstractSqlType
isNullable, typeName
-
Fields inherited from class org.apache.calcite.rel.type.RelDataTypeImpl
digest, fieldList
-
Fields inherited from interface org.apache.calcite.rel.type.RelDataType
PRECISION_NOT_SPECIFIED, SCALE_NOT_SPECIFIED
-
-
Constructor Summary
Constructors Modifier Constructor Description BasicSqlType(RelDataTypeSystem typeSystem, SqlTypeName typeName)
Constructs a type with no parameters.private
BasicSqlType(RelDataTypeSystem typeSystem, SqlTypeName typeName, boolean nullable, int precision, int scale, SqlCollation collation, SerializableCharset wrappedCharset)
Internal constructor.BasicSqlType(RelDataTypeSystem typeSystem, SqlTypeName typeName, int precision)
Constructs a type with precision/length but no scale.BasicSqlType(RelDataTypeSystem typeSystem, SqlTypeName typeName, int precision, int scale)
Constructs a type with precision/length and scale.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected static void
checkPrecScale(SqlTypeName typeName, boolean precisionSpecified, boolean scaleSpecified)
Throws iftypeName
does not allow the given combination of precision and scale.(package private) BasicSqlType
createWithCharsetAndCollation(java.nio.charset.Charset charset, SqlCollation collation)
Constructs a type with charset and collation.(package private) BasicSqlType
createWithNullability(boolean nullable)
Constructs a type with nullablity.protected void
generateTypeString(java.lang.StringBuilder sb, boolean withDetail)
Generates a string representation of this type.java.nio.charset.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.java.lang.Object
getLimit(boolean sign, SqlTypeName.Limit limit, boolean beyond)
Returns a value which is a limit for this type.int
getPrecision()
Gets the JDBC-defined precision for values of this type.int
getScale()
Gets the scale of this type.-
Methods inherited from class org.apache.calcite.sql.type.AbstractSqlType
getFamily, getPrecedenceList, getSqlTypeName, isNullable
-
Methods inherited from class org.apache.calcite.rel.type.RelDataTypeImpl
computeDigest, equals, extra, getComparability, getComponentType, getField, getFieldCount, getFieldList, getFieldNames, getFullTypeString, getIntervalQualifier, getKeyType, getSqlIdentifier, getStructKind, getValueType, hashCode, isDynamicStruct, isStruct, proto, proto, proto, proto, toString
-
-
-
-
Field Detail
-
precision
private final int precision
-
scale
private final int scale
-
typeSystem
private final RelDataTypeSystem typeSystem
-
collation
private final SqlCollation collation
-
wrappedCharset
private final SerializableCharset wrappedCharset
-
-
Constructor Detail
-
BasicSqlType
public BasicSqlType(RelDataTypeSystem typeSystem, SqlTypeName typeName)
Constructs a type with no parameters. This should only be called from a factory method.- Parameters:
typeSystem
- Type systemtypeName
- Type name
-
BasicSqlType
public BasicSqlType(RelDataTypeSystem typeSystem, SqlTypeName typeName, int precision)
Constructs a type with precision/length but no scale.- Parameters:
typeSystem
- Type systemtypeName
- Type nameprecision
- Precision (called length for some types)
-
BasicSqlType
public BasicSqlType(RelDataTypeSystem typeSystem, SqlTypeName typeName, int precision, int scale)
Constructs a type with precision/length and scale.- Parameters:
typeSystem
- Type systemtypeName
- Type nameprecision
- Precision (called length for some types)scale
- Scale
-
BasicSqlType
private BasicSqlType(RelDataTypeSystem typeSystem, SqlTypeName typeName, boolean nullable, int precision, int scale, SqlCollation collation, SerializableCharset wrappedCharset)
Internal constructor.
-
-
Method Detail
-
checkPrecScale
protected static void checkPrecScale(SqlTypeName typeName, boolean precisionSpecified, boolean scaleSpecified)
Throws iftypeName
does not allow the given combination of precision and scale.
-
createWithNullability
BasicSqlType createWithNullability(boolean nullable)
Constructs a type with nullablity.
-
createWithCharsetAndCollation
BasicSqlType createWithCharsetAndCollation(java.nio.charset.Charset charset, SqlCollation collation)
Constructs a type with charset and collation.This must be a character type.
-
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.Returns
RelDataType.PRECISION_NOT_SPECIFIED
(-1) if precision is not applicable for this type.- Specified by:
getPrecision
in interfaceRelDataType
- Overrides:
getPrecision
in classRelDataTypeImpl
- 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:RelDataType
Gets the scale of this type. ReturnsRelDataType.SCALE_NOT_SPECIFIED
(-1) if scale is not valid for this type.- Specified by:
getScale
in interfaceRelDataType
- Overrides:
getScale
in classRelDataTypeImpl
- Returns:
- number of digits of scale
-
getCharset
public java.nio.charset.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 interfaceRelDataType
- Overrides:
getCharset
in classRelDataTypeImpl
- Returns:
- charset of type
-
getCollation
public SqlCollation getCollation()
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 interfaceRelDataType
- Overrides:
getCollation
in classRelDataTypeImpl
- Returns:
- collation of type
-
generateTypeString
protected void generateTypeString(java.lang.StringBuilder sb, boolean withDetail)
Description copied from class:RelDataTypeImpl
Generates a string representation of this type.- Specified by:
generateTypeString
in classRelDataTypeImpl
- Parameters:
sb
- StringBuffer into which to generate the stringwithDetail
- when true, all detail information needed to compute a unique digest (and return from getFullTypeString) should be included;
-
getLimit
public java.lang.Object getLimit(boolean sign, SqlTypeName.Limit limit, boolean beyond)
Returns a value which is a limit for this type.For example,
Limits Datatype sign limit beyond precision scale Returns Integer true true false -1 -1 2147483647 (2 ^ 31 -1 = MAXINT) Integer true true true -1 -1 2147483648 (2 ^ 31 = MAXINT + 1) Integer false true false -1 -1 -2147483648 (-2 ^ 31 = MININT) Boolean true true false -1 -1 TRUE Varchar true true false 10 -1 'ZZZZZZZZZZ' - Parameters:
sign
- If true, returns upper limit, otherwise lower limitlimit
- If true, returns value at or near to overflow; otherwise value at or near to underflowbeyond
- If true, returns the value just beyond the limit, otherwise the value at the limit- Returns:
- Limit value
-
-