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

Update Avro version to 1.12.0 #195

Open
wants to merge 8 commits into
base: main
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
32 changes: 20 additions & 12 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,27 @@ on:
branches: [ main ]

jobs:
build:
name: Build and Test
test:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest]
scala: [2.13.11, 2.12.18]
java: [zulu@1.8, zulu@1.11, zulu@1.17]
include:
- os: ubuntu-latest
java: 11
- os: ubuntu-latest
java: 17
- os: ubuntu-latest
java: 21
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3.0.2
- name: Set up Java
uses: olafurpg/setup-scala@v13
with:
java-version: ${{ matrix.java }}
- name: Run tests
run: sbt ++${{ matrix.scala }} test
- name: Checkout
uses: actions/checkout@v4
- name: Setup JDK
uses: actions/setup-java@v3
with:
distribution: temurin
java-version: ${{ matrix.java }}
cache: sbt
- name: Build and test
shell: bash
run: sbt -v +test
28 changes: 18 additions & 10 deletions avrohugger-core/src/main/scala/input/parsers/FileInputParser.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import stores.ClassStore
import org.apache.avro.{Protocol, Schema}
import org.apache.avro.Schema.Parser
import org.apache.avro.Schema.Type.{ENUM, FIXED, RECORD, UNION}
import org.apache.avro.compiler.idl.Idl
import org.apache.avro.generic.{GenericDatumReader, GenericRecord}
import org.apache.avro.file.DataFileReader
import org.apache.avro.SchemaParseException
import org.apache.avro.generic.{GenericDatumReader, GenericRecord}
import org.apache.avro.idl.IdlReader
import org.apache.avro.{AvroTypeException, SchemaParseException}

import java.io.File
import scala.jdk.CollectionConverters._
Expand Down Expand Up @@ -48,28 +48,36 @@ class FileInputParser {
sys.error(s"Can't redefine: ${nonEqualElements.mkString(",")} in $infile")
} else {
if (commonElements.isEmpty) {
val _ = parser.addTypes(tempParser.getTypes)
val _ = parser.addTypes(tempParser.getTypes.values)
} else {
val missingTypes = tempParser.getTypes().keySet().asScala.diff(parser.getTypes().keySet().asScala)
val _ = parser.addTypes(missingTypes.map { t =>
t -> tempParser.getTypes().get(t)
}.toMap.asJava)
}.toMap.asJava.values)
}
}
}

def mightBeRecoverable(e: SchemaParseException): Boolean = {
val msg = e.getMessage
msg.contains("Undefined name:") || msg.contains("is not a defined name")
msg.contains("Undefined name:") || msg.contains("is not a defined name")
}

def mightBeRecoverableType(e: AvroTypeException): Boolean = {
val msg = e.getMessage
msg.contains("Undefined schema:")
}

def tryParse(inFile: File, parser: Schema.Parser): List[Schema] = {
val tempParser = new Parser()
val parsed = Try(tempParser.parse(inFile)).map(schema => {
copySchemas(tempParser, parser)
schema
}).recoverWith { case e: SchemaParseException if mightBeRecoverable(e) =>
Try(parser.parse(inFile))
}).recoverWith {
case e: AvroTypeException if mightBeRecoverableType(e) =>
Try(parser.parse(inFile))
case e: SchemaParseException if mightBeRecoverable(e) =>
Try(parser.parse(inFile))
}
unUnion(parsed.get)// throw the avro parse exception if Failure
}
Expand All @@ -89,8 +97,8 @@ class FileInputParser {
val protocol = Protocol.parse(infile)
List(Right(protocol))
case "avdl" =>
val idlParser = new Idl(infile, classLoader)
val protocol = idlParser.CompilationUnit()
val idl = new IdlReader().parse(infile.toPath())
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we need a parse method that accepts our classLoader, as was available for the Idl constructor

val protocol = idl.getProtocol()
/**
* IDLs may refer to types imported from another file. When converted
* to protocols, the imported types that share the IDL's namespace
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import org.apache.avro.Protocol
import org.apache.avro.Schema
import org.apache.avro.Schema.Parser
import org.apache.avro.SchemaParseException
import org.apache.avro.compiler.idl.Idl
import org.apache.avro.idl.IdlReader
import org.apache.avro.compiler.idl.ParseException

import scala.jdk.CollectionConverters._
Expand All @@ -22,7 +22,8 @@ class StringInputParser {

def getSchemaOrProtocols(
inputString: String,
schemaStore: SchemaStore): List[Either[Schema, Protocol]] = {
schemaStore: SchemaStore
): List[Either[Schema, Protocol]] = {

def trySchema(str: String): List[Either[Schema, Protocol]] = {
try {
Expand All @@ -48,13 +49,13 @@ class StringInputParser {
try {
val bytes = str.getBytes(Charset.forName("UTF-8"))
val inStream = new java.io.ByteArrayInputStream(bytes)
val idlParser = new Idl(inStream)
val protocol = idlParser.CompilationUnit()
val idlParser = new IdlReader().parse(inStream)
val protocol = idlParser.getProtocol()
List(Right(protocol))
}
catch {
case e: ParseException => sys.error(s"Unable to parse: ${e}")
case npe: NullPointerException => sys.error("Imports not supported in String IDLs, only avdl files.")
case e: SchemaParseException => sys.error("Imports not supported in String IDLs, only avdl files.")
case unknown: Throwable => sys.error("Unexpected exception: " + unknown)
}
}
Expand Down
11 changes: 6 additions & 5 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
lazy val avroVersion = "1.11.3"
lazy val avroVersion = "1.12.0"

lazy val commonSettings = Seq(
organization := "com.julianpeeters",
version := "2.8.3",
version := "2.9.0-SNAPSHOT",
ThisBuild / versionScheme := Some("semver-spec"),
scalacOptions ++= Seq("-unchecked", "-deprecation", "-feature"),
Test / scalacOptions ++= Seq("-Yrangepos"),
scalaVersion := "3.3.1",
crossScalaVersions := Seq("2.12.18", "2.13.12", scalaVersion.value),
scalaVersion := "3.3.3",
crossScalaVersions := Seq("2.12.19", "2.13.14", scalaVersion.value),
libraryDependencies += "org.apache.avro" % "avro" % avroVersion,
libraryDependencies += "org.apache.avro" % "avro-compiler" % avroVersion,
libraryDependencies += "org.apache.avro" % "avro-idl" % avroVersion,
libraryDependencies := { CrossVersion.partialVersion(scalaVersion.value) match {
case Some((2, scalaMinor)) if scalaMinor < 13 =>
// for implementing SpecificRecord from standard case class definitions
Expand All @@ -20,7 +21,7 @@ lazy val commonSettings = Seq(
}},
libraryDependencies := { CrossVersion.partialVersion(scalaVersion.value) match {
case Some((2, scalaMinor)) if scalaMinor < 13 =>
libraryDependencies.value ++ Seq("org.scala-lang.modules" %% "scala-collection-compat" % "2.11.0")
libraryDependencies.value ++ Seq("org.scala-lang.modules" %% "scala-collection-compat" % "2.12.0")
case _ =>
libraryDependencies.value
}},
Expand Down
2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version=1.9.8
sbt.version=1.10.1
Loading