Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed bug with Nested Avro Composition #4

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions example-nested/nested-composition.dot
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
digraph "Simple Composition" {
rankdir="BT";
nodesep=1;
node [shape=box,style="rounded,filled",penwidth=2.0,color=black,fillcolor=grey90];

ExampleMetadata [label="ExampleMetadata(timestamp: long, name: String, version: String)"];
ExampleSubscription [label="ExampleSubscription(raw: String, mimetype: String, subscriptionMetadata: ExampleMetadata)"];
ExampleToken [label="ExampleToken(raw: String, origin: String, metadata: ExampleMetadata, metadataBasic: ExampleMetadata, metadata: ExampleMetadata, subscription: ExampleSubscription)"];

ExampleMetadata -> ExampleToken [label="metadata"];
ExampleMetadata -> ExampleToken [label="metadataBasic"];

ExampleSubscription -> ExampleToken [label="subscription"];

ExampleMetadata -> ExampleSubscription [label="subscriptionMetadata"];

}
Binary file added example-nested/nested-composition.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 22 additions & 0 deletions example-nested/schemas/avro/examples/Metadata.avsc
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"type": "record",
"namespace": "com.oivanov.examples",
"name": "ExampleMetadata",
"fields": [
{
"name": "timestamp",
"type": {
"type": "long",
"logicalType": "timestamp-millis"
}
},
{
"name": "source",
"type": "string"
},
{
"name": "version",
"type": "string"
}
]
}
23 changes: 23 additions & 0 deletions example-nested/schemas/avro/examples/Subscription.avsc
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"type": "record",
"name": "ExampleSubscription",
"namespace": "com.oivanov.examples",
"fields": [
{
"name": "raw",
"type": "string"
},
{
"name": "origin",
"type": ["string", "null"]
},
{
"name": "mimetype",
"type": "string"
},
{
"name": "metadata",
"type": "com.oivanov.examples.ExampleMetadata"
}
]
}
27 changes: 27 additions & 0 deletions example-nested/schemas/avro/examples/Token.avsc
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"type": "record",
"name": "ExampleToken",
"namespace": "com.oivanov.examples",
"fields": [
{
"name": "raw",
"type": "string"
},
{
"name": "origin",
"type": "string"
},
{
"name": "metadataBasic",
"type": "com.oivanov.examples.ExampleMetadata"
},
{
"name": "metadata",
"type": "com.oivanov.examples.ExampleMetadata"
},
{
"name": "subscription",
"type": "com.oivanov.examples.ExampleSubscription"
}
]
}
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>com.michalklempa</groupId>
<artifactId>avro-compose</artifactId>
<version>0.0.2-SNAPSHOT</version>
<version>0.0.3-SNAPSHOT</version>
<packaging>jar</packaging>

<name>Avro Compose</name>
Expand Down Expand Up @@ -34,7 +34,7 @@

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<avro.version>1.9.2</avro.version>
<avro.version>1.11.3</avro.version>
<java.version>1.8</java.version>
<maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>
Expand Down
6 changes: 5 additions & 1 deletion src/main/java/com/michalklempa/avro/compose/SchemaFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
import java.util.Map;
import java.util.Set;

import com.google.common.collect.MapDifference;
import com.google.common.collect.Maps;

public interface SchemaFile {
String name();

Expand Down Expand Up @@ -132,7 +135,8 @@ public static Attempt attempt(Attempt attempt, SchemaFile.Parsed dependency) {
public static Parsed parsed(Attempt schemaFile) throws IOException {
Schema.Parser parser = new Schema.Parser();
for (SchemaFile.Parsed dependency : schemaFile.dependencies()) {
parser.addTypes(dependency.types());
MapDifference<String, Schema> difference = Maps.difference(parser.getTypes(), dependency.types());
parser.addTypes(difference.entriesOnlyOnRight());
}
try (InputStream is = new FileInputStream(schemaFile.filename())) {
Set<String> typeNames = new HashSet<>();
Expand Down