Examples
A Weighted Graph
This document will give you a first impression on how to store data within the edges of a graph.

The given graph is a weighted graph connecting a single type of vertices – Tags – using a single type of edges – their weighted relationships.
Creating the “Tag” vertex type
For the creation of single vertex type we again use the CREATE TYPE statement. In this example the attribute “Name” is a single value basic type, whereas the attribute “RelatedTags” is a multivalue reference type with a special edge type “WEIGHTED<Double>“. This means that we want to store a numeric double precision value within every edge of our graph. The resulting GQL statement is the following:
CREATE TYPE Tag
ATTRIBUTES (
String Name,
List<WEIGHTED(Double,DEFAULT=1)<Tag>> RelatedTags
)
INDICES (Name)
The optional parameter “DEFAULT=1” within the CREATE TYPE statement will assume a value of “1” whenever no other value was given within an INSERT or UPDATE statement.
Inserting vertices
For inserting vertices we use the INSERT statement. Within an insert statement all attributes are optional by default, thus there is no need to store null–values.
INSERT INTO Tag VALUES (Name = 'Summer')
INSERT INTO Tag VALUES (Name = 'Sun')
INSERT INTO Tag VALUES (Name = 'Diving')
INSERT INTO Tag VALUES (Name = 'Fun')
Inserting edges
UPDATE Tag SET (RelatedTags = SETOF(Name = 'Summer' : (0.5)) ) WHERE Name = 'Sun'
UPDATE Tag SET (RelatedTags = SETOF(Name = 'Fun' : (4.0)) ) WHERE Name = 'Diving'
UPDATE Tag SET (RelatedTags = SETOF(Name = 'Diving' : (5.1)) ) WHERE Name = 'Fun'
UPDATE Tag SET (RelatedTags = SETOF(Name = 'Sun' : (1.0),
Name = 'Fun' : (5.3)) ) WHERE Name = 'Summer'
Inserting vertices and edges simultaneously
INSERT INTO Tag VALUES (Name = 'Water', RelatedTags = SETOF(Name='Sun' : (3.1),
Name='Diving' : (9.1),
Name='Fun' : (9.1)))
SELECTing data from the graph
Using the WebShell and XML as output format we now can run the following queries against the graph: FROM Tag SELECT *
<QueryResult>
<Query ResultType="Successful">FROM Tag SELECT *</Query>
<DBObject>
<Attribute Name="Name" Type="String">Summer</Attribute>
<Attribute Name="RelatedTags" Type="reference">not resolved</Attribute>
</DBObject>
<DBObject>
<Attribute Name="Name" Type="String">Sun</Attribute>
<Attribute Name="RelatedTags" Type="reference">not resolved</Attribute>
</DBObject>
<DBObject>
<Attribute Name="Name" Type="String">Diving</Attribute>
<Attribute Name="RelatedTags" Type="reference">not resolved</Attribute>
</DBObject>
<DBObject>
<Attribute Name="Name" Type="String">Fun</Attribute>
<Attribute Name="RelatedTags" Type="reference">not resolved</Attribute>
</DBObject>
<DBObject>
<Attribute Name="Name" Type="String">Water</Attribute>
<Attribute Name="RelatedTags" Type="reference">not resolved</Attribute>
</DBObject>
<Duration resolution="ms">1</Duration>
</QueryResult>
<QueryResult>
<Query ResultType="Successful">FROM Tag SELECT * DEPTH 1</Query>
<DBObject>
<Attribute Name="Name" Type="String">Summer</Attribute>
<Attribute Name="RelatedTags" Type="LIST" Count="2">
<DBObject Weight="5,3">
<Attribute Name="Name" Type="String">Fun</Attribute>
<Attribute Name="RelatedTags" Type="reference">not resolved</Attribute>
</DBObject>
<DBObject Weight="1">
<Attribute Name="Name" Type="String">Sun</Attribute>
<Attribute Name="RelatedTags" Type="reference">not resolved</Attribute>
</DBObject>
</Attribute>
</DBObject>
<DBObject>
<Attribute Name="Name" Type="String">Sun</Attribute>
<Attribute Name="RelatedTags" Type="LIST" Count="1">
<DBObject Weight="0,5">
<Attribute Name="Name" Type="String">Summer</Attribute>
<Attribute Name="RelatedTags" Type="reference">not resolved</Attribute>
</DBObject>
</Attribute>
</DBObject>
<DBObject>
<Attribute Name="Name" Type="String">Diving</Attribute>
<Attribute Name="RelatedTags" Type="LIST" Count="1">
<DBObject Weight="4">
<Attribute Name="Name" Type="String">Fun</Attribute>
<Attribute Name="RelatedTags" Type="reference">not resolved</Attribute>
</DBObject>
</Attribute>
</DBObject>
<DBObject>
<Attribute Name="Name" Type="String">Fun</Attribute>
<Attribute Name="RelatedTags" Type="LIST" Count="1">
<DBObject Weight="5,1">
<Attribute Name="Name" Type="String">Diving</Attribute>
<Attribute Name="RelatedTags" Type="reference">not resolved</Attribute>
</DBObject>
</Attribute>
</DBObject>
<DBObject>
<Attribute Name="Name" Type="String">Water</Attribute>
<Attribute Name="RelatedTags" Type="LIST" Count="3">
<DBObject Weight="9,1">
<Attribute Name="Name" Type="String">Diving</Attribute>
<Attribute Name="RelatedTags" Type="reference">not resolved</Attribute>
</DBObject>
<DBObject Weight="9,1">
<Attribute Name="Name" Type="String">Fun</Attribute>
<Attribute Name="RelatedTags" Type="reference">not resolved</Attribute>
</DBObject>
<DBObject Weight="3,1">
<Attribute Name="Name" Type="String">Sun</Attribute>
<Attribute Name="RelatedTags" Type="reference">not resolved</Attribute>
</DBObject>
</Attribute>
</DBObject>
<Duration resolution="ms">2</Duration>
</QueryResult>
Functions on weighted graphs
The weighted edges come with serveraly functions to make use of this weights.
MAXWEIGHT($attribute)
FROM Tag t SELECT t.Name, t.RelatedTags, MAXWEIGHT(t.RelatedTags) AS 'MaxWeight' DEPTH 1
TOP($attribute, number)
FROM Tag t SELECT t.Name, TOP(t.RelatedTags, 2) AS 'RelatedTags' WHERE t.Name = 'Summer' DEPTH 1
FROM Tag t SELECT t.Name, TOP(t.RelatedTags, 5) AS 'RelatedTags' WHERE t.RelatedTags.Name = 'Summer' DEPTH 1
