Created
February 13, 2018 05:04
-
-
Save ottomata/e760daf8ad013d358554fd300f1c3975 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| /** Get the intersection of field names in new and old schema, newSchema is expected to be a superset */ | |
| def orderedSelect(newSchema: StructType, oldSchema: StructType): Seq[String] = { | |
| fieldSelect(newSchema).intersect(fieldSelect(oldSchema)) | |
| } | |
| /** build a list of field nameswith nested struct fields */ | |
| def fieldSelect(schema: StructType): Seq[String] = { | |
| schema.flatMap { field => | |
| field.dataType match { | |
| case struct: StructType => fieldSelect(struct).map(field.name + "." + _) | |
| case _ => Seq(field.name) | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment