如何在Scala中将DataFrame架构写入文件 [英] How to write a DataFrame schema to file in Scala

查看:286
本文介绍了如何在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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