Posts Tagged ‘NoSQL’

Neo4j
—–
Graph Data base..

download :
———-
URL     : http://neo4j.com/download/
package  : neo4j-community-2.3.0-M01-unix.tar.gz

unZip :
——-

tar -xf neo4j-community-2.3.0-M01-unix.tar.gz

Change config values :
———————-

change server port values as per your needs

cat conf/neo4j-server.properties | grep port

#org.neo4j.server.webserver.port=7474   # —- default port
org.neo4j.server.webserver.port=7475    # —- changed by me
# Turn https-support on/off
# https port (for all data, administrative, and UI access)
#org.neo4j.server.webserver.https.port=7473 #—– default port
org.neo4j.server.webserver.https.port=7476  #—– changed by me

Start Server
————
NEO4J_HOME/bin/neo4j start

[ramisetty@cluster-01 neo4j-community-2.3.0-M01]$ bin/neo4j start
Starting Neo4j Server…WARNING: not changing user
process [20390]… waiting for server to be ready…….. OK.
http://localhost:7475/ is ready.

[ramisetty@cluster-01 neo4j-community-2.3.0-M01]$ tail -f  conf/neo4j-server.properties

#*****************************************************************
# Administration client configuration
#*****************************************************************

# location of the servers round-robin database directory. Possible values:
# – absolute path like /var/rrd
# – path relative to the server working directory like data/rrd
# – commented out, will default to the database data directory.
org.neo4j.server.webadmin.rrdb.location=data/rrd

Start Client Shell:
——————-

NEO4J_HOME/bin/neo4j-shell

[ramisetty@cluster-01 neo4j-community-2.3.0-M01]$ bin/neo4j-shell
Welcome to the Neo4j Shell! Enter ‘help’ for a list of commands
NOTE: Remote Neo4j graph database service ‘shell’ at port 1337

neo4j-sh (?)$ help
Available commands: alias begin cd commit create cypher dbinfo drop dump env explain export gsh help index jsh load ls man match merge mknode mkrel mv optional paths planner profile pwd return rm rmnode rmrel rollback runtime schema set start trav unwind using with
Use man for info about each command.
neo4j-sh (?)$

Create some data :
——————

# create Movie Nodes

CREATE (matrix:Movie { title:”The Matrix”,released:1997 })
CREATE (cloudAtlas:Movie { title:”Cloud Atlas”,released:2012 })
CREATE (forrestGump:Movie { title:”Forrest Gump”,released:1994 })

# create Person nodes

CREATE (keanu:Person { name:”Keanu Reeves”, born:1964 })
CREATE (robert:Person { name:”Robert Zemeckis”, born:1951 })
CREATE (tom:Person { name:”Tom Hanks”, born:1956 })

# create RELATIONs

CREATE (tom)-[:ACTED_IN { roles: [“Forrest”]}]->(forrestGump)
CREATE (tom)-[:ACTED_IN { roles: [‘Zachry’]}]->(cloudAtlas)
CREATE (robert)-[:DIRECTED]->(forrestGump)

In Shell
——–

neo4j-sh (?)$ CREATE (matrix:Movie { title:”The Matrix”,released:1997 })
> CREATE (cloudAtlas:Movie { title:”Cloud Atlas”,released:2012 })
> CREATE (forrestGump:Movie { title:”Forrest Gump”,released:1994 })
> ;
+——————-+
| No data returned. |
+——————-+
Nodes created: 3
Properties set: 6
Labels added: 3
1214 ms
neo4j-sh (?)$ CREATE (keanu:Person { name:”Keanu Reeves”, born:1964 })
> CREATE (robert:Person { name:”Robert Zemeckis”, born:1951 })
> CREATE (tom:Person { name:”Tom Hanks”, born:1956 })
> ;
+——————-+
| No data returned. |
+——————-+
Nodes created: 3
Properties set: 6
Labels added: 3
76 ms
neo4j-sh (?)$ CREATE (tom)-[:ACTED_IN { roles: [“Forrest”]}]->(forrestGump)
> CREATE (tom)-[:ACTED_IN { roles: [‘Zachry’]}]->(cloudAtlas)
> CREATE (robert)-[:DIRECTED]->(forrestGump)
> ;
+——————-+
| No data returned. |
+——————-+
Nodes created: 4
Relationships created: 3
Properties set: 2
117 ms
neo4j-sh (?)$

