Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do i build a hierarchical database with apache Cassandra

I want to develop a hierarchical database to store directory structure in the filesystem.

Just like

 Root
   -dir
     -subdir
     -subdir
        -subdir
            -subdir
            -subdir
     -subdir
     -subdir

can i use Apache Cassandra for this

a java example will be better to understand.

like image 534
JOHN Avatar asked Feb 24 '23 12:02

JOHN


2 Answers

You could store the data, type and parent of a path in a column family,

paths { #colum family 
    "/some/path" { # key
         "type" : "file|directory" #column, either file or directory, if this is a file or a directory
         "data" : "??" # if this is a file, the data for the file.  you don't want to be storing very large files in cassandra in one column
    }
}

With cassandra, you need to denormalize to serve the queries you are going to perform. You probably want to query the children of a directory, so have a structure like,

children { #column family 
    "/some/path" { # key
         "child-path-1" : null #column, one for each child of /some/path
         "child-path-2" : null 
    }
}

Add more column families to support the other queries you wish to do.

like image 53
sbridges Avatar answered Feb 26 '23 00:02

sbridges


Hi this is what i would do for a relational dbms schema.

product{
  id int,
  parent_id int,
  name varchar2(30)
}

Sample data:

product
--------------------
id   | parent_id   | name
0    | 0           | root
1    | 0           | laptop
2    | 0           | pc
3    | 1           | Dell Latitude E4310
4    | 1           | Dell Vostro E3300
5    | 2           | Compaq Desktop 3
6    | 2           | Compaq Presario 2
like image 25
Oh Chin Boon Avatar answered Feb 26 '23 01:02

Oh Chin Boon