reuvenlax commented on code in PR #40791:
URL: https://github.com/apache/beam/pull/40791#discussion_r4393948149
##########
sdks/java/core/src/main/java/org/apache/beam/sdk/values/Row.java:
##########
@@ -892,57 +878,62 @@ public static <T> Collector<T, List<Object>, Row>
toRow(Schema schema) {
/** Creates a new record filled with nulls. */
public static Row nullRow(Schema schema) {
- return Row.withSchema(schema)
- .addValues(Collections.nCopies(schema.getFieldCount(), null))
- .build();
+ int fieldCount = schema.getFieldCount();
Review Comment:
Can you explain what this change accomplishes?
##########
sdks/java/core/src/main/java/org/apache/beam/sdk/values/Row.java:
##########
@@ -108,9 +103,12 @@ public abstract class Row implements Serializable {
/** Return a list of data values. Any LogicalType values are returned as
base values. * */
public List<Object> getBaseValues() {
- return IntStream.range(0, getFieldCount())
- .mapToObj(i -> getBaseValue(i))
- .collect(Collectors.toList());
+ int fieldCount = getFieldCount();
+ List<Object> baseValues = new ArrayList<>(fieldCount);
+ for (int i = 0; i < fieldCount; i++) {
+ baseValues.add(getBaseValue(i));
+ }
Review Comment:
Is this really that much more efficient? If you're worried about
preallocating the list, I think you can do Collectors.toCollection(() -> new
ArrayList<>(fieldCount))
##########
sdks/java/core/src/test/java/org/apache/beam/sdk/util/RowStringInterpolatorTest.java:
##########
@@ -102,7 +102,7 @@ public void
testInvalidRowThrowsHelpfulErrorForDoublyNestedFields() {
Schema nestedSchema =
Schema.builder().addNullableRowField("nested_row",
doublyNestedSchema).build();
Row invalidRow =
- Row.withSchema(Schema.builder().addNullableRowField("row",
doublyNestedSchema).build())
+ Row.withSchema(Schema.builder().addNullableRowField("row",
nestedSchema).build())
.addValue(
Review Comment:
Why is this changed?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]