Skip to content

Commit 262ae9f

Browse files
committed
review feedback
1 parent 41d5627 commit 262ae9f

File tree

3 files changed

+28
-7
lines changed

3 files changed

+28
-7
lines changed

java/vector/src/main/java/org/apache/arrow/vector/types/pojo/Field.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919

2020

2121
import static com.google.common.base.Preconditions.checkNotNull;
22-
import static java.lang.String.format;
2322
import static org.apache.arrow.vector.types.pojo.ArrowType.getTypeForField;
2423

2524
import java.util.List;
@@ -145,15 +144,18 @@ public boolean equals(Object obj) {
145144
(Objects.equals(this.children, that.children) ||
146145
(this.children == null && that.children.size() == 0) ||
147146
(this.children.size() == 0 && that.children == null));
148-
149147
}
150148

151149
@Override
152150
public String toString() {
153-
if (children.isEmpty()) {
154-
return format("%s: %s", name, type);
155-
} else {
156-
return format("%s: %s{%s}", name, type, Joiner.on(",").join(children));
151+
StringBuilder sb = new StringBuilder();
152+
if (name != null) {
153+
sb.append(name).append(": ");
154+
}
155+
sb.append(type);
156+
if (!children.isEmpty()) {
157+
sb.append("<").append(Joiner.on(", ").join(children)).append(">");
157158
}
159+
return sb.toString();
158160
}
159161
}

java/vector/src/main/java/org/apache/arrow/vector/types/pojo/Schema.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import com.fasterxml.jackson.databind.ObjectMapper;
3434
import com.fasterxml.jackson.databind.ObjectReader;
3535
import com.fasterxml.jackson.databind.ObjectWriter;
36+
import com.google.common.base.Joiner;
3637
import com.google.common.collect.ImmutableList;
3738
import com.google.flatbuffers.FlatBufferBuilder;
3839

@@ -132,6 +133,6 @@ public boolean equals(Object obj) {
132133

133134
@Override
134135
public String toString() {
135-
return "Schema" + fields;
136+
return "Schema<" + Joiner.on(", ").join(fields) + ">";
136137
}
137138
}

java/vector/src/test/java/org/apache/arrow/vector/types/pojo/TestSchema.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,24 @@ private static Field field(String name, ArrowType type, Field... children) {
3939
return field(name, true, type, children);
4040
}
4141

42+
@Test
43+
public void testComplex() throws IOException {
44+
Schema schema = new Schema(asList(
45+
field("a", false, new ArrowType.Int(8, true)),
46+
field("b", new ArrowType.Struct(),
47+
field("c", new ArrowType.Int(16, true)),
48+
field("d", new ArrowType.Utf8())),
49+
field("e", new ArrowType.List(), field(null, new ArrowType.Date())),
50+
field("f", new ArrowType.FloatingPoint(FloatingPointPrecision.SINGLE)),
51+
field("g", new ArrowType.Timestamp(TimeUnit.MILLISECOND)),
52+
field("h", new ArrowType.Interval(IntervalUnit.DAY_TIME))
53+
));
54+
roundTrip(schema);
55+
assertEquals(
56+
"Schema<a: Int(8, true), b: Struct<c: Int(16, true), d: Utf8>, e: List<Date>, f: FloatingPoint(SINGLE), g: Timestamp(MILLISECOND), h: Interval(DAY_TIME)>",
57+
schema.toString());
58+
}
59+
4260
@Test
4361
public void testAll() throws IOException {
4462
Schema schema = new Schema(asList(

0 commit comments

Comments
 (0)