Data Type - Coercion (Conversion Between Types)

> Code - (Programming|Computer) Language > (Data) Type - (Datatype|Type of data)

1 - About

Type conversion is called generally “coercion.”

Coercion is the fact to change:

  • the type of a primitive (Example from string to number)
  • a class of an object.

3 - Function

The function name to coerce can be:

  • cast
  • coerce

4 - Form

Implicit vs Explicit

4.1 - Implicit (silent)

Silent coercions can make debugging a broken program particularly frustrating, since they cover up errors and make them harder to diagnose.

The hierarchy of type defines how the types are implicitly converted. Implicit conversion is allowed for types from child to an ancestor. Example of Hierarchy for Hive:

Primitive Type > Number > DOUBLE > FLOAT > BIGINT > INT > SMALLINT > TINYINT
                                 > STRING

Note that the type hierarchy allows the implicit conversion of STRING to DOUBLE.

code/type/coercion.txt · Last modified: 2018/11/30 18:59 by gerardnico