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 to 1.12.0 #190

Merged
merged 5 commits into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
20 changes: 2 additions & 18 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,14 @@ jobs:
matrix:
os: [ubuntu-latest]
scala: [2.12.19]
java: [temurin@8, temurin@11]
java: [temurin@11]
runs-on: ${{ matrix.os }}
steps:
- name: Checkout current branch (full)
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Setup Java (temurin@8)
if: matrix.java == 'temurin@8'
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: 8
cache: sbt

- name: Setup Java (temurin@11)
if: matrix.java == 'temurin@11'
uses: actions/setup-java@v4
Expand Down Expand Up @@ -71,22 +63,14 @@ jobs:
matrix:
os: [ubuntu-latest]
scala: [2.12.19]
java: [temurin@8]
java: [temurin@11]
runs-on: ${{ matrix.os }}
steps:
- name: Checkout current branch (full)
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Setup Java (temurin@8)
if: matrix.java == 'temurin@8'
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: 8
cache: sbt

- name: Setup Java (temurin@11)
if: matrix.java == 'temurin@11'
uses: actions/setup-java@v4
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ addSbtPlugin("com.github.sbt" % "sbt-avro" % "3.4.3")
// Java sources compiled with one version of Avro might be incompatible with a
// different version of the Avro library. Therefore we specify the compiler
// version here explicitly.
libraryDependencies += "org.apache.avro" % "avro-compiler" % "1.11.3"
libraryDependencies += "org.apache.avro" % "avro-compiler" % "1.12.0"
```

Add the library dependency to `build.sbt`:
Expand Down
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ ThisBuild / githubWorkflowBuild := Seq(
WorkflowStep.Sbt(name = Some("Build project"), commands = List("compile", "test", "scripted"))
)
ThisBuild / githubWorkflowTargetBranches := Seq("main")
ThisBuild / githubWorkflowJavaVersions := Seq(JavaSpec.temurin("8"), JavaSpec.temurin("11"))
ThisBuild / githubWorkflowJavaVersions := Seq(JavaSpec.temurin("11"))
ThisBuild / githubWorkflowTargetTags := Seq("v*")
ThisBuild / githubWorkflowPublishTargetBranches := Seq(RefPredicate.StartsWith(Ref.Tag("v")))
ThisBuild / githubWorkflowPublish := Seq(WorkflowStep.Sbt(
Expand Down
2 changes: 1 addition & 1 deletion project/Dependencies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import sbt._
object Dependencies {

object Versions {
val Avro = "1.11.3"
val Avro = "1.12.0"
val Specs2 = "4.20.4"
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.github.sbt.avro.mojo;

import org.apache.avro.AvroTypeException;
import org.apache.avro.Schema;
import org.apache.avro.SchemaParseException;
import org.apache.avro.compiler.specific.SpecificCompiler;
Expand Down Expand Up @@ -122,7 +123,7 @@ private boolean tryCompile(AvroFileRef src, File outputDirectory) {
try {
schema = schemaParser.parse(src.getFile());
validateParsedSchema(src, schema);
} catch (SchemaParseException e) {
} catch (SchemaParseException | AvroTypeException e) {
RustedBones marked this conversation as resolved.
Show resolved Hide resolved
schemaParser = successfulSchemaParser;
compileExceptions.put(src, e);
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,14 @@ package com.github.sbt.avro
import com.github.sbt.avro.mojo.SchemaParserBuilder
import org.apache.avro.Schema

import scala.collection.JavaConverters._

case class DefaultSchemaParserBuilder(types: Iterable[Schema],
validate: Boolean,
validateDefaults: Boolean)
extends SchemaParserBuilder {

override def build(): Schema.Parser = {
val parser = new Schema.Parser
parser.addTypes(types.map(el => el.getFullName() -> el).toMap.asJava)
parser.setValidate(validate)
parser.setValidateDefaults(validateDefaults)
parser
}
}

object DefaultSchemaParserBuilder {
def default(): DefaultSchemaParserBuilder = {
template(new Schema.Parser())
}

def template(template: Schema.Parser): DefaultSchemaParserBuilder = {
DefaultSchemaParserBuilder(
template.getTypes.values().asScala,
template.getValidate,
template.getValidateDefaults
)
def default(): SchemaParserBuilder = {
val Array(1, minor, _) = classOf[Schema].getPackage.getImplementationVersion.split("\\.").take(3).map(_.toInt)
if (minor >= 12) {
NameValidatorSchemaParserBuilder()
} else {
LegacySchemaParserBuilder()
}
}
}
46 changes: 46 additions & 0 deletions src/main/scala/com/github/sbt/avro/LegacySchemaParserBuilder.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package com.github.sbt.avro

import com.github.sbt.avro.mojo.SchemaParserBuilder
import org.apache.avro.Schema

import scala.annotation.nowarn
import scala.collection.JavaConverters.*

// used until avro 1.11
// for avro 2.12+ use NameValidatorSchemaParserBuilder
case class LegacySchemaParserBuilder(
types: Iterable[Schema] = LegacySchemaParserBuilder.DefaultTypes,
validate: Boolean = LegacySchemaParserBuilder.DefaultValidate,
validateDefaults: Boolean = LegacySchemaParserBuilder.DefaultValidateDefaults)
extends SchemaParserBuilder {

override def build(): Schema.Parser = {
val parser = new Schema.Parser
// addTypes(Map<String, Schema> types) is the only API available in 1.8
parser.addTypes(types.map(el => el.getFullName -> el).toMap.asJava): @nowarn
LegacySchemaParserBuilder.setValidate(parser)(validate)
parser.setValidateDefaults(validateDefaults)
parser
}
}

object LegacySchemaParserBuilder {
// validate hase been removed in 1.12 in favor of a NameValidator
private def setValidate(parser: Schema.Parser)(validate: Boolean): Schema.Parser =
classOf[Schema.Parser]
.getMethod("setValidate", classOf[Boolean])
.invoke(parser, validate: java.lang.Boolean)
.asInstanceOf[Schema.Parser]

private def getValidate(parser: Schema.Parser): Boolean =
classOf[Schema.Parser]
.getMethod("getValidate")
.invoke(parser)
.asInstanceOf[Boolean]

private val defaultParser = new Schema.Parser

private val DefaultTypes: Iterable[Schema] = defaultParser.getTypes.values().asScala
private val DefaultValidate: Boolean = getValidate(defaultParser)
private val DefaultValidateDefaults: Boolean = defaultParser.getValidateDefaults
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.github.sbt.avro

import com.github.sbt.avro.mojo.SchemaParserBuilder
import org.apache.avro.{NameValidator, Schema}

import scala.collection.JavaConverters._

case class NameValidatorSchemaParserBuilder(
types: Iterable[Schema] = Iterable.empty,
validation: NameValidator = NameValidator.UTF_VALIDATOR,
validateDefaults: Boolean = true
) extends SchemaParserBuilder {

override def build(): Schema.Parser = {
val parser = new Schema.Parser(validation)
parser.addTypes(types.asJava)
parser.setValidateDefaults(validateDefaults)
}
}
2 changes: 1 addition & 1 deletion src/sbt-test/sbt-avro/avscparser/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import org.apache.avro.Schema
name := "avscparser-test"
scalaVersion := "2.13.11"
libraryDependencies ++= Seq(
"org.apache.avro" % "avro" % "1.11.3",
"org.apache.avro" % "avro" % avroCompilerVersion,
"org.specs2" %% "specs2-core" % "4.20.4" % Test
)
avroSchemaParserBuilder := AnnotateWithArtifactSchemaParser
Expand Down
2 changes: 1 addition & 1 deletion src/sbt-test/sbt-avro/avscparser/project/plugins.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ sys.props.get("plugin.version") match {
|Specify this property using the scriptedLaunchOpts -D.""".stripMargin)
}

libraryDependencies += "org.apache.avro" % "avro-compiler" % "1.11.3"
libraryDependencies += "org.apache.avro" % "avro-compiler" % "1.12.0"
1 change: 0 additions & 1 deletion src/sbt-test/sbt-avro/basic_1.10/project/build.properties

This file was deleted.

1 change: 1 addition & 0 deletions src/sbt-test/sbt-avro/basic_1.10/project/build.properties
2 changes: 1 addition & 1 deletion src/sbt-test/sbt-avro/basic_1.10/test
3 changes: 3 additions & 0 deletions src/sbt-test/sbt-avro/basic_1.11/build.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
name := "basic-test"
scalaVersion := "2.13.11"
libraryDependencies += "org.apache.avro" % "avro" % avroCompilerVersion
1 change: 1 addition & 0 deletions src/sbt-test/sbt-avro/basic_1.11/project/build.properties
6 changes: 6 additions & 0 deletions src/sbt-test/sbt-avro/basic_1.11/project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
sys.props.get("plugin.version") match {
case Some(x) => addSbtPlugin("com.github.sbt" % "sbt-avro" % x)
case _ => sys.error("""|The system property 'plugin.version' is not defined.
|Specify this property using the scriptedLaunchOpts -D.""".stripMargin)
}
libraryDependencies += "org.apache.avro" % "avro-compiler" % "1.11.3" // scala-steward:off
1 change: 1 addition & 0 deletions src/sbt-test/sbt-avro/basic_1.11/src
42 changes: 42 additions & 0 deletions src/sbt-test/sbt-avro/basic_1.11/test
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
> set avroSchemaParserBuilder := com.github.sbt.avro.LegacySchemaParserBuilder(validateDefaults = false)
> avroGenerate

$ exists target/scala-2.13/src_managed/compiled_avro/main/com/github/sbt/avro/test/A.java
$ exists target/scala-2.13/src_managed/compiled_avro/main/com/github/sbt/avro/test/B.java
$ exists target/scala-2.13/src_managed/compiled_avro/main/com/github/sbt/avro/test/C.java
$ exists target/scala-2.13/src_managed/compiled_avro/main/com/github/sbt/avro/test/D.java
$ exists target/scala-2.13/src_managed/compiled_avro/main/com/github/sbt/avro/test/E.java
$ exists target/scala-2.13/src_managed/compiled_avro/main/com/github/sbt/avro/test/_A.java
$ exists target/scala-2.13/src_managed/compiled_avro/main/com/github/sbt/avro/test/_B.java
$ exists target/scala-2.13/src_managed/compiled_avro/main/com/github/sbt/avro/test/_C.java
$ exists target/scala-2.13/src_managed/compiled_avro/main/com/github/sbt/avro/test/_D.java
$ exists target/scala-2.13/src_managed/compiled_avro/main/com/github/sbt/avro/test/_E.java

> compile

$ exists target/scala-2.13/classes/com/github/sbt/avro/test/A.class
$ exists target/scala-2.13/classes/com/github/sbt/avro/test/B.class
$ exists target/scala-2.13/classes/com/github/sbt/avro/test/C.class
$ exists target/scala-2.13/classes/com/github/sbt/avro/test/D.class
$ exists target/scala-2.13/classes/com/github/sbt/avro/test/E.class
$ exists target/scala-2.13/classes/com/github/sbt/avro/test/_A.class
$ exists target/scala-2.13/classes/com/github/sbt/avro/test/_B.class
$ exists target/scala-2.13/classes/com/github/sbt/avro/test/_C.class
$ exists target/scala-2.13/classes/com/github/sbt/avro/test/_D.class
$ exists target/scala-2.13/classes/com/github/sbt/avro/test/_E.class

> Test/compile

$ exists target/scala-2.13/src_managed/compiled_avro/test/com/github/sbt/avro/test/X.java
$ exists target/scala-2.13/src_managed/compiled_avro/test/com/github/sbt/avro/test/Y.java
$ exists target/scala-2.13/src_managed/compiled_avro/test/com/github/sbt/avro/test/Z.java
$ exists target/scala-2.13/test-classes/com/github/sbt/avro/test/X.class
$ exists target/scala-2.13/test-classes/com/github/sbt/avro/test/Y.class
$ exists target/scala-2.13/test-classes/com/github/sbt/avro/test/Z.class

> clean

> set avroSchemaParserBuilder := com.github.sbt.avro.LegacySchemaParserBuilder(validateDefaults = true)

# should fail because f.avsc has invalid default value
-> avroGenerate
5 changes: 4 additions & 1 deletion src/sbt-test/sbt-avro/basic_1.8/build.sbt
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
name := "basic-test"
scalaVersion := "2.13.11"
libraryDependencies += "org.apache.avro" % "avro" % avroCompilerVersion
libraryDependencies ++= Seq(
"org.apache.avro" % "avro" % avroCompilerVersion,
"joda-time" % "joda-time" % "2.7" // marked as optional in avro pom
)
1 change: 0 additions & 1 deletion src/sbt-test/sbt-avro/basic_1.8/project/build.properties

This file was deleted.

1 change: 1 addition & 0 deletions src/sbt-test/sbt-avro/basic_1.8/project/build.properties
2 changes: 1 addition & 1 deletion src/sbt-test/sbt-avro/basic_1.8/test
5 changes: 4 additions & 1 deletion src/sbt-test/sbt-avro/basic_1.9/build.sbt
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
name := "basic-test"
scalaVersion := "2.13.11"
libraryDependencies += "org.apache.avro" % "avro" % avroCompilerVersion
libraryDependencies ++= Seq(
"org.apache.avro" % "avro" % avroCompilerVersion,
"joda-time" % "joda-time" % "2.10.1" // marked as optional in avro pom
)
1 change: 0 additions & 1 deletion src/sbt-test/sbt-avro/basic_1.9/project/build.properties

This file was deleted.

1 change: 1 addition & 0 deletions src/sbt-test/sbt-avro/basic_1.9/project/build.properties
2 changes: 1 addition & 1 deletion src/sbt-test/sbt-avro/basic_1.9/test
2 changes: 1 addition & 1 deletion src/sbt-test/sbt-avro/basic_current/project/plugins.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ sys.props.get("plugin.version") match {
|Specify this property using the scriptedLaunchOpts -D.""".stripMargin)
}

libraryDependencies += "org.apache.avro" % "avro-compiler" % "1.11.3"
libraryDependencies += "org.apache.avro" % "avro-compiler" % "1.12.0"
38 changes: 38 additions & 0 deletions src/sbt-test/sbt-avro/basic_current/src/main/avro/logicalType.avsc
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"name": "LogicalTypesTest",
"namespace": "org.apache.parquet.avro",
"doc": "Record for testing logical types",
"type": "record",
"fields": [
{
"name": "timestamp",
"type": {
"type": "long",
"logicalType": "timestamp-millis"
}
},
{
"name": "local_date_time",
"type": {
"name": "LocalDateTimeTest",
"type": "record",
"fields": [
{
"name": "date",
"type": {
"type": "int",
"logicalType": "date"
}
},
{
"name": "time",
"type": {
"type": "int",
"logicalType": "time-millis"
}
}
]
}
}
]
}
6 changes: 3 additions & 3 deletions src/sbt-test/sbt-avro/basic_current/test
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
> set avroSchemaParserBuilder := com.github.sbt.avro.DefaultSchemaParserBuilder.default().copy(validateDefaults = false)
> set avroSchemaParserBuilder := com.github.sbt.avro.NameValidatorSchemaParserBuilder(validateDefaults = false)
> avroGenerate

$ exists target/scala-2.13/src_managed/compiled_avro/main/com/github/sbt/avro/test/A.java
Expand All @@ -25,7 +25,7 @@ $ exists target/scala-2.13/classes/com/github/sbt/avro/test/_C.class
$ exists target/scala-2.13/classes/com/github/sbt/avro/test/_D.class
$ exists target/scala-2.13/classes/com/github/sbt/avro/test/_E.class

> test:compile
> Test/compile

$ exists target/scala-2.13/src_managed/compiled_avro/test/com/github/sbt/avro/test/X.java
$ exists target/scala-2.13/src_managed/compiled_avro/test/com/github/sbt/avro/test/Y.java
Expand All @@ -36,7 +36,7 @@ $ exists target/scala-2.13/test-classes/com/github/sbt/avro/test/Z.class

> clean

> set avroSchemaParserBuilder := com.github.sbt.avro.DefaultSchemaParserBuilder.default().copy(validateDefaults = true)
> set avroSchemaParserBuilder := com.github.sbt.avro.NameValidatorSchemaParserBuilder(validateDefaults = true)

# should fail because f.avsc has invalid default value
-> avroGenerate
2 changes: 1 addition & 1 deletion src/sbt-test/sbt-avro/publishing/project/plugins.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ sys.props.get("plugin.version") match {
|Specify this property using the scriptedLaunchOpts -D.""".stripMargin)
}

libraryDependencies += "org.apache.avro" % "avro-compiler" % "1.11.3"
libraryDependencies += "org.apache.avro" % "avro-compiler" % "1.12.0"
Loading