This is an automated email from the ASF dual-hosted git repository.
yangjie01 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/spark.git
The following commit(s) were added to refs/heads/master by this push:
new a95aa7a7dda1 [SPARK-46987][CONNECT] `ProtoUtils.abbreviate` avoid
unnecessary `setField` operation
a95aa7a7dda1 is described below
commit a95aa7a7dda1a5a2cfee69b3c132c524c0e01c7d
Author: Ruifeng Zheng <[email protected]>
AuthorDate: Wed Feb 7 10:26:34 2024 +0800
[SPARK-46987][CONNECT] `ProtoUtils.abbreviate` avoid unnecessary `setField`
operation
### What changes were proposed in this pull request?
`ProtoUtils.abbreviate` avoid unnecessary `setField` operation
### Why are the changes needed?
according to the [API
reference](https://protobuf.dev/reference/java/api-docs/com/google/protobuf/Message.html#toBuilder--):
> Message.Builder toBuilder()
Constructs a builder initialized with the current message. Use this to
derive a new message from the current one.
the builder we used already has all the fields, so we only need to update
the truncated fields.
### Does this PR introduce _any_ user-facing change?
no
### How was this patch tested?
ci
### Was this patch authored or co-authored using generative AI tooling?
no
Closes #45045 from zhengruifeng/connect_redaction_nit.
Authored-by: Ruifeng Zheng <[email protected]>
Signed-off-by: yangjie01 <[email protected]>
---
.../scala/org/apache/spark/sql/connect/common/ProtoUtils.scala | 8 +-------
1 file changed, 1 insertion(+), 7 deletions(-)
diff --git
a/connector/connect/common/src/main/scala/org/apache/spark/sql/connect/common/ProtoUtils.scala
b/connector/connect/common/src/main/scala/org/apache/spark/sql/connect/common/ProtoUtils.scala
index 44de2350b9fd..2f31b63acf87 100644
---
a/connector/connect/common/src/main/scala/org/apache/spark/sql/connect/common/ProtoUtils.scala
+++
b/connector/connect/common/src/main/scala/org/apache/spark/sql/connect/common/ProtoUtils.scala
@@ -43,8 +43,6 @@ private[connect] object ProtoUtils {
val threshold = thresholds.getOrElse(STRING, MAX_STRING_SIZE)
if (size > threshold) {
builder.setField(field, createString(string.take(threshold), size))
- } else {
- builder.setField(field, string)
}
case (field: FieldDescriptor, byteString: ByteString)
@@ -57,8 +55,6 @@ private[connect] object ProtoUtils {
byteString
.substring(0, threshold)
.concat(createTruncatedByteString(size)))
- } else {
- builder.setField(field, byteString)
}
case (field: FieldDescriptor, byteArray: Array[Byte])
@@ -71,8 +67,6 @@ private[connect] object ProtoUtils {
ByteString
.copyFrom(byteArray, 0, threshold)
.concat(createTruncatedByteString(size)))
- } else {
- builder.setField(field, byteArray)
}
// TODO(SPARK-43117): should also support 1, repeated msg; 2, map<xxx,
msg>
@@ -80,7 +74,7 @@ private[connect] object ProtoUtils {
if field.getJavaType == FieldDescriptor.JavaType.MESSAGE && msg !=
null =>
builder.setField(field, abbreviate(msg, thresholds))
- case (field: FieldDescriptor, value: Any) => builder.setField(field,
value)
+ case _ =>
}
builder.build()
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]