-
Notifications
You must be signed in to change notification settings - Fork 5
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
Baleen <-> Avro generators #6
Conversation
In order to add validation to existing Avro schemas, use this utility to create Baleen descriptions from your legacy Avro schemas
Convert your Baleen data descriptions into Avro schemas to use in data serialization. This updates the Work-in-progress Avro schema generator
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. Just had a minor comment.
value == null -> sequenceOf(ValidationError(dataTrace, "is null", value)) | ||
value is String && !enum.contains(value) -> | ||
sequenceOf(ValidationError(dataTrace, | ||
"is not contained in enum [${enum.joinToString(", ")}]", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be a good idea to create the string version of the enum at construction time so the building of the string doesn't need to happen every request.
|
||
import com.shoprunner.baleen.BaleenType | ||
|
||
abstract class CoercibleType(val type: BaleenType) : BaleenType |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice
|
||
constructor(enum: Array<out Enum<*>>) : this(enum.map { it.name }) | ||
|
||
override fun name() = "enum" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be good to require enum types to have a name. That will make the error messages clearer. Could you add a name attribute to the constructor that could be used for the name field and validate
method?
@@ -42,12 +82,23 @@ object AvroEncoder { | |||
dataDescription.nameSpace, false, fields) | |||
} | |||
|
|||
fun encode(dataDescription: DataDescription, outputStream: PrintStream) { | |||
infix fun DataDescription.encodeTo(directory: File): File { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be good if this takes a type mapping function so custom types can be mapped.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you can get the syntax you want without making the function infix
. infix
functions can only take a single argument.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure I follow... Can you give an example of how it would look?
@HawaiianSpork made the changes as per our conversation |
Provide a way to generate base Baleen descriptions from legacy Avro schemas. Additionally add the reverse generater from Baleen to Avro.
TODO
WONTDO (Out of scope for now)