complex Query
—————-
neo4j-sh (?)$ MATCH (p:Person)
> RETURN p, p.name AS name, upper(p.name), coalesce(p.nickname,”n/a”) AS nickname, { name: p.name,
>   label:head(labels(p))} AS person;
+———————————————————————————————————————————————–+
| p                                         | name              | upper(p.name)     | nickname | person                                         |
+———————————————————————————————————————————————–+
| Node[3]{name:”Keanu Reeves”,born:1964}    | “Keanu Reeves”    | “KEANU REEVES”    | “n/a”    | {name -> “Keanu Reeves”, label -> “Person”}    |
| Node[4]{name:”Robert Zemeckis”,born:1951} | “Robert Zemeckis” | “ROBERT ZEMECKIS” | “n/a”    | {name -> “Robert Zemeckis”, label -> “Person”} |
| Node[5]{name:”Tom Hanks”,born:1956}       | “Tom Hanks”       | “TOM HANKS”       | “n/a”    | {name -> “Tom Hanks”, label -> “Person”}       |
+———————————————————————————————————————————————–+
3 rows
213 ms
neo4j-sh (?)$

Loading graph db from csv:
————————————–

[ramisetty@cluster-01 neo4j-community-2.3.0-M01]$ mkdir examples
[ramisetty@cluster-01 neo4j-community-2.3.0-M01]$ cd examples/
[ramisetty@cluster-01 examples]$ pwd
/home/ramisetty/vijay/neo4j/neo4j-community-2.3.0-M01/examples
[ramisetty@cluster-01 examples]$ vim movies.csv
[ramisetty@cluster-01 examples]$ vim persons.csv
[ramisetty@cluster-01 examples]$ vim roles.csv

[ramisetty@cluster-01 examples]$ cat movies.csv
id,title,country,year
1,Wall Street,USA,1987
2,The American President,USA,1995
3,The Shawshank Redemption,USA,1994

[ramisetty@cluster-01 examples]$ cat persons.csv
id,name
1,Charlie Sheen
2,Oliver Stone
3,Michael Douglas
4,Martin Sheen
5,Morgan Freeman

[ramisetty@cluster-01 examples]$ cat roles.csv
personId,movieId,role
1,1,Bud Fox
4,1,Carl Fox
3,1,Gordon Gekko
4,2,A.J. MacInerney
3,2,President Andrew Shepherd
5,3,Ellis Boyd ‘Red’ Redding
[ramisetty@cluster-01 examples]$

==== Note : refer  for graph : http://neo4j.com/docs/2.2.2/cypherdoc-loading-data.html

Load the csv files:
————————–

LOAD CSV WITH HEADERS FROM “file:///home/ramisetty/vijay/neo4j/neo4j-community-2.3.0-M01/examples/movies.csv” AS line
CREATE (m:Movie { id:line.id,title:line.title, released:toInt(line.year)});

LOAD CSV WITH HEADERS FROM “file:///home/ramisetty/vijay/neo4j/neo4j-community-2.3.0-M01/examples/persons.csv” AS line
MERGE (a:Person { id:line.id })
ON CREATE SET a.name=line.name;

LOAD CSV WITH HEADERS FROM “file:///home/ramisetty/vijay/neo4j/neo4j-community-2.3.0-M01/examples/roles.csv” AS line
MATCH (m:Movie { id:line.movieId })
MATCH (a:Person { id:line.personId })
CREATE (a)-[:ACTED_IN { roles: [line.role]}]->(m);

neo4j-sh (?)$ LOAD CSV WITH HEADERS FROM “file:///home/ramisetty/vijay/neo4j/neo4j-community-2.3.0-M01/examples/movies.csv” AS line
> CREATE (m:Movie { id:line.id,title:line.title, released:toInt(line.year)});
+——————-+
| No data returned. |
+——————-+
Nodes created: 3
Properties set: 9
Labels added: 3
158 ms
neo4j-sh (?)$

neo4j-sh (?)$ LOAD CSV WITH HEADERS FROM “file:///home/ramisetty/vijay/neo4j/neo4j-community-2.3.0-M01/examples/persons.csv” AS line
> MERGE (a:Person { id:line.id })
> ON CREATE SET a.name=line.name;
+——————-+
| No data returned. |
+——————-+
Nodes created: 5
Properties set: 10
Labels added: 5
210 ms

neo4j-sh (?)$ LOAD CSV WITH HEADERS FROM “file:///home/ramisetty/vijay/neo4j/neo4j-community-2.3.0-M01/examples/roles.csv” AS line
> MATCH (m:Movie { id:line.movieId })
> MATCH (a:Person { id:line.personId })
> CREATE (a)-[:ACTED_IN { roles: [line.role]}]->(m);
+——————-+
| No data returned. |
+——————-+
Relationships created: 6
Properties set: 6
216 ms

