Skip to content

Commit

Permalink
[Enhancement] Add toString to StructField for easy debugging (#53137)
Browse files Browse the repository at this point in the history
Signed-off-by: stephen <[email protected]>
  • Loading branch information
stephen-shelby authored Nov 22, 2024
1 parent 4f60313 commit 3310b97
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
13 changes: 13 additions & 0 deletions fe/fe-core/src/main/java/com/starrocks/catalog/StructField.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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));
Expand Down

0 comments on commit 3310b97

Please sign in to comment.