Class RelDataTypeFactoryImpl

    • Field Detail

      • CACHE

        private static final com.google.common.cache.LoadingCache<java.lang.Object,​RelDataType> CACHE
        Global cache. Uses soft values to allow GC.
      • CLASS_FAMILIES

        private static final java.util.Map<java.lang.Class,​RelDataTypeFamily> CLASS_FAMILIES
    • Constructor Detail

      • RelDataTypeFactoryImpl

        protected RelDataTypeFactoryImpl​(RelDataTypeSystem typeSystem)
        Creates a type factory.
    • Method Detail

      • keyToType

        private static RelDataType keyToType​(@Nonnull
                                             java.lang.Object k)
      • createJavaType

        public RelDataType createJavaType​(java.lang.Class clazz)
        Description copied from interface: RelDataTypeFactory
        Creates a type that corresponds to a Java class.
        Specified by:
        createJavaType in interface RelDataTypeFactory
        Parameters:
        clazz - the Java class used to define the type
        Returns:
        canonical Java type descriptor
      • createStructType

        public RelDataType createStructType​(java.util.List<RelDataType> typeList,
                                            java.util.List<java.lang.String> fieldNameList)
        Description copied from interface: RelDataTypeFactory
        Creates a type that represents a structured collection of fields. Shorthand for createStructType(StructKind.FULLY_QUALIFIED, typeList, fieldNameList).
        Specified by:
        createStructType in interface RelDataTypeFactory
      • createStructType

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

        private RelDataType createStructType​(StructKind kind,
                                             java.util.List<RelDataType> typeList,
                                             java.util.List<java.lang.String> fieldNameList,
                                             boolean nullable)
      • createStructType

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

        private RelDataType createStructType​(java.util.List<? extends java.util.Map.Entry<java.lang.String,​RelDataType>> fieldList,
                                             boolean nullable)
      • 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 be NUMERIC(12, 2).
        Specified by:
        leastRestrictive in interface RelDataTypeFactory
        Parameters:
        types - input types to be combined using union (not null, not empty)
        Returns:
        canonical union type descriptor
      • leastRestrictiveStructuredType

        protected RelDataType leastRestrictiveStructuredType​(java.util.List<RelDataType> types)
      • copyRecordType

        private RelDataType copyRecordType​(RelRecordType type,
                                           boolean ignoreNullable,
                                           boolean nullable)
      • copyType

        public RelDataType copyType​(RelDataType type)
        Description copied from interface: RelDataTypeFactory
        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.
        Specified by:
        copyType in interface RelDataTypeFactory
        Parameters:
        type - input type
        Returns:
        output type, a new object equivalent to input type
      • 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 interface RelDataTypeFactory
        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
      • canonize

        protected RelDataType canonize​(RelDataType type)
        Registers a type, or returns the existing type if it is already registered.
        Throws:
        java.lang.NullPointerException - if type is null
      • canonize

        protected RelDataType canonize​(StructKind kind,
                                       java.util.List<java.lang.String> names,
                                       java.util.List<RelDataType> types,
                                       boolean nullable)
        Looks up a type using a temporary key, and if not present, creates a permanent key and type.

        This approach allows us to use a cheap temporary key. A permanent key is more expensive, because it must be immutable and not hold references into other data structures.

      • getFieldList

        private static java.util.List<RelDataTypeField> getFieldList​(java.util.List<RelDataType> types)
        Returns a list of the fields in a list of types.
      • getTypeList

        private static void getTypeList​(com.google.common.collect.ImmutableList<RelDataType> inTypes,
                                        java.util.List<RelDataType> flatTypes)
        Returns a list of all atomic types in a list.
      • addFields

        private static void addFields​(RelDataType type,
                                      java.util.List<RelDataTypeField> fieldList)
        Adds all fields in type to fieldList, renumbering the fields (if necessary) to ensure that their index matches their position in the list.
      • isJavaType

        public static boolean isJavaType​(RelDataType t)
      • createDecimalProduct

        public 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.

        Implement RelDataTypeFactory with SQL 2003 compliant behavior. Let p1, s1 be the precision and scale of the first operand Let p2, s2 be the precision and scale of the second operand Let p, s be the precision and scale of the result, Then the result type is a decimal with:

        • p = p1 + p2
        • s = s1 + s2

        p and s are capped at their maximum values

        Specified by:
        createDecimalProduct in interface RelDataTypeFactory
        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.
        See Also:
        SQL:2003 Part 2 Section 6.26
      • createDecimalQuotient

        public RelDataType createDecimalQuotient​(RelDataType type1,
                                                 RelDataType type2)
        Rules:
        • Let p1, s1 be the precision and scale of the first operand
        • Let p2, s2 be the precision and scale of the second operand
        • Let p, s be the precision and scale of the result
        • Let d be the number of whole digits in the result
        • Then the result type is a decimal with:
          • d = p1 - s1 + s2
          • s < max(6, s1 + p2 + 1)
          • p = d + s
        • p and s are capped at their maximum values
        Specified by:
        createDecimalQuotient in interface RelDataTypeFactory
        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.
        See Also:
        SQL:2003 Part 2 Section 6.26
      • getDefaultCharset

        public java.nio.charset.Charset getDefaultCharset()
        Specified by:
        getDefaultCharset in interface RelDataTypeFactory
        Returns:
        the default Charset for string types