CREATE edge hasAppln FROM (select FROM person) TO (select FROM post)
CREATE edge hasAppln FROM (select FROM person) TO (select FROM post) where person.id = post.id
CREATE LINK out_hasAppln TYPE linkset FROM person.id To post.id
CREATE LINK in_hasAppln TYPE linkset FROM post.id To person.id
create edge hasAppIn from (select from person where id = personId) to (select from post where id = postId
)CREATE edge hasPost FROM person.id To post.id
java.lang.IllegalArgumentException: Argument 'person.id' is not a RecordId in form of string. Format must be:
create edge hasPost from ( select from person where id = 1 ) to ( select from post where id = 1 )
create edge Wrote let $a = 1 from ( select from person where id = $a ) to ( select from post where id = $a )
update person add out_Wrote=( select from post where id = $parent.current.id )
update post add in_Wrote=( select from person where id = $parent.current.id )
# Cleanup the empty collections
update person remove out_Wrote where out_Wrote.size() = 0
update post remove in_Wrote where in_Wrote.size() = 0
#Note that function definition defaults to sql so you have to specify javascript
create function test "somejavascript" LANGUAGE javascript
select test()
select from OFunction
delete from OFunction
etc.
CREATE LINK comments TYPE linkset FROM comment.postId To post.id INVERSE
update person add out_Wrote=( select from post where id = $parent.current.id )
update car add in_Wrote=( select from person where id = $parent.current.id )
# Cleanup the empty collections
update person remove out_Wrote where out_Wrote.size() = 0
update car remove in_Wrote where in_Wrote.size() = 0
# WARNING: this is not currenty valid syntax
create edge from ( select from car ) to ( select from car where $from.id=id )
or
create edge from ( select from car ) to ( select from car ) where $from.id=$to.id
create edge hasPost from ( select from person where id = 1 ) to ( select from post where id = 1 )
package orientdb.sql;
import com.orientechnologies.orient.core.sql.OCommandSQL;
import com.tinkerpop.blueprints.Vertex;
import com.tinkerpop.blueprints.impls.orient.OrientGraphFactory;
import com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx;
import org.junit.Before;
import org.junit.Test;
public class LoopEdge {
private OrientGraphFactory oGF;
private OrientGraphNoTx graphNoTx;
@Before
public void before() {
resetConnection();
}
@Test
public void all() {
dropDatabase();
resetConnection();
schema();
data();
link();
select();
}
public void resetConnection() {
if (oGF != null) {
oGF.close();
}
oGF = new OrientGraphFactory("plocal:orientdb/loopedge");
graphNoTx = oGF.getNoTx();
}
@Test
public void schema() {
graphNoTx.createVertexType("person");
graphNoTx.createVertexType("post");
graphNoTx.createEdgeType("Wrote");
}
@Test
public void dropDatabase() {
graphNoTx.drop();
}
@Test
public void data() {
graphNoTx.addVertex("class:person", "name","John", "person_id", 1);
graphNoTx.addVertex("class:post", "person_id", 1, "text", "hello");
graphNoTx.addVertex("class:post", "person_id", 1, "text", "there");
graphNoTx.addVertex("class:post", "person_id", 3, "text", "goodbye");
}
@Test
public void link() {
String sqlSelect = "select from person";
Iterable<Vertex> persons = graphNoTx.command(new OCommandSQL(sqlSelect)).execute();
for (Vertex person : persons) {
String rid = person.getId().toString();
Integer id = person.getProperty("person_id");
String sqlCreate = "create edge Wrote from " + rid + " to ( select from post where person_id = " + id + " )";
System.out.format("SQL:%s%n", sqlCreate);
graphNoTx.command(new OCommandSQL(sqlCreate)).execute("person", rid, "id", id);
}
}
@Test
public void select() {
String sqlSelect = "select *, out('Wrote').size() as postCount from person";
Iterable<Vertex> persons = graphNoTx.command(new OCommandSQL(sqlSelect)).execute();
for (Vertex person : persons) {
System.out.format("name:%s person_id:%s postCount:%s%n",
person.getProperty("name"),
person.getProperty("person_id"),
person.getProperty("postCount"));
}
}
public static void main(String[] args) {
LoopEdge loopEdge = new LoopEdge();
loopEdge.before();
loopEdge.all();
}
}
Hello Curtis,I had the same frustration (as you can see in this thread) and also check this related thread. People want JOIN syntax, because it's powerful, and then you could use that to create edges to unleash the full power of a graph database.I didn't really get the message across, so I hope your mentioning it again will help the developers understand that some kind of 'join' syntax would be useful: for exploring the database, and creating new, previously inexistent edges based on various properties from different vertices, (and extremely useful if you have some existing data from a relational database that you want to play with).I don't think there is a solution yet for what you want to do, but I do hope something ike that will be added soon to the SQL syntax.
Op donderdag 21 augustus 2014 20:00:58 UTC+2 schreef Curtis Mosters:
I just did it with: