Can't see the first property of a node on Age Viewer - postgresql

I have created a Book node called Book as follow:
Select * FROM cypher('graph_two',$$ CREATE (n:Book {title:'Something'}) $$) as (a agtype);
And a person Node as follows:
Select * FROM cypher('graph_two',$$ CREATE (n:User {Name:'Something'}) $$) as (a agtype);
And an edge between them as follows:
Select * FROM cypher('graph_two',$$ MATCH (a:User), (b:Book) CREATE (a)-[r:READS]->(b) Return r $$) as (r agtype);
And when I visualize this in age-viewer I get:
What am I doing wrong here? I want the User name and the Book title to be displayed rather than the OId.

If you click on any Node Label (your's are "Book" and "User") it will appear a bar on the bottom of the current graph scene. There you can set what the vertex or edge is currently displaying, the size of the vertex and also the color of them. This also works with the edges.

Related

Apache AGE - Changing Labels of Nodes and Edges

Is there any possible way to change the current label of a vertex or an edge? For example, if I create a graph to store movies and series and then create the following vertex:
SELECT * FROM cypher ('visual_arts', $$
CREATE (v:Movie {title: "The Last of Us", episodes: 4, seasons: 1, main_actors: ["Pedro Pascal", "Bella Ramsey"]})
RETURN v $$) as (v agtype);
And then I want to correct this vertex by changing the label to "Series" instead of "Movie". How can I do that?
I believe, this feature is currently in development right now. See https://github.com/apache/age/issues/464
In current version of AGE, we cannot update label of any vertex or edge.
To do so, the best way is to introduce a new property UpdatedLabel and set it to Series.
You can do so by:
SELECT * FROM cypher('visual_arts', $$
MATCH (v:Movie)
SET v.UpdatedLabel = "Series" RETURN v
$$) as (v agtype);
Now you can retrieve the Series by using:
SELECT * FROM cypher('visual_arts', $$
MATCH (v:Movie)
where v.UpdatedLabel = "Series" RETURN v
$$) as (v agtype);

OrientDB query to receive last vertex before a given date

Let's say I have the following list of vertices (connected by edges) in the orient database:
[t=1] --> [t=2] --> [t=3] --> [t=4] --> [t=5] --> [t=6] --> [t=7]
Each vertex has a timestamp t. I now want to receive the last vertex before a given date. Example: give me the last vertex before t=5, which is t=4.
Currently I'am using the following query to do this:
SELECT FROM ANYVERTEX WHERE t < 5 ORDER BY t DESC LIMIT 1
This is working fine when having up to let's say 1000 elements but the performance of that query drops with the number of elements inserted in the list. I already tried using an index, which improved the overall performance, but the problem, that the performance drops with the amount of elements still persists.
When building queries, always try to use the information you have about the relationship in your query to improve performance. In this case you don't need the sort (which is an expensive operation) because you know that the vertex you need has an incoming edge to the vertex, you can simply use that information in your query.
For example, let's say I have the following setup:
CREATE CLASS T EXTENDS V
CREATE VERTEX T SET t = 1
CREATE VERTEX T SET t = 2
CREATE VERTEX T SET t = 3
CREATE VERTEX T SET t = 4
CREATE VERTEX T SET t = 5
CREATE CLASS link EXTENDS E
CREATE EDGE link FROM (SELECT * FROM T WHERE t = 1) TO (SELECT * FROM T WHERE t = 2)
CREATE EDGE link FROM (SELECT * FROM T WHERE t = 2) TO (SELECT * FROM T WHERE t = 3)
CREATE EDGE link FROM (SELECT * FROM T WHERE t = 3) TO (SELECT * FROM T WHERE t = 4)
CREATE EDGE link FROM (SELECT * FROM T WHERE t = 4) TO (SELECT * FROM T WHERE t = 5)
Then I can select the vertex before any T as such:
SELECT expand(in('link')) FROM T WHERE t = 2
This query does the following:
Select the vertex from T where t=2
From that vertex, traverse the incoming edge(s) of type link
expand() the vertex from which that edge comes from to get all of its information
The result is exactly what you want:
This should give better performance (especially if you add an index on the attribute t of the vertices) because you are using all the information you know in advance about the relationship = the node you need has an edge to the node you select.
Hope that helps you out.

OrientDB combination of edge and vertex properties

I am trying to select a edge "Contained" that points to a "Rgb" vertex, in OrientDB 2.1, with PhpOrient. The edge haves a property "probability", and the Rgb haves a property "hex".
So:
Artist -> created -> Artwork -> contained -> Rgb.
This query finds the edge "Contained" with the property "probability".
SELECT *, EXPAND (OUT("Created").OUTE("Contained")) FROM Artist WHERE path="Achebach, Andreas"
This query finds the vertex Rgb with the property "hex".
SELECT *, EXPAND (OUT("Created").OUT("Contained")) FROM Artist WHERE path="Achebach, Andreas"
But I want to have both properties. How can I combine the queries to have one query, that can find both properties?
In v 2.1 you can do it with a subquery:
SELECT probability, inV().hex FROM (
SELECT expand(out("Created").outE("Contained"))
FROM Artist WHERE path="Achebach, Andreas"
)
In OrientDB v 2.2 you can also do it with pattern matching
MATCH
{class:Artist, as:a, where:(path="Achebach, Andreas")}
.out("created"){as:aw}
.outE("contained"){as:cont}
.inV(){as:rgb}
RETURN cont.probability, rgb.hex

OrientDB select unique Vertices from multiple Edges

I have 2 vertices User and Stamp. Vertices are related by three edges Have, WishToHave and Selling.
I'm wish to select unique Stamps that have any relation with User. To do it I was running this command:
select expand(out('Have', 'WishToHave', 'Selling')) from #12:0
The problem with this command is that it returns 'Stamp1' few times, because it has Have and Selling edges.
How can I select all unique/distinct Stamps related to User1?
To init test data for this example:
create class User extends V
create class Stamp extends V
create class Have extends E
create class WishToHave extends E
create class Selling extends E
create vertex User set name = 'User1'
create vertex Stamp set name = 'Stamp1'
create vertex Stamp set name = 'Stamp2'
create vertex Stamp set name = 'Stamp3'
create edge Have from (select from User where name = 'User1') to (select from Stamp where name = 'Stamp1')
create edge WishToHave from (select from User where name = 'User1') to (select from Stamp where name = 'Stamp2')
create edge Selling from (select from User where name = 'User1') to (select from Stamp where name = 'Stamp1')
create edge Selling from (select from User where name = 'User1') to (select from Stamp where name = 'Stamp3')
I tried your case with your structure:
To retrieve unique vertices you could use the DISTINCT() function. I can give you two examples:
Query 1: Using EXPAND() in the target query
SELECT EXPAND(DISTINCT(#rid)) FROM (SELECT EXPAND(out('Have', 'WishToHave', 'Selling')) FROM #12:0)
Output:
Query 2: Using UNWIND in the target query
SELECT EXPAND(DISTINCT(out)) FROM (SELECT out('Have', 'WishToHave', 'Selling') FROM #12:0 UNWIND out)
Output:
Hope it helps

2 vertices connected two times with the same edge on lightweight mode

The orientdb documentation says regarding lightweight edges:
two vertices are connected by maximum 1 edge, so if you already have one edge between two vertices and you're creating a new edge between the same vertices, the second edge will be regular
Looking at the following script:
drop database plocal:../databases/test-lightweight admin admin;
create database plocal:../databases/test-lightweight admin admin;
connect plocal:../databases/test-lightweight admin admin;
alter database custom useLightweightEdges=true;
// Vertices
CREATE class Driver extends V;
CREATE PROPERTY Driver.name STRING;
// Edges
CREATE class Knows extends E;
CREATE PROPERTY Knows.in LINK Driver MANDATORY=true;
CREATE PROPERTY Knows.out LINK Driver MANDATORY=true;
// DATA
CREATE VERTEX Driver SET name = 'Jochen';
CREATE VERTEX Driver SET name = 'Ronnie';
// Jochen and Ronnie are very good friends
CREATE EDGE Knows FROM (SELECT FROM Driver WHERE name = 'Jochen') to (SELECT FROM Driver WHERE name = 'Ronnie');
CREATE EDGE Knows FROM (SELECT FROM Driver WHERE name = 'Jochen') to (SELECT FROM Driver WHERE name = 'Ronnie');
SELECT expand(out()) FROM (SELECT FROM Driver WHERE name = 'Jochen'); // 2 times Ronnie
SELECT count(*) FROM Knows; // 0
I would expect the last count to return 1, but it returns 0.
When I execute the same script but disabling the lightweight mode the result is 2 (as expected).