diff --git a/sabot/kernel/src/main/java/com/dremio/exec/expr/fn/impl/StringFunctions.java b/sabot/kernel/src/main/java/com/dremio/exec/expr/fn/impl/StringFunctions.java index 698ad6087f..acce6794e2 100644 --- a/sabot/kernel/src/main/java/com/dremio/exec/expr/fn/impl/StringFunctions.java +++ b/sabot/kernel/src/main/java/com/dremio/exec/expr/fn/impl/StringFunctions.java @@ -1481,7 +1481,7 @@ public void eval() { } } - @FunctionTemplate(name = "from_hex", scope = FunctionScope.SIMPLE, nulls = NullHandling.NULL_IF_NULL) + @FunctionTemplate(names = {"from_hex", "unhex"}, scope = FunctionScope.SIMPLE, nulls = NullHandling.NULL_IF_NULL) public static class FromHex implements SimpleFunction { @Param VarCharHolder in; @Output VarBinaryHolder out; @@ -1501,8 +1501,8 @@ public void eval() { } } - @FunctionTemplate(name = "to_hex", scope = FunctionScope.SIMPLE, nulls = NullHandling.NULL_IF_NULL) - public static class ToHex implements SimpleFunction { + @FunctionTemplate(names = {"hex", "to_hex"}, scope = FunctionScope.SIMPLE, nulls = NullHandling.NULL_IF_NULL) + public static class ToHexVarBinary implements SimpleFunction { @Param VarBinaryHolder in; @Output VarCharHolder out; @Workspace Charset charset; @@ -1717,4 +1717,54 @@ public void eval() { out.end = outBytea.length; } } + + @FunctionTemplate(names = {"hex", "to_hex"}, scope = FunctionScope.SIMPLE, nulls = NullHandling.NULL_IF_NULL) + public static class ToHexVarChar implements SimpleFunction { + @Param VarCharHolder in; + @Output VarCharHolder out; + @Workspace Charset charset; + @Inject ArrowBuf buffer; + + @Override + public void setup() { + charset = java.nio.charset.Charset.forName("UTF-8"); + } + + @Override + public void eval() { + byte[] buf = com.dremio.common.util.DremioStringUtils.toBinaryStringNoFormat(io.netty.buffer.NettyArrowBuf.unwrapBuffer(in.buffer), in + .start, in.end).getBytes(charset); + out.buffer = buffer = buffer.reallocIfNeeded(buf.length); + buffer.setBytes(0, buf); + buffer.setIndex(0, buf.length); + + out.start = 0; + out.end = buf.length; + out.buffer = buffer; + } + } + + @FunctionTemplate(names = {"hex", "to_hex"}, scope = FunctionScope.SIMPLE, nulls = NullHandling.NULL_IF_NULL) + public static class ToHexBigInt implements SimpleFunction{ + @Param BigIntHolder in; + @Output VarCharHolder out; + @Workspace Charset charset; + @Inject ArrowBuf buffer; + + @Override + public void setup() { + charset = java.nio.charset.Charset.forName("UTF-8"); + } + + @Override + public void eval() { + String hex_format = String.format("%X", in.value); + byte[] buf = hex_format.getBytes(); + buffer.setBytes(0, buf); + + out.start = 0; + out.end = buf.length; + out.buffer = buffer; + } + } }