OrientDB - Creating an edge using rid's from index queries - orientdb

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>"

Related

Postgresql Null value populates left table when doing a left join. Why is this happening?

When I make the query:
"select * from asset a where (a.login_id = $1) and (a.status = 'pub')";
I get back the expected result:
{
id: 23f8jfj8gh2,
name: 'Asset1',
status: 'pub',
create_date: 2020-11-12T07:00:00.000Z,
...
}
But when I add a left join onto the query like this:
"select * from asset a left join asset_image i on (a.id = i.asset_id) where (a.login_id = $1) and (a.status = 'pub')";
I get back:
{
id: null, <---- THIS NULL VALUE for the asset id
name: 'Asset1',
status: 'pub',
create_date: 2020-11-12T07:00:00.000Z,
...
asset_id: null,
orig_name: null,
mimetype: null,
created: null
}
I am new to SQL, and I have looked at the docs for left joins, but I can't seem to figure out exactly where this is going wrong. Any help would be much appreciated! Thanks.
If the asset_image table contains its own column with the name of id when your query gets no match between (a.id = i.asset_id) it will overwrite the id field with null.
You may need to define each tables id column with a more unique name eg.
asset_id to replace id in the asset table
image_id to replace id in the asset_image table
Your problem is probably the * in SELECT *, which is something that you should always avoid in code.
If the table asset_image also has a column named id, your result set will contain two columns named id. You are probably looking at the wrong one.
Using SELECT * gives you no control over the columns you get in the result set, their name and their order. You should use an explicit column list and give columns with the same name in both tables an alias that allows you to disambiguate them.

Update edge with upsert in OrientDB v3.0.3

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!

Cassandra Select Query for List and Frozen

I have user define type like
CREATE TYPE point ( pointId int, floor text);
And I have table like:
CREATE TABLE path (
id timeuuid,
val timeuuid,
PointList list<frozen <point>>,
PRIMARY KEY(id,val)
);
And have create index like
create index on path(PointList);
But the problem is I am not able to execute select query where PointList = [floor : "abc"].
I google for 2 hours but not able to find the hint.
I am using this query to execute select query
Select * from path where val = sdsdsdsdsds-dsdsdsd-dssds-sdsdsd and PointList contains {floor: 'eemiG8NbzdRCQ'};
I can see this data in my cassandra table but not able to get that data using above query.
I want select query where we can only use floor and val. Because we only have data for floor and val
I tried many different ways but nothing is working.
I would appreciate any kind of hint or help.
Thank you,
Frozen point means point type is frozen, you can't partially provide point value, you have to provide the full value of point
Example Query :
select * from path where pointlist CONTAINS {pointId : 1, floor : 'abc'};

Postgres Update Using Select Passing In Parent Variable

I need to update a few thousand rows in my Postgres table using the result of a array_agg and spatial lookup.
The query needs to take the geometry of the parent table, and return an array of the matching row IDs in the other table. It may return no IDs or potentially 2-3 IDs.
I've tried to use an UPDATE FROM but I can't seem to pass into the subquery the parent table geom column for the SELECT. I can't see any way of doing a JOIN between the 2 tables.
Here is what I currently have:
UPDATE lrc_wales_data.records
SET lrc_array = subquery.lrc_array
FROM (
SELECT array_agg(wales_lrcs.gid) AS lrc_array
FROM layers.wales_lrcs
WHERE st_dwithin(records.geom_poly, wales_lrcs.geom, 0)
) AS subquery
WHERE records.lrc = 'nrw';
The error I get is:
ERROR: invalid reference to FROM-clause entry for table "records"
LINE 7: WHERE st_dwithin(records.geom_poly, wales_lrcs.geom, 0)
Is this even possible?
Many thanks,
Steve
Realised there was no need to use SET FROM. I could just use a sub query directly in the SET:
UPDATE lrc_wales_data.records
SET lrc_array = (
SELECT array_agg(wales_lrcs.gid) AS lrc
FROM layers.wales_lrcs
WHERE st_dwithin(records.geom_poly, wales_lrcs.geom, 0)
)
WHERE records.lrc = 'nrw';

OrientDB: all pairs shortest path

I'm trying to write a OSQL query for computing the length of the shortest path between all pairs of nodes but, since having more than one class in the FROM clause is not allowed, I am wondering how I can loop over all the pairs of different nodes.
I tried with this query:
SELECT shortestPath($current, $e0, 'BOTH', 'Meets')
FROM Employee
LET $e0 = (SELECT FROM Employee where $current.nt_account > $parent.nt_account)
(nt_account is the Employee ID).
When I try to execute the query I get the following error:
java.lang.IllegalArgumentException: Vertex id can not be null
Can anybody help me?
Cheers!
Try this query
select from (select $b.shortestPath from Employee let $b= ( SELECT shortestPath($parent.current,#this, 'BOTH', 'Meets') from Employee)) unwind $b