I am trying to implement this new upsert edge feature available with v3.0.3 but getting exception com.orientechnologies.orient.core.exception.OCommandExecutionException: Error updating edge: 'out' is not a vertex.
I have created a class Person with Name field as unique index and Friend with field id as unique index.
Command issued : UPDATE EDGE Friend SET in = (SELECT FROM Person WHERE Name = 'name1' ) , out = (SELECT FROM Person where Name = 'name2') , id = 'f1' UPSERT WHERE id = 'f1'. Please let me know if I am using this correctly. Thanks!
Related
I have a scenario where I need to fetch list of string values from a table.
I need to query the Subject table and get list of subjects:
EmployeeDetails emp = new EmployeeDetails();
emp.subjects = from x in EmpDB.subjects
join y in EmpDB.employeeInfo
on x.subjectCode equals y.subjectCode select new
{
x.subjectTitle,
}.toList();
I have an employee ID which I need to query the EmployeeDetails table and get SubjectCodes of that particular Employee ID, and using those subject codes, I need to query the Subject table and get the subject values.
I assume that in EmployeeDetails class you have property Subjects with List.
EmployeeDetails emp = new EmployeeDetails();
emp.subjects = (from x in EmpDB.subjects
join y in EmpDB.employeeInfo on x.subjectCode equals y.subjectCode
where y.EmployeeId = <<your ID>> // Employee ID you searching
select x.subjectTitle).ToList();
For the given SOQL query, trying to optimize SOQL Query. I have two queries
Query 1 to get userID from salesforce for the given user account
SELECT id From User WHERE Username = 'test#testmail.com'
Query 2 for the given user ID find custom objects
SELECT Id,Headline__c,Description__c
FROM Incident__c
WHERE Id IN (SELECT Incident__c FROM Node_Affected__c
WHERE (Incident__r.Account__c = '034524000000uzurX')
AND Incident__r.Indicator__c = false)
Now I want to optimize it to one query such that I dont have to make two api calls from external system. So I was trying
SELECT Id,Headline__c,Description__c
FROM Incident__c
WHERE Id IN (SELECT Incident__c FROM Node_Affected__c
WHERE (Incident__r.Account__c = null OR Incident__r.Account__c IN (SELECT id From User WHERE Username = 'test#testmail.com'))
AND Incident__r.Indicator__c = false)
But I get the following error
MALFORMED_QUERY:
Incident__r.Account__c IN (SELECT id From User WHERE Username = 'test#testmail.com'))
^
ERROR at Row:5:Column:87
Nesting of semi join sub-selects is not supported
Is there any better way to solve this type of problem? Thanks in advance :)
You should be able to use the SOQL feature to follow foreign keys and follow the account__c relationship to the user table and filter on username from there, e.g.
SELECT Id, Headline__c, Description__c
FROM Incident__c
WHERE Id IN (SELECT Incident__c FROM Node_Affected__c
WHERE (Incident__r.Account__c = null OR
Incident__r.Account__r.Username = 'test#testmail.com')
AND Incident__r.Indicator__c = false)
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
I am using OrientDB to store information about video rentals. I represent members and movies as nodes. And whenever a member borrows a movie I add an edge between them. The dataset has user borrowing movie multiple times. Also I am required to store in which month/season (still deciding which will suit our needs but besides the point) was the movie rented. I was planning to store the above mentioned detail on the edge.But I came across this:
http://orientdb.com/docs/2.1/Performance-Tuning-Graph.html
And it is recommended to avoid storing properties on edges. I wanted to know whether I should change my approach ? If yes then what is the alternative?
Thanks in advance.
I think in your case you might opt for the creation of property directly on the edge. The alternative to store data related to rental is to create a third node (ex. RentalData) between Member and Movies and utilize PK and FK fields, but it would be similar to the relational DB and not necessary.
I reproduced a small DB:
create class Member extends V;
create property Member.id integer;
create property Member.name string;
create property Member.surname string;
create index Member.id unique;
create class Movie extends V;
create property Movie.id integer;
create property Movie.title string;
create property Movie.minutes integer;
create index Movie.id unique;
create class borrows extends E;
create property borrows.rentaldate Datetime;
create vertex Member set id = 1, name = "Paul", surname = "Green";
create vertex Member set id = 2, name = "John", surname = "Smith";
create vertex Member set id = 3, name = "Frank", surname = "Redding";
create vertex Movie set id = 1, title = "Interstellar", minutes = 170;
create vertex Movie set id = 2, title = "The Gladiator", minutes = 176;
create edge borrows from (select from Member where id = 1) to (select from Movie where id = 1) set rentaldate = sysdate();
create edge borrows from (select from Member where id = 1) to (select from Movie where id = 2) set rentaldate = sysdate();
create edge borrows from (select from Member where id = 2) to (select from Movie where id = 2) set rentaldate = sysdate();
create edge borrows from (select from Member where id = 3) to (select from Movie where id = 1) set rentaldate = sysdate();
create edge borrows from (select from Member where id = 3) to (select from Movie where id = 2) set rentaldate = sysdate();
I stored the "rentaldata" property directly on the edge "borrows" to associate the member to the movie borrowed and I think you could do it like me.
From the very same link you provided:
Use the schema
Starting from OrientDB 2.0, if fields are declared in the schema,
field names are not stored in document/vertex/edge themselves. This
improves performance and saves a lot of space on disk.
source
I'm trying to create edges between existing vertices queried by their indexed IDs, similar to the first answer here, but using this index lookup query instead of the label query:
CREATE EDGE cite
FROM
(SELECT FROM index:<className>.<indexName> WHERE key = "<keyString>")
TO
(SELECT FROM index:<className>.<indexName> WHERE key = "<keyString>")
This gives me the following error: com.orientechnologies.orient.core.exception.OCommandExecutionException: Source vertex '#-1:-1' not exists
Possibly relevant:
When I just query SELECT FROM index:<className>.<indexName> WHERE key = "<keyString>" by itself it returns an array object structured like:
[ { '#type': 'd',
key: '<keyString>',
rid: { cluster: <actual cluster>, position: <actual position> }
#rid: { cluster: -1, position: -1 } } ]
I'm guessing that the error has something to do with the CREATE EDGE query using the #rid instead of the rid but I'm not sure.
The query successfully creates the edges if I simply use the #<actual cluster>:<actual position> instead of the SELECT subquery.
Any ideas what I might be doing wrong?
Edit: In the interest of replicability, I have the same problem in the GratefulDeadConcerts database when I (1) add a property name to the V class schema, (2) create a unique nameIndex index of V using the name property under V, and then (3) use the following query:
create edge followed_by from (select from index:nameIndex where key = 'HEY BO DIDDLEY') to (select from index:nameIndex where key = 'IM A MAN')
Why don't you query the class directly?
CREATE EDGE cite
FROM
(select from Class where field = '<keyString>')
TO
(select from Class where field = '<keyString>')
Select from index return a temp document as result set with key,and rid
you can try but i don't know if it will work
SELECT expand(rid) FROM index:<className>.<indexName> WHERE key = "<keyString>"