当前位置:   article > 正文

dataframe保存为csv_sparkSQL_DataFrame

dataframe.write csv option

f3713e00d0109976f75f25f6bcee65ab.png

b3e95e882977d0650ec20ad56ff0dfd7.png

0b49a1989802471abcaa331b781291de.png

a5be536971b0db83ac2c360658d1da95.png

b044b5ebbeec1a0387ba182f0e188725.png

2a69cafe16d4dc78760ffdabc3bd9d6c.png

e7ed94f10c173ac19b299f7bf0083d2d.png

0d346f3c1135fd87e6f3ade2b6ed7a3f.png

443c47756e55b2ae6ed0efd22380bf07.png

0d06b5a8201b8bdbf87835aec7ecf6b9.png

30ebf5a70ce3f070307d596a44fcd176.png

进入spark安装目录:/data0/spark/spark-2.2.1-bin/bin ,执行以下shell命令:

./spark-shell --master local[2] --jars /data0/spark/spark-2.2.1-bin/jars/mysql-connector-java-5.1.15-bin.jar

val df=spark.read.option("timestampFormat", "yyyy/MM/dd HH:mm:ss ZZ").json("file:///data0/project/person.json")

6d63a1acdc29e8f15576d89a14346b2f.png

保存到person2.csv目录

  1. 保存到person2.csv目录
  2. pDF.select("name","age").write.format("csv").option("timestampFormat", "yyyy/MM/dd HH:mm:ss ZZ").save("file:///data0/project/person2.csv")

483780cdaf21264f219ab15b1ba07187.png

d0b7093005f427443a4006c1e14a1017.png

13560950f78995bea654576f9ddee6dc.png

395b397e43e5ce8eb2f36f8e58ee4659.png

583181a602b683badd22b79f8708f309.png

296c8d39eeda634198836ae320e26302.png

c65813ec56ced7b37a388f3db1b0ce08.png

53afa8937bc743ef9d2c6869b8306d30.png

55c1d77fc59d789ed769201052ceb57e.png

ad32538c14bf87f5f8c378862972f009.png

e0aad30d5f95bfa6f32c4732cdb97991.png

b072befc040202dedce80edd5f370e2e.png

23437880c790771f251d30e40dee5042.png

4f20681a1835e9a7f0aacb98c19feebe.png

f9cc62a37f11acb328cc4c8978ffe51d.png

552a73a8d148eefd1238f230904ab686.png
  • Schema和RDD生成DataFrame

de22f131e5c7ffc853ff0f41455dcdf1.png

ba5b79aa308776043da24141ef4a5afc.png

===============对比两种方式

598a8f57b27b79504d49d7cf27c5ce84.png

252b6c51a3b2ed821c952c04ddbf30f9.png

637630810ccc96bc0d4698406316785b.png

242ee14ceb773a2596612024199468b6.png

参见:

spark-shell & spark-sql 使用​blog.csdn.net
8479f731419cfb3cedcfcf38576f0b25.png
Spark学习之路 (十八)SparkSQL简单使用​www.cnblogs.com
c069706dfa039f968bccfc7eb66da36a.png
Spark SQL & DataFrames​spark.apache.org
954e8a4a5cdd5d5a71884ff4549e0f2e.png
Spark SQL, Built-in Functions​spark.apache.org Spark SQL and DataFrames​spark.apache.org
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/凡人多烦事01/article/detail/609234
推荐阅读
相关标签
  

闽ICP备14008679号