datanerds-io / avropatch Goto Github PK
View Code? Open in Web Editor NEWAvro implementation of a PATCH payload as defined for JSON in RFC 6902.
License: Apache License 2.0
Avro implementation of a PATCH payload as defined for JSON in RFC 6902.
License: Apache License 2.0
Order of method calls to PatchMapper.builder()
impacts deserialization:
PatchMapper serializer = PatchMapper.builder()
.withType(Bimmel.class)
.with(PatchMapper.arrayBuilder()
.withAvroPrimitives()
.withCustomTypes()
.build())
.nullable()
.withAvroPrimitives()
.build();
PatchMapper deserializer = PatchMapper.builder()
.withType(Bimmel.class)
.with(PatchMapper.arrayBuilder()
.withCustomTypes()
.withAvroPrimitives()
.build())
.nullable()
.withAvroPrimitives()
.build();
byte[] bytes = serializer.toBytes(patch);
assertThat(patch, is(equalTo(deserializer.toPatch(bytes))));
java.lang.ArrayIndexOutOfBoundsException: -27
at org.apache.avro.io.parsing.Symbol$Alternative.getSymbol(Symbol.java:416)
at org.apache.avro.io.ResolvingDecoder.doAction(ResolvingDecoder.java:290)
at org.apache.avro.io.parsing.Parser.advance(Parser.java:88)
at org.apache.avro.io.ResolvingDecoder.readIndex(ResolvingDecoder.java:267)
at org.apache.avro.generic.GenericDatumReader.readWithoutConversion(GenericDatumReader.java:178)
at org.apache.avro.reflect.ReflectDatumReader.readCollection(ReflectDatumReader.java:219)
at org.apache.avro.reflect.ReflectDatumReader.readArray(ReflectDatumReader.java:137)
at org.apache.avro.generic.GenericDatumReader.readWithoutConversion(GenericDatumReader.java:176)
at org.apache.avro.generic.GenericDatumReader.read(GenericDatumReader.java:152)
at org.apache.avro.generic.GenericDatumReader.readWithoutConversion(GenericDatumReader.java:178)
at org.apache.avro.reflect.ReflectDatumReader.readField(ReflectDatumReader.java:302)
at org.apache.avro.generic.GenericDatumReader.readRecord(GenericDatumReader.java:230)
at org.apache.avro.generic.GenericDatumReader.readWithoutConversion(GenericDatumReader.java:174)
at org.apache.avro.generic.GenericDatumReader.read(GenericDatumReader.java:152)
at org.apache.avro.generic.GenericDatumReader.readWithoutConversion(GenericDatumReader.java:178)
at org.apache.avro.reflect.ReflectDatumReader.readCollection(ReflectDatumReader.java:219)
at org.apache.avro.reflect.ReflectDatumReader.readArray(ReflectDatumReader.java:137)
at org.apache.avro.generic.GenericDatumReader.readWithoutConversion(GenericDatumReader.java:176)
at org.apache.avro.reflect.ReflectDatumReader.readField(ReflectDatumReader.java:302)
at org.apache.avro.generic.GenericDatumReader.readRecord(GenericDatumReader.java:230)
at org.apache.avro.generic.GenericDatumReader.readWithoutConversion(GenericDatumReader.java:174)
at org.apache.avro.generic.GenericDatumReader.read(GenericDatumReader.java:152)
at org.apache.avro.generic.GenericDatumReader.read(GenericDatumReader.java:144)
at io.datanerds.avropatch.serialization.PatchMapper.toPatch(PatchMapper.java:46)
at io.datanerds.avropatch.serialization.PatchMapperTest.unionTest(PatchMapperTest.java:111)
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.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)
It looks like the order within Avro's schema union is crucial for resolving the types. Need to be deterministic on creation of the union list (e.g. alphabetical order).
As discussed in #6: Add equals
and hashCode
to Operation
classes in order to remove boilerplate test code which itself needs to be tested to ensure testing works as expected.
While working on this library the Avro schema may evolve. We should track the changes and version them.
Currently avropatch supports headers and the change set out of the box. Let's add some more items as first-class citizens to the Patch
POJO:
timestamp
to specify when the PATCH request was maderesource
representing the object to be updated by PATCH callversion
Let's start versioning avropatchHandling of parse
and of
is confusing since both take string arguments, but behave differently:
Path.of("/com")
results in
io.datanerds.avropatch.exception.InvalidReferenceTokenException: /com is not a valid JSON path
We would like to have some convenience accessor methods for the Patch
class.
Patch#getOperations()
. Let's add some methods to access them directly (e.g. Patch#size()
, Patch#stream()
, Patch#getOperation(int index)
etc.)Patch#getHeader(String name)
would ease accessing a specific header, because right now, there's an indirection as well.Replace value schemata in io.datanerds.avropatch.operation.DefaultSchema
with a solution loading them from JSON files.
Since we have so many versions of the constructor now, given 3 arguments it would be a good idea to use a builder or factory methods instead.
In general there should be only one assertion per test method to avoid hiding further assertion failures after the first failing assertion which effectively may hide the real severity of the problem.
See http://blog.jayfields.com/2007/06/testing-one-assertion-per-test.html
Also reoccurring words in several test methods are a sign that the tests should be grouped together, i.e. with @Enclosed. Since that feature is still experimental let's discuss what we want to do.
(See comments for PR #14 )
Java's generic type used to define the value part of the Add
, Replace
and Test
operation is not restricted to supported value types. Let's implement a mechanism to enable sanity checks on those value instances.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.