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

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

                Author: ASF GitHub Bot
            Created on: 21/Dec/18 15:56
            Start Date: 21/Dec/18 15:56
    Worklog Time Spent: 10m 
      Work Description: kanterov commented on a change in pull request #7290: 
[[BEAM-4454] Support avro schema inference in sources
URL: https://github.com/apache/beam/pull/7290#discussion_r243598981
 
 

 ##########
 File path: 
sdks/java/core/src/main/java/org/apache/beam/sdk/schemas/utils/AvroUtils.java
 ##########
 @@ -251,6 +252,35 @@ public static GenericRecord toGenericRecord(
     return builder.build();
   }
 
+  @SuppressWarnings("unchecked")
+  public static <T> SerializableFunction<T, Row> getToRowFunction(
+      Class<T> clazz, @Nullable org.apache.avro.Schema schema) {
+    if (GenericRecord.class.equals(clazz)) {
+      Schema beamSchema = toBeamSchema(schema);
+      return (SerializableFunction<T, Row>) 
getGenericRecordToRowFunction(beamSchema);
+    } else {
+      return new AvroRecordSchema().toRowFunction(TypeDescriptor.of(clazz));
+    }
+  }
+
+  @SuppressWarnings("unchecked")
+  public static <T> SerializableFunction<Row, T> getFromRowFunction(Class<T> 
clazz) {
+    return (GenericRecord.class.equals(clazz))
+        ? (SerializableFunction<Row, T>) getRowToGenericRecordFunction(null)
+        : new AvroRecordSchema().fromRowFunction(TypeDescriptor.of(clazz));
+  }
+
+  @Nullable
+  public static <T> Schema getSchema(Class<T> clazz, @Nullable 
org.apache.avro.Schema schema) {
 
 Review comment:
   Now we have a call chain:
   
   1. `AvroIO.setBeamSchema`
   2. `AvroUtil. getSchema(Class<T> clazz, @Nullable org.apache.avro.Schema 
schema)`
   3. `AvroRecordSchema#schemaFor`
   4. `AvroUtil.getSchema(Class<T> clazz)`
   
   As for me, it's a bit misleading. I would rather leave it in 
`AvroIO.setBeamSchema`, and expose:
   ```java
   Schema AvroUtils.getSchema(org.apache.avro.Schema schema);
   <T> Schema AvroUtils.getSchema(Class<T> clazz);
   ```

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on 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: 178028)
    Time Spent: 11h 50m  (was: 11h 40m)

> Provide automatic schema registration for AVROs
> -----------------------------------------------
>
>                 Key: BEAM-4454
>                 URL: https://issues.apache.org/jira/browse/BEAM-4454
>             Project: Beam
>          Issue Type: Sub-task
>          Components: sdk-java-core
>            Reporter: Reuven Lax
>            Assignee: Reuven Lax
>            Priority: Major
>          Time Spent: 11h 50m
>  Remaining Estimate: 0h
>
> Need to make sure this is a compatible change



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to