Object

org.apache.spark.sql.catalyst.analysis

HiveTypeCoercion

Related Doc: package analysis

Permalink

object HiveTypeCoercion

A collection of Rules that can be used to coerce differing types that participate in operations into compatible ones. Most of these rules are based on Hive semantics, but they do not introduce any dependencies on the hive codebase. For this reason they remain in Catalyst until we have a more standard set of coercions.

Linear Supertypes
AnyRef, Any
Ordering
  1. Alphabetic
  2. By inheritance
Inherited
  1. HiveTypeCoercion
  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 DecimalPrecision extends Rule[LogicalPlan]

    Permalink

    Calculates and propagates precision for fixed-precision decimals.

    Calculates and propagates precision for fixed-precision decimals. Hive has a number of rules for this based on the SQL standard and MS SQL: https://cwiki.apache.org/confluence/download/attachments/27362075/Hive_Decimal_Precision_Scale_Support.pdf https://msdn.microsoft.com/en-us/library/ms190476.aspx

    In particular, if we have expressions e1 and e2 with precision/scale p1/s2 and p2/s2 respectively, then the following operations have the following precision / scale:

    Operation Result Precision Result Scale ------------------------------------------------------------------------ e1 + e2 max(s1, s2) + max(p1-s1, p2-s2) + 1 max(s1, s2) e1 - e2 max(s1, s2) + max(p1-s1, p2-s2) + 1 max(s1, s2) e1 * e2 p1 + p2 + 1 s1 + s2 e1 / e2 p1 - s1 + s2 + max(6, s1 + p2 + 1) max(6, s1 + p2 + 1) e1 % e2 min(p1-s1, p2-s2) + max(s1, s2) max(s1, s2) e1 union e2 max(s1, s2) + max(p1-s1, p2-s2) max(s1, s2) sum(e1) p1 + 10 s1 avg(e1) p1 + 4 s1 + 4

    Catalyst also has unlimited-precision decimals. For those, all ops return unlimited precision.

    To implement the rules for fixed-precision types, we introduce casts to turn them to unlimited precision, do the math on unlimited-precision numbers, then introduce casts back to the required fixed precision. This allows us to do all rounding and overflow handling in the cast-to-fixed-precision operator.

    In addition, when mixing non-decimal types with decimals, we use the following rules: - BYTE gets turned into DECIMAL(3, 0) - SHORT gets turned into DECIMAL(5, 0) - INT gets turned into DECIMAL(10, 0) - LONG gets turned into DECIMAL(20, 0) - FLOAT and DOUBLE cause fixed-length decimals to turn into DOUBLE

    Note: Union/Except/Interact is handled by WidenTypes

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

  9. object FunctionArgumentConversion extends Rule[LogicalPlan]

    Permalink

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

  10. object IfCoercion extends Rule[LogicalPlan]

    Permalink

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

  11. object ImplicitTypeCasts extends Rule[LogicalPlan]

    Permalink

    Casts types according to the expected input types for Expressions.

  12. object InConversion extends Rule[LogicalPlan]

    Permalink

    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.

    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 type checking phase.

  13. object PromoteStrings extends Rule[LogicalPlan]

    Permalink

    Promotes strings that appear in arithmetic expressions.

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

  15. object StringToIntegralCasts extends Rule[LogicalPlan]

    Permalink

    When encountering a cast from a string representing a valid fractional number to an integral type the jvm will throw a java.lang.NumberFormatException.

    When encountering a cast from a string representing a valid fractional number to an integral type the jvm will throw a java.lang.NumberFormatException. Hive, in contrast, returns the truncated version of this number.

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

  17. final def asInstanceOf[T0]: T0

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

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

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

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

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

    Permalink

    Find the tightest common type of two types that might be used in a binary expression.

    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 HiveTypeCoercion.DecimalPrecision.

  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. final def synchronized[T0](arg0: ⇒ T0): T0

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

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

    Permalink
  32. final def wait(): Unit

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

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

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

Inherited from AnyRef

Inherited from Any

Ungrouped