Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def flattenSchema(schema: StructType, prefix: String = null) : Array[Column] = {
- schema.fields.flatMap(f => {
- val colName = if (prefix == null) f.name else (prefix + "." + f.name)
- f.dataType match {
- case st: StructType => flattenSchema(st, colName)
- case _ => Array(col(colName).alias(colName))
- }
- })
- }
- var flattenedDf = json.select(flattenSchema(json.schema):_*)
- display(flattenedDf)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement