From 3310b97355632ed0ffdf2931a7f3ab5d42250e91 Mon Sep 17 00:00:00 2001 From: stephen <91597003+stephen-shelby@users.noreply.github.com> Date: Fri, 22 Nov 2024 19:33:20 +0800 Subject: [PATCH] [Enhancement] Add toString to StructField for easy debugging (#53137) Signed-off-by: stephen --- .../java/com/starrocks/catalog/StructField.java | 13 +++++++++++++ .../com/starrocks/sql/ast/StructFieldDescTest.java | 7 +++++++ 2 files changed, 20 insertions(+) diff --git a/fe/fe-core/src/main/java/com/starrocks/catalog/StructField.java b/fe/fe-core/src/main/java/com/starrocks/catalog/StructField.java index d5da4647427f4..a5649c6f0a87b 100644 --- a/fe/fe-core/src/main/java/com/starrocks/catalog/StructField.java +++ b/fe/fe-core/src/main/java/com/starrocks/catalog/StructField.java @@ -22,6 +22,8 @@ import com.starrocks.thrift.TTypeNode; import org.apache.commons.lang3.StringUtils; +import java.util.StringJoiner; + /** * TODO: Support comments for struct fields. The Metastore does not properly store * comments of struct fields. We set comment to null to avoid compatibility issues. @@ -162,6 +164,17 @@ public boolean equals(Object other) { (fieldId == otherStructField.fieldId) && Objects.equal(fieldPhysicalName, otherStructField.fieldPhysicalName); } + @Override + public String toString() { + return new StringJoiner(", ", StructField.class.getSimpleName() + "[", "]") + .add("name='" + (Strings.isNullOrEmpty(name) ? "" : name) + "'") + .add("type=" + type) + .add("position=" + position) + .add("fieldId=" + fieldId) + .add("fieldPhysicalName='" + (Strings.isNullOrEmpty(fieldPhysicalName) ? "" : fieldPhysicalName) + "'") + .toString(); + } + @Override public StructField clone() { return new StructField(name, fieldId, fieldPhysicalName, type.clone(), comment); diff --git a/fe/fe-core/src/test/java/com/starrocks/sql/ast/StructFieldDescTest.java b/fe/fe-core/src/test/java/com/starrocks/sql/ast/StructFieldDescTest.java index 9e595ed3b1a2b..336ae82b70023 100644 --- a/fe/fe-core/src/test/java/com/starrocks/sql/ast/StructFieldDescTest.java +++ b/fe/fe-core/src/test/java/com/starrocks/sql/ast/StructFieldDescTest.java @@ -23,6 +23,7 @@ import com.starrocks.catalog.StructType; import com.starrocks.catalog.Type; import com.starrocks.common.AnalysisException; +import org.junit.Assert; import org.junit.Test; import org.junit.jupiter.api.Assertions; @@ -33,6 +34,12 @@ public void testAnalyze() { StructField field2 = new StructField("v2", Type.VARCHAR); StructField field3 = new StructField("v3", Type.INT); + Assert.assertEquals("StructField[name='v3', type=INT, position=0, fieldId=-1, fieldPhysicalName='']", + field3.toString()); + StructField unnamedField = new StructField(null, Type.VARCHAR); + Assert.assertEquals("StructField[name='', type=VARCHAR, position=0, fieldId=-1, fieldPhysicalName='']", + unnamedField.toString()); + StructType subStructType = new StructType(Lists.newArrayList(field2, field3)); StructField field4 = new StructField("v4", subStructType); StructType type = new StructType(Lists.newArrayList(field1, field4));