Example Query :   
—————

referhttp://neo4j.com/docs/2.2.2/cypherdoc-movie-database.html
——–

Let’s list all persons and the movies they acted in.

neo4j-sh (?)$ MATCH (person:Person)-[:ACTED_IN]->(movie:Movie)
> RETURN person.name, movie.title;
+————————————————+
| person.name       | movie.title                |
+————————————————+
| “Michael Douglas” | “Wall Street”              |
| “Martin Sheen”    | “Wall Street”              |
| “Charlie Sheen”   | “Wall Street”              |
| “Michael Douglas” | “The American President”   |
| “Martin Sheen”    | “The American President”   |
| “Morgan Freeman”  | “The Shawshank Redemption” |
+————————————————+
6 rows
65 ms
neo4j-sh (?)$

neo4j-sh (?)$ MATCH (movie:Movie)
> RETURN movie.title;
+—————————-+
| movie.title                |
+—————————-+
| “The Matrix”               |
| “Cloud Atlas”              |
| “Forrest Gump”             |
| “Wall Street”              |
| “The American President”   |
| “The Shawshank Redemption” |
+—————————-+
6 rows
194 ms

neo4j-sh (?)$ MATCH (n)-[r]->(m)
> RETURN n AS FROM , r AS `->`, m AS to;
+—————————————————————————————————————————————————————+
| FROM                                    | ->                                                | to                                                              |
+—————————————————————————————————————————————————————+
| Node[6]{}                               | :ACTED_IN[1]{roles:[“Zachry”]}                    | Node[8]{}                                                       |
| Node[6]{}                               | :ACTED_IN[0]{roles:[“Forrest”]}                   | Node[7]{}                                                       |
| Node[9]{}                               | :DIRECTED[2]{}                                    | Node[7]{}                                                       |
| Node[13]{name:”Charlie Sheen”,id:”1″}   | :ACTED_IN[3]{roles:[“Bud Fox”]}                   | Node[10]{title:”Wall Street”,released:1987,id:”1″}              |
| Node[15]{name:”Michael Douglas”,id:”3″} | :ACTED_IN[7]{roles:[“President Andrew Shepherd”]} | Node[11]{id:”2″,title:”The American President”,released:1995}   |
| Node[15]{name:”Michael Douglas”,id:”3″} | :ACTED_IN[5]{roles:[“Gordon Gekko”]}              | Node[10]{title:”Wall Street”,released:1987,id:”1″}              |
| Node[16]{name:”Martin Sheen”,id:”4″}    | :ACTED_IN[6]{roles:[“A.J. MacInerney”]}           | Node[11]{id:”2″,title:”The American President”,released:1995}   |
| Node[16]{name:”Martin Sheen”,id:”4″}    | :ACTED_IN[4]{roles:[“Carl Fox”]}                  | Node[10]{title:”Wall Street”,released:1987,id:”1″}              |
| Node[17]{name:”Morgan Freeman”,id:”5″}  | :ACTED_IN[8]{roles:[“Ellis Boyd ‘Red’ Redding”]}  | Node[12]{id:”3″,title:”The Shawshank Redemption”,released:1994} |
+—————————————————————————————————————————————————————+
9 rows
78 ms
neo4j-sh (?)$

PC & OS -Information

vijay@hp-15-notebook-pc:~$ uname -a
Linux vijay.cluster.node1 3.16.0-33-generic #44~14.04.1-Ubuntu SMP Fri Mar 13 10:33:29 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux

vijay@hp-15-notebook-pc:~$ lsb_release -a
No LSB modules are available.
Distributor ID:    Ubuntu
Description:    Ubuntu 14.04.2 LTS
Release:    14.04
Codename:    trusty

RAM      : 4 GB (3.3 GiB available)
Processor : AMD A8-6410 APU with AMD Radeon R5 Graphics × 4
OS type      : 64 bit
Disk      : 109.6 GB

Download

http://apache.cs.utah.edu/cassandra/2.0.15/apache-cassandra-2.0.15-bin.tar.gz

Make Sure Java is available

vijay@hp-15-notebook-pc:~/developer/installations$ java -version
java version “1.7.0_45”
Java(TM) SE Runtime Environment (build 1.7.0_45-b18)
Java HotSpot(TM) 64-Bit Server VM (build 24.45-b08, mixed mode)

