jojoba
jojoba

Reputation: 554

Hadoop: How can someone write a multidimensional array to HDFS?

I have a task where i need to write a multidimensional array to HDFS. Since double arrays are serializable, i thought i could do it just by using this code:

     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();

where directory is a path in hdfs, labelPredictions is the multidimensional array. But when i do this i get this error:

     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)

Does my double array need to implement Writable to do this, or there is another way?

Upvotes: 0

Views: 832

Answers (1)

Louis Wasserman
Louis Wasserman

Reputation: 198103

Perhaps you should be using double[][].class instead of double.class...? (Depending on the dimension of the array you're using -- you said "multidimensional," but it's not clear what the actual dimension is.)

Upvotes: 2

Related Questions