Creating AVRO schema from JSON Schema File

我的未来我决定 提交于 2020-05-27 03:17:28

问题


I have the JSON file & JSON Schema to be parsed into the AVRO Schema. I am little bit confused, do i have to write the manual AVRO schema using the data types defined in AVRO documentation.

Or is there any automated method / function / program that can work exactly the same as required ?


回答1:


Well, you can try https://github.com/fge/json-schema-avro, but they say it is still not complete. So not sure it will work, though




回答2:


avro4s derives schemas at compile time from case classes:

import com.sksamuel.avro4s.SchemaFor

object Avro {
  case class MyAvroClass(s: String, i: Int)

  def main(args: Array[String]): Unit = {
    val avroSchema = SchemaFor[MyAvroClass]()
    println(avroSchema.toString(true))
  }
}

Yields:

{
  "type" : "record",
  "name" : "MyAvroClass",
  "namespace" : "tests",
  "fields" : [ {
    "name" : "s",
    "type" : "string"
  }, {
    "name" : "i",
    "type" : "int"
  } ]
}


来源:https://stackoverflow.com/questions/36689916/creating-avro-schema-from-json-schema-file

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!