Guest User

Untitled

a guest
Mar 17th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.49 KB | None | 0 0
  1. import org.apache.spark.sql.types._ // You'll need this to evaluate its output
  2.  
  3. object StructFmt {
  4. def asScala(field: StructField): String = field.dataType match {
  5. case struct: StructType => s"""StructField("${field.name}",""" + asScala(struct) + s", ${field.nullable})"
  6. case _ => s"""StructField("${field.name}", ${field.dataType}, ${field.nullable})"""
  7. }
  8.  
  9. def asScala(struct: StructType): String = "StructType(Seq(" + (for(field <- struct) yield asScala(field)).mkString(",") + "))"
  10. }
Add Comment
Please, Sign In to add comment