我有一个 JSON 模式,我想将其转换为 Spark 模式。 我认为来自 Zalando 的这个库可以提供帮助,但它似乎不再维护并且不起作用。
我还能做什么?如果你问我,我认为这将是一个相当常见的用例,所以很惊讶 Spark 不支持它。
在scala中,你只需要这样写
import org.apache.spark.sql.types.{DataType, StructType}
val jsonSchema = "get your json schema from a file or hardcode it here directly"
val schemaFromJson = DataType.fromJson(jsonSchema).asInstanceOf[StructType]