githubEdit

Type Conversion Functions

Pinot provides functions for converting values between data types, as well as encoding and decoding between binary, hex, and Base64 representations.

CAST

CAST(value AS type)

Converts a value to the specified target type. This is the standard SQL cast syntax supported by Pinot.

Supported target types:

Type
Aliases
Description

INT

INTEGER

32-bit integer

LONG

BIGINT

64-bit integer

FLOAT

32-bit floating point

DOUBLE

64-bit floating point

BOOLEAN

Boolean value

TIMESTAMP

Timestamp value

STRING

VARCHAR

String value

BYTES

VARBINARY

Byte array

BIG_DECIMAL

DECIMAL

Arbitrary-precision decimal

SELECT CAST(revenue AS DOUBLE) AS revenue_double,
       CAST(zipCode AS VARCHAR) AS zip_string,
       CAST('12345' AS BIGINT) AS id_long
FROM orders
LIMIT 5

The function-call form cast(value, 'TYPE') is also supported:

When casting a STRING to INT or LONG, Pinot will first attempt direct integer parsing. If that fails, it will parse the string as a DOUBLE and truncate. For LONG, Pinot also attempts timestamp parsing before falling back to double conversion.

bigDecimalToBytes

Serializes a BIG_DECIMAL value to its byte array representation. The resulting bytes contain the unscaled value appended to the scale in big-endian order.

bytesToBigDecimal

Deserializes a byte array (previously created by bigDecimalToBytes) back to a BIG_DECIMAL value.

hexToBytes

Converts a plain hex string to a byte array.

bytesToHex

Converts a byte array to a plain hex string.

base64Encode

Encodes a byte array to its Base64 representation.

base64Decode

Decodes a Base64-encoded byte array back to the original bytes.

hexDecimalToLong

Converts a hexadecimal string to its corresponding LONG value. Accepts strings with or without the 0x prefix.

longToHexDecimal

Converts a LONG value to its hexadecimal string representation.

Last updated

Was this helpful?