Home 중첩된 schema flattening하기
Post
Cancel

중첩된 schema flattening하기

1
2
3
4
5
6
7
8
9
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) as colName)
      }
    })
}

출처

https://stackoverflow.com/questions/37471346/automatically-and-elegantly-flatten-dataframe-in-spark-sql/37473765#37473765

This post is licensed under CC BY 4.0 by the author.

Scala return

[Trouble Shooting] cannot resolve column(numeric column name) in Spark Dataframe

Comments powered by Disqus.

Trending Tags