• Like


Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

GQL cheat sheet latest



Published in Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
    Be the first to like this
No Downloads


Total Views
On SlideShare
From Embeds
Number of Embeds



Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

    No notes for slide


  • 1. GQL cheatsheet GQL The sones Graph Query Language (GQL) allows you to create, modify, administrate and query a graph (database). sones Login and Access sones graphDB can be accessed through a number of different interfaces like SOAP WebService, REST - even a WebShell running inside every browser is CREATE VERTEX Create a user-defined vertex type TRUNCATE Removes all records from a user-defined vertex available. CREATE [ABSTRACT] VERTEX vertex_type_def TRUNCATE vertex CREATE VERTICES Create user-defined vertices having circular dependencies DESCRIBE Get information on items within the database REST The REST API can be used to run GQL queries. The query is encapsulated CREATE VERTICES [ABSTRACT] vertex_type_def [, [ABSTRACT] vertex_type_def]] DESCRIBE AGGREGATES | into the URL (URL encoded) and data then is returned in the specified format (xml / json / DESCRIBE AGGREGATE identifier | ALTER VERTEX Manipulates a user-defined vertex DESCRIBE EDGES | text). Basic authentication is mandatory. ALTER VERTEX vertex DESCRIBE EDGE identifier | ADD ATTRIBUTES(attr_definition [,attr_definition])| DESCRIBE FUNCTIONS | DROP ATTRIBUTES (identifier [,identifier]) | DESCRIBE FUNCTION identifier | ADD BACKWARDEDGES (backward_edge_def [,backward_edge_def]) | DESCRIBE INDICES | DROP BACKWARDEDGES (identifier [,identifier]) | DESCRIBE INDEX identifier [edition] | RENAME ATTRIBUTE identifier TO identifier | DESCRIBE SETTINGS [ON VERTEX vertex | ON ATTRIBUTE attr_definition | ON DB | ON SESSION] | RENAME TO identifier | DESCRIBE SETTING identifier [ON VERTEX vertex | ON ATTRIBUTE attribute | ON DB | ON SESSION] RENAME BACKWARDEDGE identifier TO identifier | DESCRIBE TYPES | UNIQUE (identifier [,identifier]) | DESCRIBE VERTEX vertex DROP UNIQUE | DROP MANDATORY | SETTING Set, get or remove a setting (in a session or global) MANDATORY (identifier [,identifier]) | SETTING DB setting_operation | DEFINE ATTRIBUTES (identifier [,identifier]) | SETTING SESSION setting_operation | UNDEFINE ATTRIBUTES (identifier [,identifier]) | SETTING [TYPE | VERTEX] identifier setting_operation | COMMENT = "<string>" SETTING ATTRIBUTE identifier setting_operation DROP VERTEX Deletes a user-defined vertex SELECT Retrieve objects or their data from a graph DROP VERTEX vertex FROM identifier [reference] [,identifier [= <value>] [reference]] SELECT * | # | - | > | < | selection [,selection] | CREATE INDEX Creates an index on a user-defined vertex @Primitive-Datatype [,@Primitive-Datatype] CREATE INDEX [identifier] [EDITION edition_identifier] [WHERE where_condition] [GROUP BY identifier] [ORDER BY identifier] WebShell sones graphDB WebShell is a unix-like shell in a web browser allowing the ON VERTEX identifier (index_attribute_list) [INDEXTYPE identifier] [OFFSET <number>] [LIMIT <number>] [DEPTH <number>] user to interact with an instance of a sones graphDB. It is based on well-known technologies REBUILD INDICES rebuilds all or specific index of a user-defined vertex and libraries like HTML, JavaScript, JQuery and our REST API Authentication is mandatory. API. REBUILD INDICES [vertex [,vertex]] BUILT- BUILT-IN Datatypes (case sensitive) Anyone can gain access to a personalized instance by logging on to http://www.sones.com. DROP INDEX Deletes an index of a user-defined vertex Integer, UnsignedInteger, Double, String, Boolean, DateTime, List<Primitive-Datatype>, FROM vertex DROP INDEX index_identifier [EDITION edition_identifier] SET<Primitive-Datatype>, SET<Userdefined-Datatype> useful commands: INSERT Insert an object into a graph Aggregates / Functions INSERT INTO Identifier VALUES (attr_assign [,attr_assign]) [WHERE where_condition] COUNT | AVG | CONCAT | TOUPPER | MAXWEIGHT | SUBSTRING | TOP | PATH | ... command parameters description INSERTORUPDATE Inserts or Updates an object into a graph Comments help n/a displays help text INSERTORUPDATE vertex VALUES (attr_assign [,attr_assign]) [WHERE where_condition] vertex_type_def = identifier [EXTENDS Identifier] [ATTRIBUTES(attr_definition clear n/a clears the screen [,attr_definition])] [BACKWARDEDGES(backward_edge_def [,backward_edge_def])] [UNIQUE INSERTORREPLACE Inserts or Replaces an object into a graph (identifier [,identifier])] [MANDATORY(identifier [,identifier])] [INDICES format xml | json | text by default results are displays as xml. Output INSERTORREPLACE vertex VALUES (attr_assign [,attr_assign]) [WHERE where_condition] (index_on_create)] [COMMENT = "<string>"] UPDATE Updates an object within a graph attr_definition = built-in_type <attribute_name> [=DefaultValue] UPDATE vertex SET (attr_update [,attr_update]) [WHERE where_condition] sample json output: attr_assign = identifier=value | REPLACE Replaces an object within a graph identifier={REF(identifier=value) | REFUUID(uuid) | SETOF(identifier=value REPLACE vertex VALUES (attr_assign [,attr_assign]) WHERE where_condition [,identifier=value]) | LISTOF(value [,value]) | SETOFUUIDS(uuid [,uuid])} { attr_update = identifier={value | REF(identifier=value) | REFUUID(uuid)} | "query": "FROM User u SELECT *", DELETE Deletes attributes from an vertex or the vertex itself identifier {= | += | -=} {SETOF(identifier=value [,identifier=value]) | LISTOF(value "result": "Successful", FROM vertex DELETE [identifier [,identifier] ] [WHERE where_condition] [,value]) | SETOFUUIDS(uuid [,uuid])} "warnings": [], EXPORT Create a complete (query) dump in different formats vertex = case-sensitive name of any existing vertex "errors": [], EXPORT [VERTICES vertex [,vertex]] [{GDDL|GDML|ALL}] [AS {GQL}] "results": [TO {‘file:...‘ | ‘http://...‘}] setting_operation = SET ("SettingName"=value [,"SettingName"=value]) | GET [{ ("SettingName" [,"SettingName"]) | REMOVE ("SettingName" [,"SettingName"] IMPORT Import queries "Username": "User1", IMPORT FROM {‘file:...‘ | ‘http://...‘} FORMAT {GQL} SettingName = (DEPTH, SETREADONLY, TYPE, UUID, SHOWREVISION, SELECTTIMEOUT, ...) "Age": "25" [PARALLELTASKS(number)] [COMMENTS(‘value‘ [,‘value‘])] selection = [reference.]identifier [= <value> | ?= <value>] [AS alias] }], Add edges between vertices "Duration": ["1","ms"] LINK LINK vertex (identifier=value [,identifier=value]) } TO vertex (identifier=value [,identifier=value]) VIA edge_attribute UNLINK Remove edges between vertices UNLINK vertex (identifier=value [,identifier=value]) FROM vertex (identifier=value [,identifier=value]) VIA edge_attribute based on latest GQL specification — comments to info@sones.com are welcome — Last Update: Oct 25th, 2010 © sones GmbH
  • 2. GQL cheatsheet examples Examples sones CREATE VERTEX INSERT CREATE VERTEX UserProfile INSERT INTO UserProfile VALUES (Name = "User1", Age = 25, UUID = "ID1") ATTRIBUTES (String Username, Integer Age, SET<UserProfile> Friends) INSERT INTO UserProfile VALUES (Name = "User2", Age = 22, Friends = SETOF(Name = "User1"), UUID = "ID2") BACKWARDEDGES (UserProfile.Friends FriendOf) INSERT INTO UserProfile VALUES (Name = "User3" Father = REF(Name = "User1"), Enemies = SETOF(Name = "User2")) UNIQUE (Username) MANDATORY (Username) INSERT INTO UserProfile VALUES (Name = "User4", WeightedFriends = SETOF(Name = "User1":(1.2))) INDICES ( (Idx_Age ON ATTRIBUTES Age), (Username) ) INSERT INTO UserProfile VALUES (Name = "User5", Hobbies = LISTOF("Books","Music")) COMMENT = "The UserProfile vertex" INSERT INTO UserProfile VALUES (Name = "UndefinedAttributeUser", Weight = 70.1) /* Undefined Attribute */ CREATE VERTEX SecondUserProfile EXTENDS UserProfile INSERT INTO UserProfile VALUES (Name = "User2", Age = 22, Friends = SETOFUUIDS("ID1", "ID2"), Father = REFUUID("ID1"))) ATTRIBUTES (SET<UserProfile> Enemies, String Language = "en") CREATE VERTEX ThirdUserProfile EXTENDS SecondUserProfile UPDATE ATTRIBUTES (LIST<String> Hobbies) UPDATE UserProfile SET (Friends += SETOF(Name="User2", Name="User4") ) WHERE Name = "User3" INDICES (Language) UPDATE UserProfile SET (Friends -= SETOF(Name="User4") ) WHERE Name = "User3" CREATE VERTEX WeightedProfile UPDATE UserProfile SET (Friends = SETOF(Name="User2"), Enemies += SETOFUUIDS("ID1") ) WHERE Name = "User3" ATTRIBUTES (SET<WEIGHTED(Double, DEFAULT = 1.0, SORTED = DESC)<WeightedProfile>> Friends) SELECT CREATE VERTICES FROM UserProfile U SELECT U.Friends.Friends.Name WHERE U.Name = "User1" CREATE VERTICES FROM UserProfile SELECT Name WHERE Friends.Friends.Name = "User1" Tag ATTRIBUTES (String Name) BACKWARDEDGES (Website.Tags TaggedSite) INDICES (Name) FROM UserProfile SELECT Friends.TOP(10) Website ATTRIBUTES (String Name, String URL, SET<Tag> Tags) INDICES (Name) DESCRIBE ALTER VERTEX Functions DESCRIBE TYPES ALTER VERTEX UserProfile FROM UserProfile U DESCRIBE VERTEX UserProfile ADD ATTRIBUTES (SET<UserProfile> Enemies, UserProfile Father) SELECT U.Name.CONCAT("-> Age:", U.Age) AS "Name" DESCRIBE SETTING Depth ON VERTEX UserProfile ADD INDICES ( (Idx_Age ON ATTRIBUTES Age), (Username) ) FROM UserProfile U DESCRIBE SETTING Depth ON ATTRIBUTE UserProfile.Friends RENAME ATTRIBUTE Friends TO AllFriends SELECT U.Name, CURRENTDATE() DESCRIBE SETTINGS ON DB MANDATORY(Username, Age) FROM UserProfile U DESCRIBE INDEX Tag.Name DEFINE(Double UndefinedProp) SELECT U.WeightedFriends.MAXWEIGHT() DESCRIBE FUNCTION CONCAT UNDEFINE(DefinedProp) FROM UserProfile U COMMENT = "The UserProfile vertex" SELECT U.Name.SUBSTRING(2,3) ALTER VERTEX UserProfile REPLACE FROM UserProfile U ADD BACKWARDEDGES (UserProfile.Enemies EnemyOf) REPLACE SELECT U.Friends.Path(S.Name = "User1", 10, 10, "true", "false") ALTER VERTEX UserProfile UserProfile VALUES (Name = "User1", Age = 50) WHERE U.Name = "User2" DEPTH 1 ADD ATTRIBUTES (SET<WEIGHTED(Double, DEFAULT = 1.5, SORTED = ASC)<UserProfile>> WeightedFriends ) WHERE Name= "User1-new" DROP MANDATORY Aggregates ALTER VERTEX UserProfile DELETE FROM UserProfile U DROP ATTRIBUTES (Enemies, Father) FROM UserProfile DELETE WHERE Name = "User1" SELECT AVG(U.Age) FROM UserProfile U DROP VERTEX EXPORT SELECT AVG(U.Age), U.Name DROP VERTEX SecondUserProfile GROUP BY U.Name EXPORT AS GQL OFFSET 10 EXPORT GDDL AS GQL LIMIT 10 DROP INDEX EXPORT GDML AS GQL TO "file:gdml_export.gql" FROM UserProfile DROP INDEX IDX_Name IMPORT CREATE INDEX IMPORT FROM "http://developers.sones.de/gdml_export.gql" FORMAT GQL CREATE INDEX ON UserProfile(City) IMPORT FROM "file:gdml_export.gql" FORMAT GQL PARALLELTASKS(3) COMMENTS("#", "-") CREATE INDEX IDX_Name ON VERTEX UserProfile (Name) INDEXTYPE Hashtable LINK TRUNCATE LINK UserProfile (Name = "User1") TO UserProfile (Name = "User2") TRUNCATE UserProfile VIA Friends INSERTORUPDATE UNLINK INSERTORUPDATE UNLINK UserProfile (Name = "User1") FROM UserProfile (Name = "User2") UserProfile VALUES (Name = "User1", Age = 40) WHERE Name = "User1" VIA Friends INSERTORUPDATE UserProfile VALUES (Name = "User5") WHERE Name = "User5" SETTING SETTING VERTEX User SET („DEPTH“=2) INSERTORREPLACE INSERTORREPLACE UserProfile VALUES (Name = "User1-new", Age = 50) WHERE Name = "User1" based on latest GQL specification — comments to info@sones.com are welcome — Last Update: Oct 25th, 2010 © sones