[ 
https://issues.apache.org/jira/browse/AVRO-1847?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15329494#comment-15329494
 ] 

Yibing Shi commented on AVRO-1847:
----------------------------------

The {{conver}} method is newly added by this patch. It didn't exist in master 
branch. However, the exception it throws does get out through method {{write}}. 
I agree with [~busbey] that we should keep the exceptions the same as before.
On the other hand, it also makes sense to make the to convert methods in 
{{Conversions}} behave similarly. So I prefer throwing AvroRuntimeException in 
{{convertToRawType}}, but catch this exception in 
{{GenericDatumWriter.convert}} and throw its cause out to keep backwards 
compatibility. Maybe we can change this feature in later versions?
The code is like below:
{code}
  protected <T> Object convert(Schema schema, LogicalType logicalType,
                               Conversion<T> conversion, Object datum) {
    try {
      if (conversion == null) {
        return datum;
      } else {
        return Conversions.convertToRawType(datum, schema, logicalType, 
conversion);
      }
    } catch (AvroRuntimeException e) {
      Throwable cause = e.getCause();
      if (cause != null && cause.getClass() == ClassCastException.class) {
        // This is to keep backwards compatibility. The convert function here 
used to
        // throw CCE. When prompted to Conversions, it throws 
AvroRuntimeException. So,
        // if the cause is a CCE, rethrow it in case any child class checks it. 
This
        // behaviour can be changed later in future versions to make it 
consistent with
        // reading path, which throws AvroRuntimeException
        throw (ClassCastException)cause;
      } else {
        throw e;
      }
    }
  }
{code}
Please let me know your opinion.


> IDL compiler uses ByteBuffer for decimal type even if logical type is 
> supported 
> --------------------------------------------------------------------------------
>
>                 Key: AVRO-1847
>                 URL: https://issues.apache.org/jira/browse/AVRO-1847
>             Project: Avro
>          Issue Type: Bug
>          Components: java
>    Affects Versions: 1.8.0
>            Reporter: Yibing Shi
>            Assignee: Yibing Shi
>         Attachments: AVRO-1847.1.patch, AVRO-1847.2.patch, AVRO-1847.3.patch, 
> AVRO-1847.4.patch
>
>
> Version 1.8.0 has added the support of logical types. A conversion class 
> (Conversions.DecimalConversion) has also been added for decimal type. 
> However, the IDL compiler still uses ByteBuffer for decimal types, which is 
> not the same behaviour as data, time or timestamp type (added in AVRO-1684). 



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to