Object

org.apache.spark.sql.catalyst.analysis

TypeCoercion

Related Doc: package analysis

Permalink

object TypeCoercion

A collection of Rule that can be used to coerce differing types that participate in operations into compatible ones.

Notes about type widening / tightest common types: Broadly, there are two cases when we need to widen data types (e.g. union, binary comparison). In case 1, we are looking for a common data type for two or more data types, and in this case no loss of precision is allowed. Examples include type inference in JSON (e.g. what's the column's data type if one row is an integer while the other row is a long?). In case 2, we are looking for a widened data type with some acceptable loss of precision (e.g. there is no common type for double and decimal because double's range is larger than decimal, and yet decimal is more precise than double, but in union we would cast the decimal into double).

Linear Supertypes
AnyRef, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. TypeCoercion
  2. AnyRef
  3. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Value Members

  1. final def !=(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  4. object BooleanEquality extends Rule[LogicalPlan]

    Permalink

    Changes numeric values to booleans so that expressions like true = 1 can be evaluated.

  5. object CaseWhenCoercion extends Rule[LogicalPlan]

    Permalink

    Coerces the type of different branches of a CASE WHEN statement to a common type.

  6. object DateTimeOperations extends Rule[LogicalPlan]

    Permalink

    Turns Add/Subtract of DateType/TimestampType/StringType and CalendarIntervalType to TimeAdd/TimeSub

  7. object Division extends Rule[LogicalPlan]

    Permalink

    Hive only performs integral division with the DIV operator.

    Hive only performs integral division with the DIV operator. The arguments to / are always converted to fractional types.

  8. object FunctionArgumentConversion extends Rule[LogicalPlan]

    Permalink

    This ensure that the types for various functions are as expected.

  9. object IfCoercion extends Rule[LogicalPlan]

    Permalink

    Coerces the type of different branches of If statement to a common type.

  10. object ImplicitTypeCasts extends Rule[LogicalPlan]

    Permalink

    Casts types according to the expected input types for Expressions.

  11. object InConversion extends Rule[LogicalPlan]

    Permalink

    Handles type coercion for both IN expression with subquery and IN expressions without subquery.

    Handles type coercion for both IN expression with subquery and IN expressions without subquery. 1. In the first case, find the common type by comparing the left hand side (LHS) expression types against corresponding right hand side (RHS) expression derived from the subquery expression's plan output. Inject appropriate casts in the LHS and RHS side of IN expression.

    2. In the second case, convert the value and in list expressions to the common operator type by looking at all the argument types and finding the closest one that all the arguments can be cast to. When no common operator type is found the original expression will be returned and an Analysis Exception will be raised at the type checking phase.

  12. object PromoteStrings extends Rule[LogicalPlan]

    Permalink

    Promotes strings that appear in arithmetic expressions.

  13. object PropagateTypes extends Rule[LogicalPlan]

    Permalink

    Applies any changes to AttributeReference data types that are made by other rules to instances higher in the query tree.

  14. object WidenSetOperationTypes extends Rule[LogicalPlan]

    Permalink

    Widens numeric types and converts strings to numbers when appropriate.

    Widens numeric types and converts strings to numbers when appropriate.

    Loosely based on rules from "Hadoop: The Definitive Guide" 2nd edition, by Tom White

    The implicit conversion rules can be summarized as follows:

    • Any integral numeric type can be implicitly converted to a wider type.
    • All the integral numeric types, FLOAT, and (perhaps surprisingly) STRING can be implicitly converted to DOUBLE.
    • TINYINT, SMALLINT, and INT can all be converted to FLOAT.
    • BOOLEAN types cannot be converted to any other type.
    • Any integral numeric type can be implicitly converted to decimal type.
    • two different decimal types will be converted into a wider decimal type for both of them.
    • decimal type will be converted into double if there float or double together with it.

    Additionally, all types when UNION-ed with strings will be promoted to strings. Other string conversions are handled by PromoteStrings.

    Widening types might result in loss of precision in the following cases: - IntegerType to FloatType - LongType to FloatType - LongType to DoubleType - DecimalType to Double

    This rule is only applied to Union/Except/Intersect

  15. final def asInstanceOf[T0]: T0

    Permalink
    Definition Classes
    Any
  16. def clone(): AnyRef

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  17. final def eq(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  18. def equals(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  19. def finalize(): Unit

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  20. val findCommonTypeForBinaryComparison: (DataType, DataType) ⇒ Option[DataType]

    Permalink

    This function determines the target type of a comparison operator when one operand is a String and the other is not.

    This function determines the target type of a comparison operator when one operand is a String and the other is not. It also handles when one op is a Date and the other is a Timestamp by making the target type to be String.

  21. val findTightestCommonType: (DataType, DataType) ⇒ Option[DataType]

    Permalink

    Case 1 type widening (see the classdoc comment above for TypeCoercion).

    Case 1 type widening (see the classdoc comment above for TypeCoercion).

    Find the tightest common type of two types that might be used in a binary expression. This handles all numeric types except fixed-precision decimals interacting with each other or with primitive types, because in that case the precision and scale of the result depends on the operation. Those rules are implemented in DecimalPrecision.

  22. def findWiderTypeWithoutStringPromotion(types: Seq[DataType]): Option[DataType]

    Permalink
  23. final def getClass(): Class[_]

    Permalink
    Definition Classes
    AnyRef → Any
  24. def hashCode(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  25. final def isInstanceOf[T0]: Boolean

    Permalink
    Definition Classes
    Any
  26. final def ne(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  27. final def notify(): Unit

    Permalink
    Definition Classes
    AnyRef
  28. final def notifyAll(): Unit

    Permalink
    Definition Classes
    AnyRef
  29. val numericPrecedence: IndexedSeq[NumericType with Product with Serializable]

    Permalink
  30. final def synchronized[T0](arg0: ⇒ T0): T0

    Permalink
    Definition Classes
    AnyRef
  31. def toString(): String

    Permalink
    Definition Classes
    AnyRef → Any
  32. val typeCoercionRules: List[Rule[LogicalPlan]]

    Permalink
  33. final def wait(): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  34. final def wait(arg0: Long, arg1: Int): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  35. final def wait(arg0: Long): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )

Inherited from AnyRef

Inherited from Any

Ungrouped