Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Write a binary tree in hadoop FS

I need to write a binary tree to HDFS, which i will use to represent a desicion tree. But in order to do that i first need to create a BinaryTreeNode class, which will be the tree node. These are my class attributes:

private String name;
private String attribute;
private String attType;
private String condition;
private String lines;
private BinaryTreeNode leftChild;
private BinaryTreeNode rightChild;

So now i need to implement the write and readFields methods for reading and writing these nodes. These are what i have done:

public void write(DataOutput d) throws IOException 
{
    d.writeUTF(name);
    d.writeUTF(attribute);
    d.writeUTF(attType);
    d.writeUTF(condition);
    d.writeUTF(lines);
    //SOMETHIN FOR LEFT AND RIGHT CHILD
}

public void readFields(DataInput di) throws IOException 
{
    name=di.readUTF();
    attribute=di.readUTF();
    attType=di.readUTF();
    condition=di.readUTF();
    lines=di.readUTF();
    //SOMETHIN FOR LEFT AND RIGHT CHILD
}

BinaryTreeNode read(DataInput in) throws IOException
{
     BinaryTreeNode ob = new BinaryTreeNode();
     ob.readFields(in);
     return ob;
}

What i cant think of is how to write and read my 2 child nodes. Note that the tree is going to be build recursively and every node will have 0-2 childs. So my later purpose is to have a BinaryTree class that will have the attribute BinaryTreeNode root. Thanks

like image 436
jojoba Avatar asked Mar 16 '26 14:03

jojoba


1 Answers

I need to write a binary tree to HDFS

All i need is a way to save and load my tree.

What's the reason to go with HDFS? HDFS is a distributed file system on which any type of data/files can be stored. You have write a lot of code to store and retrieve the graphs effectively on large scale.

You can store and retrieve graphs from graph oriented databases like OrientDB and Neo4j.

Also, there are open source frameworks like Apache Giraph, Apache Hama and GoldenOrb. There might also be bindings to interact from Java programs.

like image 183
Praveen Sripati Avatar answered Mar 19 '26 02:03

Praveen Sripati