Skip to content

Commit

Permalink
Account for references in records
Browse files Browse the repository at this point in the history
Before reversing (for proper compilation order), use distinct in order to account for references between field schemas
  • Loading branch information
julianpeeters committed Jan 22, 2025
1 parent c3656e5 commit 90330e6
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ _Note:_ Currently [Treehugger](http://eed3si9n.com/treehugger/comments.html#Scal

##### Get the dependency with:

"com.julianpeeters" %% "avrohugger-core" % "2.11.0"
"com.julianpeeters" %% "avrohugger-core" % "2.11.1"


##### Description:
Expand Down Expand Up @@ -211,7 +211,7 @@ namespace rewritten. Multiple conflicting wildcards are not permitted.

##### Get the dependency with:

"com.julianpeeters" %% "avrohugger-filesorter" % "2.11.0"
"com.julianpeeters" %% "avrohugger-filesorter" % "2.11.1"


##### Description:
Expand All @@ -231,17 +231,17 @@ To ensure dependent schemas are compiled in the proper order (thus avoiding `org
#### `avrohugger-tools`


Download the avrohugger-tools jar for Scala [2.12](https://search.maven.org/remotecontent?filepath=com/julianpeeters/avrohugger-tools_2.12/2.11.0/avrohugger-tools_2.12-2.11.0-assembly.jar), or Scala [2.13](https://search.maven.org/remotecontent?filepath=com/julianpeeters/avrohugger-tools_2.13/2.11.0/avrohugger-tools_2.13-2.11.0-assembly.jar) (>30MB!) and use it like the avro-tools jar `Usage: [-string] (schema|protocol|datafile) input... outputdir`:
Download the avrohugger-tools jar for Scala [2.12](https://search.maven.org/remotecontent?filepath=com/julianpeeters/avrohugger-tools_2.12/2.11.1/avrohugger-tools_2.12-2.11.1-assembly.jar), or Scala [2.13](https://search.maven.org/remotecontent?filepath=com/julianpeeters/avrohugger-tools_2.13/2.11.1/avrohugger-tools_2.13-2.11.1-assembly.jar) (>30MB!) and use it like the avro-tools jar `Usage: [-string] (schema|protocol|datafile) input... outputdir`:


* `generate` generates Scala case class definitions:

`java -jar /path/to/avrohugger-tools_2.12-2.11.0-assembly.jar generate schema user.avsc . `
`java -jar /path/to/avrohugger-tools_2.12-2.11.1-assembly.jar generate schema user.avsc . `


* `generate-specific` generates definitions that extend Avro's `SpecificRecordBase`:

`java -jar /path/to/avrohugger-tools_2.12-2.11.0-assembly.jar generate-specific schema user.avsc . `
`java -jar /path/to/avrohugger-tools_2.12-2.11.1-assembly.jar generate-specific schema user.avsc . `


## Warnings
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ private[avrohugger] class FileGenerator {
val topLevelSchemas: List[Schema] =
NestedSchemaExtractor.getNestedSchemas(schema, schemaStore, typeMatcher)
// most-nested classes processed first
topLevelSchemas.reverse.distinct.foreach(schema => {
topLevelSchemas.distinct.reverse.foreach(schema => {
// pass in the top-level schema's namespace if the nested schema has none
val ns = DependencyInspector.getReferredNamespace(schema) orElse topNS
format.compile(classStore, ns, Left(schema), outDir, schemaStore, typeMatcher, restrictedFields, targetScalaPartialVersion)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ private[avrohugger] class StringGenerator {
val topLevels =
NestedSchemaExtractor.getNestedSchemas(schema, schemaStore, typeMatcher)
//reversed to process nested classes first
val compilationUnits = topLevels.reverse.distinct.flatMap(schema => {
val compilationUnits = topLevels.distinct.reverse.flatMap(schema => {
// pass in the top-level schema's namespace if the nested schema has none
val maybeNS = DependencyInspector.getReferredNamespace(schema).orElse(maybeNamespace)
format.asCompilationUnits(
Expand Down
4 changes: 2 additions & 2 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ lazy val avroVersion = "1.11.4"

lazy val commonSettings = Seq(
organization := "com.julianpeeters",
version := "2.11.0",
version := "2.11.1",
ThisBuild / versionScheme := Some("semver-spec"),
scalacOptions ++= Seq("-unchecked", "-deprecation", "-feature"),
Test / scalacOptions ++= Seq("-Yrangepos"),
scalaVersion := "3.3.4",
crossScalaVersions := Seq("2.12.20", "2.13.15", scalaVersion.value),
crossScalaVersions := Seq("2.12.20", "2.13.16", scalaVersion.value),
libraryDependencies += "org.apache.avro" % "avro" % avroVersion,
libraryDependencies += "org.apache.avro" % "avro-compiler" % avroVersion,
libraryDependencies := { CrossVersion.partialVersion(scalaVersion.value) match {
Expand Down

0 comments on commit 90330e6

Please sign in to comment.