iemejia commented on a change in pull request #10974: [BEAM-9384] Add SchemaRegistry.getSchemaCoder to get SchemaCoders for registered types URL: https://github.com/apache/beam/pull/10974#discussion_r384960299
########## File path: sdks/java/core/src/main/java/org/apache/beam/sdk/schemas/SchemaRegistry.java ########## @@ -288,6 +281,38 @@ public void registerSchemaProvider(SchemaProvider schemaProvider) { return getProviderResult((SchemaProvider p) -> p.fromRowFunction(typeDescriptor)); } + /** + * Retrieve a {@link SchemaCoder} for a given {@link Class} type. If no schema exists, throws + * {@link * NoSuchSchemaException}. + */ + public <T> SchemaCoder<T> getSchemaCoder(Class<T> clazz) throws NoSuchSchemaException { + return getSchemaCoder(TypeDescriptor.of(clazz)); + } + + /** + * Retrieve a {@link SchemaCoder} for a given {@link TypeDescriptor} type. If no schema exists, + * throws {@link * NoSuchSchemaException}. + */ + public <T> SchemaCoder<T> getSchemaCoder(TypeDescriptor<T> typeDescriptor) + throws NoSuchSchemaException { + return SchemaCoder.of( + getSchema(typeDescriptor), + typeDescriptor, + getToRowFunction(typeDescriptor), + getFromRowFunction(typeDescriptor)); Review comment: I agree with you in the fact that `SchemaCoder` is an internal detail that regular users (authors of Pipelines) should not care about. I felt tempted to mark this method as `@Internal` however PTransform authors (e.g. IO authors) will find this useful (as I did for the PR I mention above for KafkaIO schema support), so probably worth to let it available, also I cannot think of a better place to put this method than here. ---------------------------------------------------------------- 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 With regards, Apache Git Services