Unzip

vijay@hp-15-notebook-pc:~/developer/installations$ tar -xf apache-cassandra-2.0.15-bin.tar.gz

vijay@hp-15-notebook-pc:~/developer/installations$ ls -l
total 17704
drwxrwxr-x 9 vijay vijay     4096 May 20 21:24 apache-cassandra-2.0.15
-rw-rw-r– 1 vijay vijay 18111795 May 20 21:22 apache-cassandra-2.0.15-bin.tar.gz
drwxr-xr-x 8 vijay vijay     4096 Oct  8  2013 jdk1.7.0_45
drwxr-xr-x 5 vijay vijay     4096 Apr 19 20:27 sublime
vijay@hp-15-notebook-pc:~/developer/installations$ rm -r apache-cassandra-2.0.15-bin.tar.gz
vijay@hp-15-notebook-pc:~/developer/installations$ ls
apache-cassandra-2.0.15  jdk1.7.0_45  sublime
vijay@hp-15-notebook-pc:~/developer/installations$ cd apache-cassandra-2.0.15/
vijay@hp-15-notebook-pc:~/developer/installations/apache-cassandra-2.0.15$ ls
bin  CHANGES.txt  conf  interface  javadoc  lib  LICENSE.txt  NEWS.txt  NOTICE.txt  pylib  tools
vijay@hp-15-notebook-pc:~/developer/installations/apache-cassandra-2.0.15$ ls -l
total 320
drwxr-xr-x 2 vijay vijay   4096 May 20 21:24 bin
-rw-r–r– 1 vijay vijay 220336 May 13 21:17 CHANGES.txt
drwxr-xr-x 3 vijay vijay   4096 May 20 21:24 conf
drwxr-xr-x 2 vijay vijay   4096 May 20 21:24 interface
drwxr-xr-x 4 vijay vijay   4096 May 20 21:24 javadoc
drwxr-xr-x 3 vijay vijay   4096 May 20 21:24 lib
-rw-r–r– 1 vijay vijay  11609 May 13 21:17 LICENSE.txt
-rw-r–r– 1 vijay vijay  60141 May 13 21:17 NEWS.txt
-rw-r–r– 1 vijay vijay   2030 May 13 21:17 NOTICE.txt
drwxr-xr-x 3 vijay vijay   4096 May 20 21:24 pylib
drwxr-xr-x 4 vijay vijay   4096 May 13 21:17 tools
vijay@hp-15-notebook-pc:~/developer/installations/apache-cassandra-2.0.15$ pwd
/home/vijay/developer/installations/apache-cassandra-2.0.15
vijay@hp-15-notebook-pc:~/developer/installations/apache-cassandra-2.0.15$ cd bin/
vijay@hp-15-notebook-pc:~/developer/installations/apache-cassandra-2.0.15/bin$ ls
cassandra          cassandra.in.sh  debug-cql.bat     nodetool.bat      sstablekeys.bat    sstablescrub.bat  sstableupgrade.bat
cassandra.bat      cqlsh            json2sstable      sstable2json      sstableloader      sstablesplit      stop-server
cassandra-cli      cqlsh.bat        json2sstable.bat  sstable2json.bat  sstableloader.bat  sstablesplit.bat
cassandra-cli.bat  debug-cql        nodetool          sstablekeys       sstablescrub       sstableupgrade
vijay@hp-15-notebook-pc:~/developer/installations/apache-cassandra-2.0.15/bin$

Change Directory Permissions

Next, make sure that the folders Cassandra accesses, such as the log folder, exists and that Cassandra has the right to write on it:

sudo mkdir /var/lib/cassandra
sudo mkdir /var/log/cassandra
sudo chown -R $USER:$GROUP /var/lib/cassandra
sudo chown -R $USER:$GROUP /var/log/cassandra

Set Cassandra Path and Home

vijay@cluster-01:~$ sudo vim ~/.bashrc
vijay@cluster-01:~$ source ~/.bashrc
vijay@cluster-01:~$ tail ~/.bashrc

#——— Cassandra

export export CASSANDRA_HOME=/home/vijay/developer/installations/apache-cassandra-2.0.15
export PATH=$PATH:$CASSANDRA_HOME/bin
vijay@cluster-01:~$

Start Cassandra:

restart terminal session and run below command.

vijay@cluster-01:~$ cassandra -p

STOP Cassandra:

