@Description("Encode binary data as base32")
    @ScalarFunction
    @SqlType(StandardTypes.VARCHAR)
    public static Slice toBase32(@SqlType(StandardTypes.VARBINARY) Slice slice)
    {
        String encoded;
        if (slice.hasByteArray()) {
            encoded = BaseEncoding.base32().encode(slice.byteArray(), slice.byteArrayOffset(), slice.length());
        }
        else {
            encoded = BaseEncoding.base32().encode(slice.getBytes());
        }
        return Slices.utf8Slice(encoded);
    }
@Test
    public void testToBase32()
    {
        assertFunction("to_base32(CAST('' AS VARBINARY))", VARCHAR, encodeBase32(""));
        assertFunction("to_base32(CAST('a' AS VARBINARY))", VARCHAR, encodeBase32("a"));
        assertFunction("to_base32(CAST('abc' AS VARBINARY))", VARCHAR, encodeBase32("abc"));
        assertFunction("to_base32(CAST('hello world' AS VARBINARY))", VARCHAR, "NBSWY3DPEB3W64TMMQ======");
        assertFunction("to_base32(NULL)", VARCHAR, null);
    }