diff --git a/velox/docs/functions/presto/binary.rst b/velox/docs/functions/presto/binary.rst index 2a92f262309f5..849ac2b89b522 100644 --- a/velox/docs/functions/presto/binary.rst +++ b/velox/docs/functions/presto/binary.rst @@ -41,6 +41,28 @@ Binary Functions Decodes ``bigint`` value from a 64-bit 2’s complement big endian ``binary``. +.. function:: from_base32(string) -> varbinary + + Decodes a Base32-encoded ``string`` back into its original binary form. + This function can handle both padded and non-padded Base32 encoded strings. Partially padded Base32 strings will result in an error. + + Examples + -------- + Query with padded Base32 string: + :: + SELECT from_base32('JBSWY3DPEBLW64TMMQ======'); -- [72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100] + + Query with non-padded Base32 string: + :: + SELECT from_base32('JBSWY3DPEBLW64TMMQ'); -- [72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100] + + Query with partially padded Base32 string: + :: + SELECT from_base32('JBSWY3DPEBLW64TM=='); -- Error: Base32::decode() - invalid input string: length is not a multiple of 8. + + In the examples above, both fully padded and non-padded Base32 strings ('JBSWY3DPEBLW64TMMQ======' and 'JBSWY3DPEBLW64TMMQ') decode to the binary representation of the text 'Hello World'. + The partially padded Base32 string 'JBSWY3DPEBLW64TM==' will lead to a decoding error. + .. function:: from_hex(string) -> varbinary Decodes binary data from the hex encoded ``string``. @@ -137,21 +159,22 @@ Binary Functions .. function:: to_base32(varbinary) -> string - Encodes a binary ``varbinary`` value into its Base32 string representation. - This function generates padded Base32 strings by default. + Encodes a binary ``varbinary`` value into its Base32 string representation. + This function generates padded Base32 strings by default. - Examples - -------- - Query to encode a binary value to a padded Base32 string: - :: + Examples + -------- + Query to encode a binary value to a padded Base32 string: + :: SELECT to_base32(ARRAY[72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100]); -- 'JBSWY3DPEBLW64TMMQ======' - Query to encode a binary value with fewer bytes: - :: + Query to encode a binary value with fewer bytes: + :: SELECT to_base32(ARRAY[104, 101, 108, 108, 111]); -- 'NBSWY3DP' - In the above examples, the binary array `[72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100]` is encoded to the padded Base32 string 'JBSWY3DPEBLW64TMMQ======'. - The binary array `[104, 101, 108, 108, 111]` is encoded to 'NBSWY3DP'. + In the above examples, the binary array `[72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100]` is encoded to the padded Base32 string 'JBSWY3DPEBLW64TMMQ======'. + The binary array `[104, 101, 108, 108, 111]` is encoded to 'NBSWY3DP'. + .. function:: to_hex(binary) -> varchar