-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Update avro-compiler to 1.12.0 * Add 1.11 in scripted tests * Support avro 1.12 new schema parser builder * Update CI to java 11 * Use generic AvroRuntimeException in avro compile step --------- Co-authored-by: Michel Davit <[email protected]>
- Loading branch information
1 parent
c4a48f6
commit dcedb81
Showing
31 changed files
with
199 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
src/main/scala/com/github/sbt/avro/LegacySchemaParserBuilder.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
19 changes: 19 additions & 0 deletions
19
src/main/scala/com/github/sbt/avro/NameValidatorSchemaParserBuilder.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../basic_current/project/build.properties |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
../basic_current/test | ||
../basic_1.11/test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../basic_current/project/build.properties |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../basic_current/src |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../basic_current/project/build.properties |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
../basic_current/test | ||
../basic_1.11/test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../basic_current/project/build.properties |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
../basic_current/test | ||
../basic_1.11/test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
src/sbt-test/sbt-avro/basic_current/src/main/avro/logicalType.avsc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} | ||
] | ||
} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.