You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@avro.apache.org by "ASF GitHub Bot (JIRA)" <ji...@apache.org> on 2017/10/05 13:04:00 UTC
[jira] [Commented] (AVRO-2086) Can't create specific record with a
single Decimal field with default value
[ https://issues.apache.org/jira/browse/AVRO-2086?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16192840#comment-16192840 ]
ASF GitHub Bot commented on AVRO-2086:
--------------------------------------
GitHub user nandorKollar opened a pull request:
https://github.com/apache/avro/pull/255
AVRO-2086: Can't create specific record with a single Decimal field w…
…ith default value
You can merge this pull request into a Git repository by running:
$ git pull https://github.com/nandorKollar/avro AVRO-2086
Alternatively you can review and apply these changes as the patch at:
https://github.com/apache/avro/pull/255.patch
To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:
This closes #255
----
commit 70144dd136374520da0686f2a02dc3c7bae650fe
Author: Nandor Kollar <nk...@cloudera.com>
Date: 2017-10-05T13:01:34Z
AVRO-2086: Can't create specific record with a single Decimal field with default value
----
> 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
>
> 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)