Back Home

Database and Schemas

OrientDb can be run

  • schemeless - where we don't define the index type and new fields can be added dynamically
  • scheme - where we explicitly add the schema and index type

Embedded (Json) documents

the Embedded type supports any valid Json document

orientdb> INSERT INTO examples (embedded) VALUES ({"name":"James","age":23})

allows us to

SELECT embedded.age  FROM examples

Embedset functions:

  • expand(embset) - extract each element of the set into individual row
  • first()
  • last()
  • size()
  • remove()
  • removeAll()
  • keys() e.g select embedded.keys() from examples
  • removeAll()
  • toJson()

Containers (set) datatype

A container is to support arrays, sets, lists objects:

 INSERT INTO Examples (embset) VALUES ([{"name":"John","age":24},{"name":"Barbara","age":23}])

This allows us to use set functions:

SELECT embset.size() FROM examples

Getting Strict



OrientDB doesn't use JOINs. Instead it uses LINKs. A LINK is a relationship managed by storing the target RID in the source record. e.g Invoice → Customer, then you have a pointer to Customer inside Invoice as an attribute.

This means that a JOIN operation has no computational cost to retrieve a related document from a given one.

OrientDB supports different kinds of relationships:

  • LINK, to point to one record only
  • LINKSET, to point to several records. Like Java Sets, the same RID can only be included once. The pointers also have no order
  • LINKLIST, to point to several records. Like Java Lists, they are ordered and can contain duplicates
  • LINKMAP, to point to several records with a key stored in the source record. The Map values are the RIDs. Works like the Java Map<?,Record>.

To follow a relationship we can follow the IN or OUT paths e.g

SELECT name, OUT("Parent").name[0]  FROM category_prod LIMIT 5000

OrientDb Rest Interface

  def url = "http://localhost:2480/database/demo"
		HttpClient client = new HttpClient()
		HttpMethod get = new GetMethod(url);
		Credentials credentials = new UsernamePasswordCredentials("admin", "admin");
		client.getState().setCredentials(AuthScope.ANY, credentials);
		def result = new groovy.json.JsonSlurper().parseText(  get.getResponseBodyAsString().toString())
		println "pretty printing .. "
		println JsonOutput.prettyPrint( get.getResponseBodyAsString().toString() )

Spark OrientDB Connector allows you to:

  • access OrientDB classes as Spark RDDs
  • access OrientDB graphs as GraphX graphs
  • write RDDs to OrientDB
  • write GraphX graphs to OrientDB
orientdb.txt · Last modified: 2018/01/26 09:07 by root
RSS - 200 © CrosswireDigitialMedia Ltd