开发者社区> 问答> 正文

Spark中的hadoopFile无法读取HDFS上的文件:报错

SparkConf conf = new SparkConf().setAppName("test");
        JavaSparkContext sc = new JavaSparkContext(conf);
        JavaPairRDD<Double, String> tempRDD = sc.hadoopFile(
                "hdfs://localhost:9000/dsd", TextInputFormat.class,

                Double.class, String.class);

写完以上语句后,hadoopFile下面老是会有红线提示错误。不知道为什么,即使把读取的数据类型换成Text还是出错。

展开
收起
kun坤 2020-06-06 23:53:27 959 0
1 条回答
写回答
取消 提交回答
  • <K,V,F extends org.apache.hadoop.mapred.InputFormat<K,V>> 
    RDD<scala.Tuple2<K,V>>
    hadoopFile(String path, scala.reflect.ClassTag<K> km, scala.reflect.ClassTag<V> vm, scala.reflect.ClassTag<F> fm)
    ######

    不是同一个class,spark中是scala.reflect.ClassTag,而你用的是hadoop中的class

    ######

    TextInputFormat extends FileInputFormat<LongWritable, Text>

    因此在kClass这里天LongWritable.class

    2020-06-06 23:53:33
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
Hybrid Cloud and Apache Spark 立即下载
Scalable Deep Learning on Spark 立即下载
Comparison of Spark SQL with Hive 立即下载