如何在 Scala 中将 DataFrame 模式写入文件 [英] How to write a DataFrame schema to file in Scala
本文介绍了如何在 Scala 中将 DataFrame 模式写入文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个 DataFrame,它从一个巨大的 json 文件中加载并从中获取架构.架构基本上大约有 1000 列.我希望将 printSchema 的相同输出保存在文件中而不是控制台中.
I have a DataFrame that loads from a huge json file and gets the schema from it. The schema is basically around 1000 columns. I want the same output of printSchema to be saved in a file instead of the console.
有什么想法吗?
推荐答案
如果您在本地环境中工作,您可以执行以下操作:
You can do the following if you are working in a local environment :
val filePath = "/path/to/file/schema_file"
new PrintWriter(filePath) { write(df.schema.treeString); close }
如果您使用的是 HDFS,则需要提供 URI.
If you are on HDFS, you'll need to provide a URI.
这篇关于如何在 Scala 中将 DataFrame 模式写入文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文