[ https://issues.apache.org/jira/browse/BEAM-9331?focusedWorklogId=389359&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-389359 ]
ASF GitHub Bot logged work on BEAM-9331: ---------------------------------------- Author: ASF GitHub Bot Created on: 19/Feb/20 09:07 Start Date: 19/Feb/20 09:07 Worklog Time Spent: 10m Work Description: alexvanboxel commented on pull request #10883: [BEAM-9331] Add better Row builders URL: https://github.com/apache/beam/pull/10883#discussion_r381151951 ########## File path: sdks/java/core/src/main/java/org/apache/beam/sdk/values/Row.java ########## @@ -539,37 +568,118 @@ public String toString() { } /** - * Creates a record builder with specified {@link #getSchema()}. {@link Builder#build()} will - * throw an {@link IllegalArgumentException} if number of fields in {@link #getSchema()} does not - * match the number of fields specified. + * Creates a row builder with specified {@link #getSchema()}. {@link Builder#build()} will throw + * an {@link IllegalArgumentException} if number of fields in {@link #getSchema()} does not match + * the number of fields specified. If any of the arguments don't match the expected types for the + * schema fields, {@link Builder#build()} will throw a {@link ClassCastException}. */ public static Builder withSchema(Schema schema) { return new Builder(schema); } + /** + * Creates a row builder based on the specified row. Field values in the new row can be explicitly + * set using {@link ModifyingBuilder#withFieldValue}. Any values not so overridden will be the + * same as the values in the original row. + */ + public static ModifyingBuilder fromRow(Row row) { + return new ModifyingBuilder(row); + } + + /** Builder for {@link Row} that bases a row on another row. */ + public static class ModifyingBuilder { Review comment: Can't this be tweaked a bit, that this is the builder specifically for use with `withFieldValue`. Meaning that if when nit doesn't have a source row it just assumes null values for the fields not set. See remark on `withFieldValue` on initial builder as well. ---------------------------------------------------------------- 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. For queries about this service, please contact Infrastructure at: us...@infra.apache.org Issue Time Tracking ------------------- Worklog Id: (was: 389359) Time Spent: 1h 20m (was: 1h 10m) > The Row object needs better builders > ------------------------------------ > > Key: BEAM-9331 > URL: https://issues.apache.org/jira/browse/BEAM-9331 > Project: Beam > Issue Type: Sub-task > Components: sdk-java-core > Reporter: Reuven Lax > Priority: Major > Time Spent: 1h 20m > Remaining Estimate: 0h > > Users should be able to build a Row object by specifying field names. Desired > syntax: > > Row.withSchema(schema) > .withFieldName("field1", "value) > .withFieldName("field2.field3", value) > .build() > > Users should also have a builder that allows taking an existing row and > changing specific fields. -- This message was sent by Atlassian Jira (v8.3.4#803005)