Package org.apache.calcite.sql.type
Class SqlTypeFactoryImpl
- java.lang.Object
-
- org.apache.calcite.rel.type.RelDataTypeFactoryImpl
-
- org.apache.calcite.sql.type.SqlTypeFactoryImpl
-
- All Implemented Interfaces:
RelDataTypeFactory
- Direct Known Subclasses:
JavaTypeFactoryImpl
public class SqlTypeFactoryImpl extends RelDataTypeFactoryImpl
SqlTypeFactoryImpl provides a default implementation ofRelDataTypeFactory
which supports SQL types.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
SqlTypeFactoryImpl.UnknownSqlType
The unknown type.-
Nested classes/interfaces inherited from class org.apache.calcite.rel.type.RelDataTypeFactoryImpl
RelDataTypeFactoryImpl.JavaType
-
Nested classes/interfaces inherited from interface org.apache.calcite.rel.type.RelDataTypeFactory
RelDataTypeFactory.Builder, RelDataTypeFactory.FieldInfo, RelDataTypeFactory.FieldInfoBuilder
-
-
Field Summary
-
Fields inherited from class org.apache.calcite.rel.type.RelDataTypeFactoryImpl
typeSystem
-
-
Constructor Summary
Constructors Constructor Description SqlTypeFactoryImpl(RelDataTypeSystem typeSystem)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private void
assertBasic(SqlTypeName typeName)
protected RelDataType
canonize(RelDataType type)
Registers a type, or returns the existing type if it is already registered.private RelDataType
copyArrayType(RelDataType type, boolean nullable)
private RelDataType
copyIntervalType(RelDataType type, boolean nullable)
private RelDataType
copyMapType(RelDataType type, boolean nullable)
private RelDataType
copyMultisetType(RelDataType type, boolean nullable)
private RelDataType
copyObjectType(RelDataType type, boolean nullable)
RelDataType
createArrayType(RelDataType elementType, long maxCardinality)
Creates an array type.private RelDataType
createDoublePrecisionType()
RelDataType
createMapType(RelDataType keyType, RelDataType valueType)
Creates a map type.RelDataType
createMultisetType(RelDataType type, 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
createTypeWithCharsetAndCollation(RelDataType type, java.nio.charset.Charset charset, SqlCollation collation)
Creates a type that is the same as another type but with possibly different charset or collation.RelDataType
createTypeWithNullability(RelDataType type, boolean nullable)
Creates a type that is the same as another type but with possibly different nullability.RelDataType
createUnknownType()
Creates a SQL type that represents the "unknown" type.RelDataType
leastRestrictive(java.util.List<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.private RelDataType
leastRestrictiveByCast(java.util.List<RelDataType> types)
private RelDataType
leastRestrictiveSqlType(java.util.List<RelDataType> types)
-
Methods inherited from class org.apache.calcite.rel.type.RelDataTypeFactoryImpl
builder, canonize, copyType, createDecimalProduct, createDecimalQuotient, createJavaType, createJoinType, createStructType, createStructType, createStructType, createStructType, getDefaultCharset, getTypeSystem, isJavaType, leastRestrictiveStructuredType, useDoubleMultiplication
-
-
-
-
Constructor Detail
-
SqlTypeFactoryImpl
public SqlTypeFactoryImpl(RelDataTypeSystem typeSystem)
-
-
Method Detail
-
createSqlType
public RelDataType createSqlType(SqlTypeName typeName)
Description copied from interface:RelDataTypeFactory
Creates a SQL type with no precision or scale.- Parameters:
typeName
- Name of the type, for exampleSqlTypeName.BOOLEAN
, never null- Returns:
- canonical type descriptor
-
createSqlType
public RelDataType createSqlType(SqlTypeName typeName, int precision)
Description copied from interface:RelDataTypeFactory
Creates a SQL type with length (precision) but no scale.- Parameters:
typeName
- Name of the type, for exampleSqlTypeName.VARCHAR
. Never null.precision
- Maximum length of the value (non-numeric types) or the precision of the value (numeric/datetime types). Must be non-negative orRelDataType.PRECISION_NOT_SPECIFIED
.- Returns:
- canonical type descriptor
-
createSqlType
public RelDataType createSqlType(SqlTypeName typeName, int precision, int scale)
Description copied from interface:RelDataTypeFactory
Creates a SQL type with precision and scale.- Parameters:
typeName
- Name of the type, for exampleSqlTypeName.DECIMAL
. Never null.precision
- Precision of the value. Must be non-negative orRelDataType.PRECISION_NOT_SPECIFIED
.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
-
createUnknownType
public RelDataType createUnknownType()
Description copied from interface:RelDataTypeFactory
Creates a SQL type that represents the "unknown" type. It is only equal to itself, and is distinct from the NULL type.- Returns:
- unknown type
-
createMultisetType
public RelDataType createMultisetType(RelDataType type, long maxCardinality)
Description copied from interface:RelDataTypeFactory
Creates a multiset type. Multisets are unordered collections of elements.- Parameters:
type
- type of the elements of the multisetmaxCardinality
- maximum collection size, or -1 for unlimited- Returns:
- canonical multiset type descriptor
-
createArrayType
public RelDataType createArrayType(RelDataType elementType, long maxCardinality)
Description copied from interface:RelDataTypeFactory
Creates an array type. Arrays are ordered collections of elements.- Parameters:
elementType
- type of the elements of the arraymaxCardinality
- maximum array size, or -1 for unlimited- Returns:
- canonical array type descriptor
-
createMapType
public RelDataType createMapType(RelDataType keyType, RelDataType valueType)
Description copied from interface:RelDataTypeFactory
Creates a map type. Maps are unordered collections of key/value pairs.- Parameters:
keyType
- type of the keys of the mapvalueType
- type of the values of the map- Returns:
- canonical map type descriptor
-
createSqlIntervalType
public RelDataType createSqlIntervalType(SqlIntervalQualifier intervalQualifier)
Description copied from interface:RelDataTypeFactory
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
-
createTypeWithCharsetAndCollation
public RelDataType createTypeWithCharsetAndCollation(RelDataType type, java.nio.charset.Charset charset, SqlCollation collation)
Description copied from interface:RelDataTypeFactory
Creates a type that is the same as another type but with possibly different charset or collation. For types without a concept of charset or collation this function must throw an error.- Parameters:
type
- input typecharset
- charset to assigncollation
- collation to assign- Returns:
- output type, same as input type except with specified charset and collation
-
leastRestrictive
public RelDataType leastRestrictive(java.util.List<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 that is less restrictive than any of the input types, e.g.leastRestrictive(INT, NUMERIC(3, 2))
could beNUMERIC(12, 2)
.- Specified by:
leastRestrictive
in interfaceRelDataTypeFactory
- Overrides:
leastRestrictive
in classRelDataTypeFactoryImpl
- Parameters:
types
- input types to be combined using union (not null, not empty)- Returns:
- canonical union type descriptor
-
leastRestrictiveByCast
private RelDataType leastRestrictiveByCast(java.util.List<RelDataType> types)
-
createTypeWithNullability
public RelDataType createTypeWithNullability(RelDataType type, boolean nullable)
Description copied from interface:RelDataTypeFactory
Creates a type that 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 interfaceRelDataTypeFactory
- Overrides:
createTypeWithNullability
in classRelDataTypeFactoryImpl
- Parameters:
type
- input typenullable
- true to request a nullable type; false to request a NOT NULL type- Returns:
- output type, same as input type except with specified nullability
-
assertBasic
private void assertBasic(SqlTypeName typeName)
-
leastRestrictiveSqlType
private RelDataType leastRestrictiveSqlType(java.util.List<RelDataType> types)
-
createDoublePrecisionType
private RelDataType createDoublePrecisionType()
-
copyMultisetType
private RelDataType copyMultisetType(RelDataType type, boolean nullable)
-
copyIntervalType
private RelDataType copyIntervalType(RelDataType type, boolean nullable)
-
copyObjectType
private RelDataType copyObjectType(RelDataType type, boolean nullable)
-
copyArrayType
private RelDataType copyArrayType(RelDataType type, boolean nullable)
-
copyMapType
private RelDataType copyMapType(RelDataType type, boolean nullable)
-
canonize
protected RelDataType canonize(RelDataType type)
Description copied from class:RelDataTypeFactoryImpl
Registers a type, or returns the existing type if it is already registered.- Overrides:
canonize
in classRelDataTypeFactoryImpl
-
-