GQLcheatsheet
GQL The sones Graph Query Language (GQL) allows you to create, modify, administrate and query a graph (datab...
GQLcheatsheet examples
Examples
CREATE VERTEXCREATE VERTEXCREATE VERTEXCREATE VERTEX
CREATE VERTEX UserProfile
ATTRIBUTES ...
Upcoming SlideShare
Loading in …5
×

GQL cheat sheet latest

2,168 views

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
2,168
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
44
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

GQL cheat sheet latest

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

×