From 4592e07fdb4179c68e41405b020e7cae202d7336 Mon Sep 17 00:00:00 2001 From: Jin Chengcheng Date: Tue, 28 May 2024 08:21:26 +0800 Subject: [PATCH] [CORE] Avoid copy in ByteLiteralNode (#5763) Optimize the serialized bloom filter to avoid extra copy --- .../substrait/expression/BinaryLiteralNode.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/gluten-core/src/main/java/org/apache/gluten/substrait/expression/BinaryLiteralNode.java b/gluten-core/src/main/java/org/apache/gluten/substrait/expression/BinaryLiteralNode.java index 864aeb741a15..3d1ee51741ee 100644 --- a/gluten-core/src/main/java/org/apache/gluten/substrait/expression/BinaryLiteralNode.java +++ b/gluten-core/src/main/java/org/apache/gluten/substrait/expression/BinaryLiteralNode.java @@ -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 { public BinaryLiteralNode(byte[] value) { super(value, new BinaryTypeNode(true)); @@ -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); } }