[ 
https://issues.apache.org/jira/browse/BEAM-9384?focusedWorklogId=395477&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-395477
 ]

ASF GitHub Bot logged work on BEAM-9384:
----------------------------------------

                Author: ASF GitHub Bot
            Created on: 29/Feb/20 16:28
            Start Date: 29/Feb/20 16:28
    Worklog Time Spent: 10m 
      Work Description: reuvenlax commented on pull request #10974: [BEAM-9384] 
Add SchemaRegistry.getSchemaCoder to get SchemaCoders for registered types
URL: https://github.com/apache/beam/pull/10974#discussion_r386038872
 
 

 ##########
 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:
   It's useful when integrating schema code with code that does not yet 
understand schemas.
   
   In the KafkaIO example I think that the ideal solution would be to allow a 
Schema on KafkaRecord (this probably requires us to add Java generic type 
awareness to schema inference though), in which case they keyCoder and 
valueCoder isn't needed. I agree that allowing easy inference of SchemaCoder 
allows for lower-effort integration of schemas in code like this, though 
hopefully this is just a short-term solution.
 
----------------------------------------------------------------
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:
[email protected]


Issue Time Tracking
-------------------

    Worklog Id:     (was: 395477)
    Time Spent: 4h 40m  (was: 4.5h)

> Add SchemaRegistry.getSchemaCoder to get SchemaCoders for registered types
> --------------------------------------------------------------------------
>
>                 Key: BEAM-9384
>                 URL: https://issues.apache.org/jira/browse/BEAM-9384
>             Project: Beam
>          Issue Type: Improvement
>          Components: sdk-java-core
>            Reporter: Ismaël Mejía
>            Assignee: Ismaël Mejía
>            Priority: Minor
>          Time Spent: 4h 40m
>  Remaining Estimate: 0h
>
> PTransforms that are parameterized by types may be able to infer a valid 
> SchemaCoder for a given type from the SchemaRegistry (if a Schema for the 
> given type is available). This method will provide a unified place to do that.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to