Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[REVIEW PURPOSE] Add TO_HEX and FROM_HEX implementation in Java #24

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
}
}
}