Interface RelDataTypeFactory

  • All Known Subinterfaces:
    JavaTypeFactory
    All Known Implementing Classes:
    JavaTypeFactoryExtImpl, JavaTypeFactoryImpl, RelDataTypeFactoryImpl, SqlTypeFactoryImpl

    public interface RelDataTypeFactory
    RelDataTypeFactory is a factory for datatype descriptors. It defines methods for instantiating and combining SQL, Java, and collection types. The factory also provides methods for return type inference for arithmetic in cases where SQL 2003 is implementation defined or impractical.

    This interface is an example of the abstract factory pattern. Any implementation of RelDataTypeFactory must ensure that type objects are canonical: two types are equal if and only if they are represented by the same Java object. This reduces memory consumption and comparison cost.

    • Method Detail

      • getTypeSystem

        RelDataTypeSystem getTypeSystem()
        Returns the type system.
        Returns:
        Type system
      • createJavaType

        RelDataType createJavaType​(java.lang.Class clazz)
        Creates a type that corresponds to a Java class.
        Parameters:
        clazz - the Java class used to define the type
        Returns:
        canonical Java type descriptor
      • createJoinType

        RelDataType createJoinType​(RelDataType... types)
        Creates a cartesian product type.
        Parameters:
        types - array of types to be joined
        Returns:
        canonical join type descriptor
      • createStructType

        RelDataType createStructType​(StructKind kind,
                                     java.util.List<RelDataType> typeList,
                                     java.util.List<java.lang.String> fieldNameList)
        Creates a type that represents a structured collection of fields, given lists of the names and types of the fields.
        Parameters:
        kind - Name resolution policy
        typeList - types of the fields
        fieldNameList - names of the fields
        Returns:
        canonical struct type descriptor
      • createStructType

        RelDataType createStructType​(java.util.List<RelDataType> typeList,
                                     java.util.List<java.lang.String> fieldNameList)
        Creates a type that represents a structured collection of fields. Shorthand for createStructType(StructKind.FULLY_QUALIFIED, typeList, fieldNameList).
      • createStructType

        @Deprecated
        RelDataType createStructType​(RelDataTypeFactory.FieldInfo fieldInfo)
        Deprecated.
        Creates a type that represents a structured collection of fields, obtaining the field information via a callback.
        Parameters:
        fieldInfo - callback for field information
        Returns:
        canonical struct type descriptor
      • createStructType

        RelDataType createStructType​(java.util.List<? extends java.util.Map.Entry<java.lang.String,​RelDataType>> fieldList)
        Creates a type that represents a structured collection of fieldList, obtaining the field information from a list of (name, type) pairs.
        Parameters:
        fieldList - List of (name, type) pairs
        Returns:
        canonical struct type descriptor
      • createArrayType

        RelDataType createArrayType​(RelDataType elementType,
                                    long maxCardinality)
        Creates an array type. Arrays are ordered collections of elements.
        Parameters:
        elementType - type of the elements of the array
        maxCardinality - maximum array size, or -1 for unlimited
        Returns:
        canonical array type descriptor
      • createMapType

        RelDataType createMapType​(RelDataType keyType,
                                  RelDataType valueType)
        Creates a map type. Maps are unordered collections of key/value pairs.
        Parameters:
        keyType - type of the keys of the map
        valueType - type of the values of the map
        Returns:
        canonical map type descriptor
      • createMultisetType

        RelDataType createMultisetType​(RelDataType elementType,
                                       long maxCardinality)
        Creates a multiset type. Multisets are unordered collections of elements.
        Parameters:
        elementType - type of the elements of the multiset
        maxCardinality - maximum collection size, or -1 for unlimited
        Returns:
        canonical multiset type descriptor
      • copyType

        RelDataType copyType​(RelDataType type)
        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.
        Parameters:
        type - input type
        Returns:
        output type, a new object equivalent to input type
      • createTypeWithNullability

        RelDataType createTypeWithNullability​(RelDataType type,
                                              boolean nullable)
        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.
        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
        Throws:
        java.lang.NullPointerException - if type is null
      • createTypeWithCharsetAndCollation

        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. For types without a concept of charset or collation this function must throw an error.
        Parameters:
        type - input type
        charset - charset to assign
        collation - collation to assign
        Returns:
        output type, same as input type except with specified charset and collation
      • getDefaultCharset

        java.nio.charset.Charset getDefaultCharset()
        Returns:
        the default Charset for string types
      • leastRestrictive

        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. 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 be NUMERIC(12, 2).
        Parameters:
        types - input types to be combined using union (not null, not empty)
        Returns:
        canonical union type descriptor
      • createSqlType

        RelDataType createSqlType​(SqlTypeName typeName)
        Creates a SQL type with no precision or scale.
        Parameters:
        typeName - Name of the type, for example SqlTypeName.BOOLEAN, never null
        Returns:
        canonical type descriptor
      • createUnknownType

        RelDataType createUnknownType()
        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
      • createSqlType

        RelDataType createSqlType​(SqlTypeName typeName,
                                  int precision)
        Creates a SQL type with length (precision) but no scale.
        Parameters:
        typeName - Name of the type, for example SqlTypeName.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 or RelDataType.PRECISION_NOT_SPECIFIED.
        Returns:
        canonical type descriptor
      • createSqlType

        RelDataType createSqlType​(SqlTypeName typeName,
                                  int precision,
                                  int scale)
        Creates a SQL type with precision and scale.
        Parameters:
        typeName - Name of the type, for example SqlTypeName.DECIMAL. Never null.
        precision - Precision of the value. Must be non-negative or RelDataType.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
      • createSqlIntervalType

        RelDataType createSqlIntervalType​(SqlIntervalQualifier intervalQualifier)
        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
      • createDecimalProduct

        RelDataType createDecimalProduct​(RelDataType type1,
                                         RelDataType type2)
        Infers the return type of a decimal multiplication. Decimal multiplication involves at least one decimal operand and requires both operands to have exact numeric types.
        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.
      • useDoubleMultiplication

        boolean useDoubleMultiplication​(RelDataType type1,
                                        RelDataType type2)
        Returns whether a decimal multiplication should be implemented by casting arguments to double values.

        Pre-condition: createDecimalProduct(type1, type2) != null

      • createDecimalQuotient

        RelDataType createDecimalQuotient​(RelDataType type1,
                                          RelDataType type2)
        Infers the return type of a decimal division. Decimal division involves at least one decimal operand and requires both operands to have exact numeric types.
        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.