Java Hadoop:如何将多维数组写入HDFS?
我有一个任务,需要将多维数组写入HDFS。由于双数组是可序列化的,我想我可以通过使用以下代码来实现:Java Hadoop:如何将多维数组写入HDFS?,java,multidimensional-array,hadoop,hdfs,Java,Multidimensional Array,Hadoop,Hdfs,我有一个任务,需要将多维数组写入HDFS。由于双数组是可序列化的,我想我可以通过使用以下代码来实现: FileSystem fs=FileSystem.get(context.getConfiguration()); FSDataOutputStream dos = fs.create(new Path(directory+"/Predictions")); ObjectWritable obj=new ObjectWritable(double.class,lab
FileSystem fs=FileSystem.get(context.getConfiguration());
FSDataOutputStream dos = fs.create(new Path(directory+"/Predictions"));
ObjectWritable obj=new ObjectWritable(double.class,labelPredictions);
obj.write(dos);
dos.close();
其中directory是hdfs中的路径,labelPredictions是多维数组。但当我这样做时,我会得到以下错误:
java.lang.ClassCastException: [[D cannot be cast to java.lang.Double
at org.apache.hadoop.io.ObjectWritable.writeObject(ObjectWritable.java:150)
at org.apache.hadoop.io.ObjectWritable.write(ObjectWritable.java:70)
at MapReduce.MapReduce$Reduce.cleanup(MapReduce.java:181)
at org.apache.hadoop.mapreduce.Reducer.run(Reducer.java:178)
at org.apache.hadoop.mapred.ReduceTask.runNewReducer(ReduceTask.java:648)
at org.apache.hadoop.mapred.ReduceTask.run(ReduceTask.java:416)
at org.apache.hadoop.mapred.Child$4.run(Child.java:259)
at java.security.AccessController.doPrivileged(Native Method)
at javax.security.auth.Subject.doAs(Subject.java:416)
at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1059)
at org.apache.hadoop.mapred.Child.main(Child.java:253)
我的双数组是否需要实现可写来实现这一点,或者有其他方法吗?也许您应该使用
double[][].class
而不是double.class
。。。?(取决于您使用的数组的维度--您说的是“多维”,但不清楚实际维度是什么。)我想到了这一点,但出于某种原因,我觉得这个类非常愚蠢。谢谢:D