avro-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Nandor Kollar (JIRA)" <j...@apache.org>
Subject [jira] [Assigned] (AVRO-2086) Can't create specific record with a single Decimal field with default value
Date Thu, 05 Oct 2017 13:07:01 GMT

     [ https://issues.apache.org/jira/browse/AVRO-2086?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

Nandor Kollar reassigned AVRO-2086:
-----------------------------------

    Assignee: Nandor Kollar

> Can't create specific record with a single Decimal field with default value
> ---------------------------------------------------------------------------
>
>                 Key: AVRO-2086
>                 URL: https://issues.apache.org/jira/browse/AVRO-2086
>             Project: Avro
>          Issue Type: Bug
>          Components: java
>    Affects Versions: 1.8.2
>            Reporter: Nandor Kollar
>            Assignee: Nandor Kollar
>
> Given a simple record schema with a single byte field annotated with Decimal logical
type and has default value set:
> {code}
> {
>    "type":"record",
>    "name":"TestRecordWithDecimalFieldWithDefault",
>    "namespace":"org.apache.avro.specific",
>    "fields":[
>       {
>          "name":"f1",
>          "type":{
>             "type":"bytes",
>             "logicalType":"decimal",
>             "precision":9,
>             "scale":2
>          },
>          "default":"0.00"
>       }
>    ]
> }
> {code}
> compiled with
> {{avro-tools compile -bigDecimal schema TestRecordWithDecimalFieldWithDefault.avsc .}}
> The following test case (which should use the decimal's default value):
> {code}
>   @Test
>   public void testRecordWithDecimalLogicalTypeWithDefault() throws IOException {
>     SpecificData.get().addLogicalTypeConversion(new Conversions.DecimalConversion());
>     TestRecordWithDecimalFieldWithDefault record = TestRecordWithDecimalFieldWithDefault.newBuilder().build();
>     File data = write(TestRecordWithDecimalFieldWithDefault.getClassSchema(), record);
>     List<TestRecordWithDecimalFieldWithDefault> actual = read(
>       TestRecordWithDecimalFieldWithDefault.getClassSchema(), data);
>     assertEquals(new BigDecimal(0.00).setScale(2), actual.get(0).getF1());
>   }
> {code}
> fails with
> {code}
> org.apache.avro.AvroRuntimeException: org.apache.avro.AvroRuntimeException: Cannot convert
8083333.60:BigDecimal: expected generic type
> 	at org.apache.avro.specific.TestRecordWithDecimalFieldWithDefault$Builder.build(TestRecordWithDecimalFieldWithDefault.java:239)
> 	at org.apache.avro.specific.TestSpecificLogicalTypes.testRecordWithDecimalLogicalTypeWithDefault(TestSpecificLogicalTypes.java:123)
> 	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> 	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
> 	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
> 	at java.lang.reflect.Method.invoke(Method.java:498)
> 	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
> 	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
> 	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
> 	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
> 	at org.junit.rules.ExternalResource$1.evaluate(ExternalResource.java:48)
> 	at org.junit.rules.RunRules.evaluate(RunRules.java:20)
> 	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
> 	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
> 	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
> 	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
> 	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
> 	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
> 	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
> 	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
> 	at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
> 	at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
> 	at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:119)
> 	at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:42)
> 	at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:234)
> 	at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:74)
> 	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> 	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
> 	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
> 	at java.lang.reflect.Method.invoke(Method.java:498)
> 	at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)
> Caused by: org.apache.avro.AvroRuntimeException: Cannot convert 8083333.60:BigDecimal:
expected generic type
> 	at org.apache.avro.Conversions.convertToLogicalType(Conversions.java:172)
> 	at org.apache.avro.data.RecordBuilderBase.defaultValue(RecordBuilderBase.java:159)
> 	at org.apache.avro.specific.TestRecordWithDecimalFieldWithDefault$Builder.build(TestRecordWithDecimalFieldWithDefault.java:236)
> 	... 30 more
> Caused by: java.lang.ClassCastException: java.math.BigDecimal cannot be cast to java.nio.ByteBuffer
> 	at org.apache.avro.Conversions.convertToLogicalType(Conversions.java:162)
> 	... 32 more
> {code}



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Mime
View raw message