简体   繁体   English

Java Spark如何保存JavaPairRDD <HashSet<String> ,HashMap <String, Double> &gt;归档?

[英]Java Spark how to save a JavaPairRDD<HashSet<String>, HashMap<String, Double>> to file?

I got this " JavaPairRDD<HashSet<String>, HashMap<String, Double>> " RDD after some complicated aggregations, want to save the result to file. 经过一些复杂的聚合后,我得到了这个“ JavaPairRDD<HashSet<String>, HashMap<String, Double>> ” RDD,想将结果保存到文件中。 I believe saveAsHadoopFile is a good API to do so, but am having trouble filling in the parameters for saveAsHadoopFile(path, keyClass, valueClass, outputFormatClass, CompressionCodec) . 我相信saveAsHadoopFile是这样做的一个不错的API,但是在为saveAsHadoopFile(path, keyClass, valueClass, outputFormatClass, CompressionCodec)填写参数时遇到了麻烦。 Can anyone help? 有人可以帮忙吗?

You can use the following function and later on parse it to the desired result. 您可以使用以下函数,稍后再将其解析为所需的结果。

rdd.saveAsTextFile ("hdfs:///complete_path_to_hdfs_file/");

but if you want to use saveAsHadoopFile API then following method can be used. 但是,如果要使用saveAsHadoopFile API,则可以使用以下方法。

saveAsHadoopFile(complete_path_to_file, HashSet.class, HashMap.class, TextOutputFormat.class)

you can also use HadoopOutputFormat.class as the last parameter 您还可以使用HadoopOutputFormat.class作为最后一个参数

For more information, you can refer to this link HadoopFile 有关更多信息,您可以参考此链接HadoopFile。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在Spark中将HashMap转换为JavaPairRDD? - How to convert a HashMap to a JavaPairRDD, in Spark? 如何将带有标头的 csv 文件流式传输到 HashMap<String, Double> 在爪哇? - How to stream a csv file with header to a HashMap<String, Double> in Java? 如何对Hashmap进行排序<String, Map<String, Double> &gt; 在 Java 中? - How to sort Hashmap<String, Map<String, Double>> in Java? 如何为私有 HashMap 编写 bytebuddy 代码<string, hashset<string> &gt; 嗯;?</string,> - How to write bytebuddy code for private HashMap<String, HashSet<String>> hm;? 我们如何搜索 HashMap<string, string> object 内带外循环 HashSet <hashmap<string, string> &gt;? </hashmap<string,></string,> - How can we search HashMap<String, String> object inside with out loop HashSet<HashMap<String, String>>? 文件中出现HashMap字符串[JAVA] - HashMap String occurrences in a file [JAVA] Java中的字符串实习和HashSet - String interning and HashSet in java Java中的String转换为HashSet - Convert String to HashSet in Java 转换HashMap <Integer, List<String> &gt;到HashMap <String, HashSet<Integer> &gt; - Convert a HashMap<Integer, List<String>> to HashMap<String, HashSet<Integer>> 搜索一个HashMap <String, Arraylist<Users> &gt;或HashMap <String, HashSet<Users> &gt; - Searching a HashMap<String, Arraylist<Users>> or HashMap<String, HashSet<Users>>
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM