Multiple functions needed on ordered lists
Scenario:
I have one album and that album references many photos (maybe 1000s). The photos are shared between Albums.
The album can have additional properties to its instance/reference of photo1, and another album can have different properties to the its own instance/reference of the same photo1.
For example, Album1-SharedPhoto1 has property LikeCount which is different from Album2-SharedPhoto1 LikeCount.
The photo references in an album will naturally need to be ordered and can be re-ordered by the Album owner.
So user should be able to...
- add a photo to beginning of album. (before all)
- add a photo to end of album. (after all)
- move photo 15 before photo 2
- move photo 15 after photo 81
- delete a photo reference by id (not position)
- update a property of a photo by id (not position)
- fetch detail of photo 15 only..
Since the number of photos can be large, it would be best to have these functions work on the database level. Getting the entire set of photos to re-order them on the middleware and send back is very expensive.
I would hope that the solution not to use EmbeddedList as it's likely to give us more trouble later on as not being bi-directional and would require to add more indexes on embedded items. Edges would just be great if we can order them.
Thanks.
HI, small note if we can use vertex centric indexes here. It will be part of 1.7 . So it is like linkmap sorted by key. So you update key and change edge position.
Hi Andrey,
I read a little about vertex centric indexes but not enough to understand the impact in performance, size, etc? Seems to me that this is what Luca mentioned when he talked about speeding up super nodes. is it?
What do we gain/lose by using vertex centric indexes?
Safwan
On Thu, Jan 23, 2014 at 11:00 AM, Andrey Lomakin [email protected]:
HI, small note if we can use vertex centric indexes here.
— Reply to this email directly or view it on GitHubhttps://github.com/orientechnologies/orientdb/issues/1994#issuecomment-33106868 .
I've just pushed a small fix that allow to use other collections to manage edges. So if you declare it as linklist should work. I've had no time to write test cases, but maybe you could try if works. Create the property as linklist as:
create property Album.photos linklist
hmmm. So I declare album.photos as linkList. create edges the normal way? use the edge name album.photos?
finally, do you know if sonatype builds are working? because I'm not setup to build from git.
Thanks
On Thu, Jan 23, 2014 at 11:17 AM, Luca Garulli [email protected]:
I've just pushed a small fix that allow to use other collections to manage edges. So if you declare it as linklist should work. I've had no time to write test cases, but maybe you could try if works. Create the property as linklist as:
create property Album.photos linklist
— Reply to this email directly or view it on GitHubhttps://github.com/orientechnologies/orientdb/issues/1994#issuecomment-33107822 .
Call the property
out_Photos
If the direction is out and the edge's class is Photos.
Sonatype is updated.
Lvc@
Sent from Mobile device Il 23/gen/2014 10:39 "SafwanHak" [email protected] ha scritto:
hmmm. So I declare album.photos as linkList. create edges the normal way? use the edge name album.photos?
finally, do you know if sonatype builds are working? because I'm not setup to build from git.
Thanks
On Thu, Jan 23, 2014 at 11:17 AM, Luca Garulli [email protected]:
I've just pushed a small fix that allow to use other collections to manage edges. So if you declare it as linklist should work. I've had no time to write test cases, but maybe you could try if works. Create the property as linklist as:
create property Album.photos linklist
— Reply to this email directly or view it on GitHub< https://github.com/orientechnologies/orientdb/issues/1994#issuecomment-33107822>
.
— Reply to this email directly or view it on GitHubhttps://github.com/orientechnologies/orientdb/issues/1994#issuecomment-33109138 .
@SafwanHak The only problem with current collections that they are embedded and are not optimized to track thousands of links. so cons is you will have slower insertion speed than on linklist during add operation (actually do not think that you will notice difference between let say 1ms and 2 ms), but cons is that if you work with big collections of links selection of records, iteration by links and addition of new links will be faster. For example: .you want to add to add one link to collection then you need to deserialize 10 000 items, add one item and serialize 10 000 items, the same if you want to change position of link in list plus take in account that you have to copy half of these items on new positions, but in case of vertex centric indexes only small part of these 10 000 items will be deserialized/serialized.
Right. So the best solution is to use link list then. The question is can we teach a link list to be ordered? Really edges not linked list because I need additional properties on that edge/link.
Do you know what I mean? If you want we can have a quick call. Let me know.
Sent from my iPhone
On Jan 23, 2014, at 13:17, Andrey Lomakin [email protected] wrote:
@SafwanHak The only problem with current collections that they are embedded and are not optimized to track thousands of links. so cons is you will have slower insertion speed than on linklist during add operation (actually do not think that you will notice difference between let say 1ms and 2 ms), but cons is that if you work with big collections of links selection of records, iteration by links and addition of new links will be faster.
— Reply to this email directly or view it on GitHub.
@SafwanHak "Right. So the best solution is to use link list then." How did you conclude this ? deserialization and serialization of 10 000 items (linklist) instead of partion of it (aboout 100 (vertex centic index)) can not be faster. but now the only way to implement this now is to use linklist it is not linked list it is list of links. (List from collection API) so it is ordered
@lvca I will write tests for this solution if you do not mint to keep branch stable.
Great
Sent from Mobile device Il 23/gen/2014 14:15 "Andrey Lomakin" [email protected] ha scritto:
@lvca https://github.com/lvca I will write tests for this solution if you do not mint to keep branch stable.
— Reply to this email directly or view it on GitHubhttps://github.com/orientechnologies/orientdb/issues/1994#issuecomment-33122445 .
I forgot that link list is internal. So actually edges is what I should've said.
I see from your other email that you will do tests. Will that test include all the points from this morning. Including re-ordering? And can it be done by SQL?
Thanks
Sent from my iPhone
On Jan 23, 2014, at 15:09, Andrey Lomakin [email protected] wrote:
@SafwanHak "Right. So the best solution is to use link list then." How did you conclude this ? So for you deserialization and serialization of 10 000 items (linklist) instead of partion of it (aboout 100) is faster ?
— Reply to this email directly or view it on GitHub.
I will add tests to force blueprints test suite to use linklist instead of ridset and ridbag. But it will be next week task. I have to finish set of tasks for this week related to overall graphdb performance.
Also if we need to change position of edge using SQL we can do it only directly working with properties (once again vertex centric index will not have this limitation ) ) and we need to add new syntax for this, so you should use to sql commands remove item with index and then add item to index. I will create issue for this.
I've applied small changes to support ordered edge collection. Now this test case works. The last part it's a little bit tricky by accessing to the underlying list of documents, but works.
package com.orientechnologies.orient.graph.blueprints;
import com.orientechnologies.orient.core.record.impl.ODocument;
import com.tinkerpop.blueprints.Direction;
import com.tinkerpop.blueprints.Edge;
import com.tinkerpop.blueprints.Vertex;
import com.tinkerpop.blueprints.impls.orient.OrientEdgeType;
import com.tinkerpop.blueprints.impls.orient.OrientGraph;
import com.tinkerpop.blueprints.impls.orient.OrientVertex;
import com.tinkerpop.blueprints.impls.orient.OrientVertexType;
import org.junit.Test;
import java.util.List;
import static junit.framework.TestCase.assertEquals;
public class OrderedEdgesGraphTest {
private static String DB_URL = "memory:orderedEdgesDatabase";
private static OrientGraph graph;
private final OrientVertex mainPerson;
public OrderedEdgesGraphTest() {
graph = new OrientGraph(DB_URL);
graph.setAutoStartTx(false);
graph.commit();
if (graph.getEdgeType("Knows") == null) {
OrientEdgeType knows = graph.createEdgeType("Knows");
OrientVertexType person = graph.createVertexType("Person");
person.createEdgeProperty(Direction.OUT, "Knows").setOrdered(true);
}
graph.setAutoStartTx(true);
mainPerson = graph.addVertex("class:Person", new Object[] { "index", 0 });
for (int i = 1; i < 101; ++i) {
final Vertex newVertex = graph.addVertex("class:Person", new Object[] { "index", i });
mainPerson.addEdge("Knows", newVertex);
}
}
@Test
public void testEdgeOrder() {
OrientVertex loadedPerson = graph.getVertex(mainPerson.getId());
int i = 1;
for (Edge e : loadedPerson.getEdges(Direction.OUT)) {
assertEquals(e.getVertex(Direction.IN).getProperty("index"), i++);
}
graph.shutdown();
}
@Test
public void testReplacePosition() {
OrientVertex loadedPerson = graph.getVertex(mainPerson.getId());
int i = 1;
List<ODocument> edges = loadedPerson.getRecord().field("out_Knows");
ODocument edge10 = edges.remove(9);
edges.add(edge10);
graph.shutdown();
graph = new OrientGraph(DB_URL);
loadedPerson = graph.getVertex(mainPerson.getId());
edges = loadedPerson.getRecord().field("out_Knows");
assertEquals(graph.getVertex(edges.get(9)).getProperty("index"), 11);
assertEquals(graph.getVertex(edges.get(99)).getProperty("index"), 10);
graph.shutdown();
}
}