-
Notifications
You must be signed in to change notification settings - Fork 19
[orientdb] Install and Usage
Myungchul Shin edited this page Jun 9, 2015
·
28 revisions
- orientdb
- good instruction blog
- install
download community version say, orientdb-community-2.0.9.tar.gz
tar -zxvf orientdb-community-2.0.9.tar.gz
cd orientdb-community-2.0.9
cd bin
./server.sh
- tutorial
- SQL+
- python driver
- example query
<create edge via select>
create edge WorksAt from (select from Person where name="Bob") to (select from Company where name="네이버")
<select & expand>
select * from V where name = '네이버'
select expand(in("CeoOf")) from Company where name = '다음카카오'
: CeoOf class type inlink에 연결된 vertex
select expand(in_CeoOf.out) from Company where name = '다음카카오'
: CeoOf class type inlink의 out vertex
select name from (select expand(out_MemberOf.in) from V where name = 'John')
: name이 'John'인 vertex의 MemberOf edge와 연결된 vertex의 name
select out_Place_Coordinate.in.y from Place where name='제주특별자치도청'
: 이름이 '제주특별자치도청'인 Place record의 Place_Coordindate type의 out edge를 따라가서
: 해당 record의 y property를 출력
select expand(out_Address_Place.in) from ( select expand(out_Place_Address.in) from Place where "제주시 시청" in synonyms )
: edge를 한번 더 따라가면서 출력
<update edge command>
delete edge WorksAt from #12:3 to #13:2
create edge WorksAt from #12:3 to #13:0
<traverse>
traverse * from #12:0 while $depth <= 2
traverse * from #12:0 while $depth <= 3
traverse * from #12:5 while $depth <= 1
traverse * from #12:0 while $depth <= 2
== child들을 전부 가져온다
traverse * from (select @rid from Type where type='Place' and name='장소') while $depth <= 3
== traverse로 변경하면 $depth는 1 더해야 동일한 결과가 나온다
<update all property>
update MemberOf set name='소속'
create property MemberOf.name string
<remove property>
update MemberOf remove name
<rename edge class name>
http://stackoverflow.com/questions/26236442/renaming-existing-edge-relationships
alter class WorksAt name MemberOf
update V set out_MemberOf = out_WorksAt where out_WorksAt is not null
update V set in_MemberOf = in_WorksAt where in_WorksAt is not null
update V remove out_WorksAt where out_WorksAt is not null
update V remove in_WorksAt where in_WorksAt is not null
<delete vertex>
delete vertex @rid
: vertex와 연결된 edge 및 관련된 모든 정보들이 삭제됨
<select leaf node>
select * from V where out('Child').size() = 0
<remove edge and clean>
delete edge @rid
: 특정 id인 edge를 삭제한다.
update V remove in_ClassEdge where in_ClassEdge.size() = 0
update V remove out_ClassEdge where out_ClassEdge.size() = 0
: 삭제된 edge의 양쪽에 해당하는 record에 garbage in, out이 존재할 수 있으므로
: 찾아서 삭제한다.
<expand with select edge>
select expand(out) from Place_Category where @rid = #23:2
select expand(in) from Place_Category where @rid = #23:2
: Place_Category 클래스의 record id가 '#23:2'인 edge를 찾고, 그것의 시작, 끝에 해당하는 record를 보는 방법
<select with EMBEDDEDLIST STRING>
select from Place where "서귀포시청" in synonyms
: EMBEDDEDLIST STRING type인 synonyms에 '서귀포시청'이 있는 record를 출력
-
주의사항
1. Vertex class를 하나 만들고 record간 연결을 디폴트 'E'로 하는 경우,
select from ClassName where out('E').size() = 0
여기에서 out('E')가 먹히지 않는 버그가 있음
따라서, 반드시 edge는 별도의 class로 만들어서 적용해야한다.