chamikaramj commented on a change in pull request #17101: URL: https://github.com/apache/beam/pull/17101#discussion_r827549894
########## File path: runners/core-construction-java/src/main/java/org/apache/beam/runners/core/construction/PayloadBuilder.java ########## @@ -0,0 +1,79 @@ +package org.apache.beam.runners.core.construction; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import org.apache.beam.sdk.schemas.JavaFieldSchema; +import org.apache.beam.sdk.schemas.NoSuchSchemaException; +import org.apache.beam.sdk.schemas.Schema; +import org.apache.beam.sdk.schemas.SchemaRegistry; +import org.apache.beam.sdk.values.Row; + + +// TODO: Move to sdks/java/extensions/python/src/main/java/org/apache/beam/sdk/extensions/python/ +// when https://github.com/apache/beam/pull/17035 is in. +// TODO: Add unit tests. +public class PayloadBuilder { + + private Schema schema; + private static final SchemaRegistry SCHEMA_REGISTRY = SchemaRegistry.createDefault(); + private List<Object> args; + private Map<String, Object> kwargs; + + private PayloadBuilder(Schema schema) { + this.schema = schema; + args = new ArrayList<>(); + kwargs = new HashMap<>(); + } + + static PayloadBuilder fromSchema(Schema schema) { + return new PayloadBuilder(schema); + } + + static PayloadBuilder fromType(Class<?> type) { + try { + return fromSchema(SCHEMA_REGISTRY.getSchema(type)); + } catch (NoSuchSchemaException e) { + throw new RuntimeException(e); + } + } + + static PayloadBuilder fromJavaPojo(Object pojo) { Review comment: Thanks. Will do updates after https://github.com/apache/beam/pull/17035 is in. -- 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]
