Skip to content

Commit

Permalink
[CORE] Avoid copy in ByteLiteralNode (apache#5763)
Browse files Browse the repository at this point in the history
Optimize the serialized bloom filter to avoid extra copy
  • Loading branch information
jinchengchenghh authored May 28, 2024
1 parent efd6f31 commit 4592e07
Showing 1 changed file with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
import com.google.protobuf.ByteString;
import io.substrait.proto.Expression.Literal.Builder;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class BinaryLiteralNode extends LiteralNodeWithValue<byte[]> {
public BinaryLiteralNode(byte[] value) {
super(value, new BinaryTypeNode(true));
Expand All @@ -33,6 +36,14 @@ public BinaryLiteralNode(byte[] value, TypeNode typeNode) {

@Override
protected void updateLiteralBuilder(Builder literalBuilder, byte[] value) {
literalBuilder.setBinary(ByteString.copyFrom(value));
ByteString byteValue;
try {
Method m = ByteString.class.getDeclaredMethod("wrap", byte[].class);
m.setAccessible(true);
byteValue = (ByteString) m.invoke(null, value);
} catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) {
throw new RuntimeException(e);
}
literalBuilder.setBinary(byteValue);
}
}

0 comments on commit 4592e07

Please sign in to comment.