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

ASF GitHub Bot logged work on AVRO-3224:
----------------------------------------

                Author: ASF GitHub Bot
            Created on: 08/Mar/22 00:19
            Start Date: 08/Mar/22 00:19
    Worklog Time Spent: 10m 
      Work Description: liu-du commented on a change in pull request #1355:
URL: https://github.com/apache/avro/pull/1355#discussion_r821215780



##########
File path: 
lang/java/avro/src/main/java/org/apache/avro/reflect/ReflectDatumReader.java
##########
@@ -152,68 +160,39 @@ protected Object readArray(Object old, Schema expected, 
ResolvingDecoder in) thr
         throw new AvroRuntimeException(msg);
       }
     } else {
-      return readJavaArray(array, expectedType, l, in);
-    }
-  }
-
-  private Object readJavaArray(Object array, Schema expectedType, long l, 
ResolvingDecoder in) throws IOException {
-    Class<?> elementType = array.getClass().getComponentType();
-    if (elementType.isPrimitive()) {
-      return readPrimitiveArray(array, elementType, l, in);
-    } else {
-      return readObjectArray((Object[]) array, expectedType, l, in);
+      return readJavaArray(array, elementClass, elementSchema, l, in);
     }
   }
 
-  private Object readPrimitiveArray(Object array, Class<?> c, long l, 
ResolvingDecoder in) throws IOException {
-    return ArrayAccessor.readArray(array, c, l, in);
-  }
-
-  private Object readObjectArray(Object[] array, Schema expectedType, long l, 
ResolvingDecoder in) throws IOException {
-    LogicalType logicalType = expectedType.getLogicalType();
-    Conversion<?> conversion = getData().getConversionFor(logicalType);
-    int index = 0;
-    if (logicalType != null && conversion != null) {
-      do {
-        int limit = index + (int) l;
-        while (index < limit) {
-          Object element = readWithConversion(null, expectedType, logicalType, 
conversion, in);
-          array[index] = element;
-          index++;
-        }
-      } while ((l = in.arrayNext()) > 0);
+  private Object readJavaArray(Object array, Class<?> elementClass, Schema 
expected, long l, ResolvingDecoder in)
+      throws IOException {
+    Class<?> arrayElementClass = array.getClass().getComponentType();
+    if (arrayElementClass.isPrimitive()) {
+      return ArrayAccessor.readArray(array, arrayElementClass, l, in);

Review comment:
       the call to "newArray" at line 138 accepts an elementClass, it will only 
return a primitive array if elementClass==null ,that is, if there is no 
conversion. I guess this might be a performance optimisation for the common 
case when there is no conversion? 




-- 
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]


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

    Worklog Id:     (was: 737877)
    Time Spent: 2h 50m  (was: 2h 40m)

> Wrong deserialisation when using ReflectData.AllowNull with custom 
> LogicalType conversions
> ------------------------------------------------------------------------------------------
>
>                 Key: AVRO-3224
>                 URL: https://issues.apache.org/jira/browse/AVRO-3224
>             Project: Apache Avro
>          Issue Type: Bug
>          Components: java
>    Affects Versions: 1.10.2
>            Reporter: Du Liu
>            Priority: Minor
>              Labels: pull-request-available
>         Attachments: ReflectData.AllowNull.get doesnt work.png, 
> ReflectData.get works.png, class_and_conversion.png, tests.txt
>
>          Time Spent: 2h 50m
>  Remaining Estimate: 0h
>
> If a class contains both a java.time.LocalDate field and a java.sql.Date 
> field, serialising an instance of the class using ReflectData.*AllowNull* 
> with two conversions that both convert to avro date logical type (e.g. one 
> converts java.time.LocalDate to avro date, the other converts java.sql.Date 
> to avro date) is done correctly, but when deserialising the data back, the 
> LocalDate field of the deserialised instance incorrectly contains a 
> java.sql.Date (or the Date field incorrectly contains a LocalDate depending 
> on which conversions is added last).
> This only happens when using ReflectData.*AllowNull*.get(). ReflectData.get() 
> can correctly deserialised data back. I think this issue affects other types 
> as long as two java types are mapped to the same avro logical type.
> A working example (using ReflectData.get()):
> !ReflectData.get works.png|width=887,height=379!
>  
> A not working example (using ReflectData.AllowNull.get()):
> !ReflectData.AllowNull.get doesnt work.png|width=831,height=469!
> The class and conversion: 
> !class_and_conversion.png|width=798,height=687!
>  
> These tests are included in the attached patch file:  [^tests.txt]



--
This message was sent by Atlassian Jira
(v8.20.1#820001)

Reply via email to