vijay@cluster-01:~$ jps
4180 CassandraDaemon
4414 Jps
vijay@cluster-01:~$ sudo kill -9 4180   (or) pkill -f CassandraDaemon
[sudo] password for vijay:
vijay@cluster-01:~$ jps
4439 Jps

Start Cassandra and start CLI – cqlsh

vijay@cluster-01:~$ cqlsh
Connected to Test Cluster at localhost:9160.
[cqlsh 4.1.1 | Cassandra 2.0.15 | CQL spec 3.1.1 | Thrift protocol 19.39.0]
Use HELP for help.

Create a keyspace — a namespace of tables.
cqlsh> CREATE KEYSPACE mykeyspace
… WITH REPLICATION = { ‘class’ : ‘SimpleStrategy’, ‘replication_factor’ : 1 };

Help
cqlsh> help

Documented shell commands:
===========================
CAPTURE      COPY  DESCRIBE  EXPAND  SHOW    TRACING
CONSISTENCY  DESC  EXIT      HELP    SOURCE

CQL help topics:
================
ALTER                        CREATE_TABLE_OPTIONS  SELECT
ALTER_ADD                    CREATE_TABLE_TYPES    SELECT_COLUMNFAMILY
ALTER_ALTER                  CREATE_USER           SELECT_EXPR
ALTER_DROP                   DELETE                SELECT_LIMIT
ALTER_RENAME                 DELETE_COLUMNS        SELECT_TABLE
ALTER_USER                   DELETE_USING          SELECT_WHERE
ALTER_WITH                   DELETE_WHERE          TEXT_OUTPUT
APPLY                        DROP                  TIMESTAMP_INPUT
ASCII_OUTPUT                 DROP_COLUMNFAMILY     TIMESTAMP_OUTPUT
BEGIN                        DROP_INDEX            TRUNCATE
BLOB_INPUT                   DROP_KEYSPACE         TYPES
BOOLEAN_INPUT                DROP_TABLE            UPDATE
COMPOUND_PRIMARY_KEYS        DROP_USER             UPDATE_COUNTERS
CREATE                       GRANT                 UPDATE_SET
CREATE_COLUMNFAMILY          INSERT                UPDATE_USING
CREATE_COLUMNFAMILY_OPTIONS  LIST                  UPDATE_WHERE
CREATE_COLUMNFAMILY_TYPES    LIST_PERMISSIONS      USE
CREATE_INDEX                 LIST_USERS            UUID_INPUT
CREATE_KEYSPACE              PERMISSIONS
CREATE_TABLE                 REVOKE

cqlsh> USE mykeyspace;
cqlsh:mykeyspace>

Create table

cqlsh> USE mykeyspace;
cqlsh:mykeyspace> CREATE TABLE users (
…   user_id int PRIMARY KEY,
…   fname text,
…   lname text
… );

 

Insert the data

cqlsh:mykeyspace> INSERT INTO users (user_id,  fname, lname)
…   VALUES (1745, ‘john’, ‘smith’);
cqlsh:mykeyspace> INSERT INTO users (user_id,  fname, lname)
…   VALUES (1744, ‘john’, ‘doe’);
cqlsh:mykeyspace> INSERT INTO users (user_id,  fname, lname)
…   VALUES (1746, ‘john’, ‘smith’);

Check the entries

cqlsh:mykeyspace> SELECT * FROM users;

user_id | fname | lname
———+——-+——-
1745 |  john | smith
1744 |  john |   doe
1746 |  john | smith

(3 rows)

cqlsh:mykeyspace>

Indexing

—You can retrieve data about users whose last name is smith by creating an index, then querying the table as follows:

cqlsh:mykeyspace> CREATE INDEX ON users (lname);
cqlsh:mykeyspace> SELECT * FROM users WHERE lname = ‘smith’;

user_id | fname | lname
———+——-+——-
1745 |  john | smith
1746 |  john | smith

(2 rows)

cqlsh:mykeyspace>

Node tool

vijay@cluster-01:~$ nodetool -h localhost  status
Note: Ownership information does not include topology; for complete information, specify a keyspace
Datacenter: datacenter1
=======================
Status=Up/Down
|/ State=Normal/Leaving/Joining/Moving
—  Address    Load       Tokens  Owns   Host ID                               Rack
UN  127.0.0.1  117.04 KB  256     100.0%  971c1a4f-4e49-4400-801a-2e27d46af032  rack1
vijay@cluster-01:~$

For GUI Installation 

http://downloads.datastax.com/community/opscenter-5.0.tar.gz

free : https://github.com/tomekkup/helenos