gpt4 book ai didi

hadoop - 在 Spark Java 中将文本文件转换为序列格式

转载 作者:可可西里 更新时间:2023-11-01 14:45:40 26 4
gpt4 key购买 nike

在 Spark Java 中,如何将文本文件转换为序列文件?以下是我的代码:

    SparkConf sparkConf = new SparkConf().setAppName("txt2seq");
sparkConf.setMaster("local").set("spark.executor.memory", "1g");
sparkConf.set("spark.serializer", "org.apache.spark.serializer.KryoSerializer");
JavaSparkContext ctx = new JavaSparkContext(sparkConf);

JavaPairRDD<String, String> infile = ctx.wholeTextFiles("input_txt");
infile.saveAsNewAPIHadoopFile("outfile.seq", String.class, String.class, SequenceFileOutputFormat.class);

我得到了下面的错误。

14/12/07 23:43:33 ERROR Executor: Exception in task ID 0
java.io.IOException: Could not find a serializer for the Key class: 'java.lang.String'. Please ensure that the configuration 'io.serializations' is properly configured, if you're usingcustom serialization.
at org.apache.hadoop.io.SequenceFile$Writer.init(SequenceFile.java:1176)
at org.apache.hadoop.io.SequenceFile$Writer.<init>(SequenceFile.java:1091)

有人知道吗?谢谢!

最佳答案

改变这个:

JavaPairRDD<String, String> infile = ctx.wholeTextFiles("input_txt");
infile.saveAsNewAPIHadoopFile("outfile.seq", String.class, String.class, SequenceFileOutputFormat.class);

JavaPairRDD<String, String> infile = ctx.wholeTextFiles("input_txt");
JavaPairRDD<Text, Text> resultRDD = infile.mapToPair(f -> new Tuple2<>(new Text(f._1()), new Text(f._2())));
resultRDD.saveAsNewAPIHadoopFile("outfile.seq", Text.class, Text.class, SequenceFileOutputFormat.class);

关于hadoop - 在 Spark Java 中将文本文件转换为序列格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27353462/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com