10.4. Types

The Type interface in Presto is used to implement a type in the SQL language.Presto ships with a number of built-in types, like VarcharType and BigintType.The ParametricType interface is used to provide type parameters for types, toallow types like VARCHAR(10) or DECIMAL(22, 5). A Plugin can providenew Type objects by returning them from getTypes() and new ParametricTypeobjects by returning them from getParametricTypes().

Below is a high level overview of the Type interface, for more details see theJavaDocs for Type.

  • Native container type:

All types define the getJavaType() method, frequently referred to as the“native container type”. This is the Java type used to hold values during executionand to store them in a Block. For example, this is the type used inthe Java code that implements functions that produce or consume this Type.

  • Native encoding:

The interpretation of a value in its native container type form is defined by itsType. For some types, such as BigintType, it matches the Javainterpretation of the native container type (64bit 2’s complement). However, for othertypes such as TimestampWithTimeZoneType, which also uses long for itsnative container type, the value stored in the long is a 8byte binary valuecombining the timezone and the milliseconds since the unix epoch. In particular,this means that you cannot compare two native values and expect a meaningfulresult, without knowing the native encoding.

  • Type signature:

The signature of a type defines its identity, and also encodes some generalinformation about the type, such as its type parameters (if it’s parametric),and its literal parameters. The literal parameters are used in types likeVARCHAR(10).