For the complete documentation index, see llms.txt. This page is also available as Markdown.

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

Pinot also accepts the SQL-standard unsigned integer targets TINYINT UNSIGNED, SMALLINT UNSIGNED, and INTEGER UNSIGNED. Because Pinot does not store unsigned integers, these casts return the narrowest signed type that preserves the full range: TINYINT UNSIGNED and SMALLINT UNSIGNED behave like INT, while INTEGER UNSIGNED behaves like LONG. BIGINT UNSIGNED is not supported; use BIGINT or DECIMAL instead.

For array-valued casts, Pinot supports CAST(expr AS DECIMAL ARRAY) in standard SQL. In the single-stage engine, Pinot also accepts the Pinot-specific target name BIG_DECIMAL_ARRAY.

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?